mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-01 20:20:10 +00:00
73_ElectricityCalculator: New set command to synchronize Counters
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@21390 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
155bb2cfb1
commit
65669668e9
@ -265,22 +265,33 @@ sub ElectricityCalculator_Get($@)
|
|||||||
### If not enough arguments have been provided
|
### If not enough arguments have been provided
|
||||||
if ( @a < 2 )
|
if ( @a < 2 )
|
||||||
{
|
{
|
||||||
return "\"get ElectricityCalculator\" needs at least one argument";
|
return "\"set ElectricityCalculator\" needs at least one argument";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $ElectricityCalcName = shift @a;
|
my $ElectricityCalcName = shift @a;
|
||||||
my $reading = shift @a;
|
my $reading = shift @a;
|
||||||
my $value;
|
my $value = join(" ", @a);
|
||||||
my $ReturnMessage;
|
my $ReturnMessage;
|
||||||
|
my @cList;
|
||||||
|
|
||||||
if(!defined($hash->{helper}{gets}{$reading}))
|
### Create Log entries for debugging
|
||||||
{
|
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. "_Get - reading : " . $reading;
|
||||||
my @cList = keys %{$hash->{helper}{gets}};
|
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. "_Get - value : " . $value;
|
||||||
return "Unknown argument $reading, choose one of " . join(" ", @cList);
|
|
||||||
|
|
||||||
### Create Log entries for debugging
|
|
||||||
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - get list: " . join(" ", @cList);
|
if(defined($hash->{READINGS})) {
|
||||||
|
push(@cList, " ");
|
||||||
|
push(@cList, keys(%{$hash->{READINGS}}));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
push(@cList, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
### Create Log entries for debugging
|
||||||
|
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - set list: " . join(" ", @cList);
|
||||||
|
|
||||||
|
return "Unknown argument $reading, choose one of " . join(" ", @cList) if $reading eq '?';
|
||||||
|
|
||||||
|
|
||||||
if ( $reading ne "?")
|
if ( $reading ne "?")
|
||||||
{
|
{
|
||||||
@ -313,17 +324,65 @@ sub ElectricityCalculator_Set($@)
|
|||||||
my $reading = shift @a;
|
my $reading = shift @a;
|
||||||
my $value = join(" ", @a);
|
my $value = join(" ", @a);
|
||||||
my $ReturnMessage;
|
my $ReturnMessage;
|
||||||
|
my @cList;
|
||||||
|
|
||||||
if(!defined($hash->{helper}{gets}{$reading}))
|
### Create Log entries for debugging
|
||||||
{
|
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. "_Set - reading : " . $reading;
|
||||||
my @cList = keys %{$hash->{helper}{sets}};
|
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. "_Set - value : " . $value;
|
||||||
return "Unknown argument $reading, choose one of " . join(" ", @cList);
|
|
||||||
|
|
||||||
### Create Log entries for debugging
|
|
||||||
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - set list: " . join(" ", @cList);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $reading ne "?")
|
if(defined($hash->{READINGS})) {
|
||||||
|
push(@cList, "SyncCounter");
|
||||||
|
push(@cList, keys(%{$hash->{READINGS}}));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
push(@cList, "SyncCounter");
|
||||||
|
}
|
||||||
|
|
||||||
|
### Create Log entries for debugging
|
||||||
|
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - set list: " . join(" ", @cList);
|
||||||
|
|
||||||
|
return "Unknown argument $reading, choose one of " . join(" ", @cList) if $reading eq '?';
|
||||||
|
|
||||||
|
### If the command supposed to synchronize the CounterValues between CounterModule and CalculatorModule
|
||||||
|
if ($reading eq "SyncCounter") {
|
||||||
|
### Create Log entries for debugging
|
||||||
|
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " - Syncing Counter with :" . $value;
|
||||||
|
|
||||||
|
### Sreach for the ReadingsName of the Current CounterValue
|
||||||
|
my @SearchResult = grep(/_CounterCurrent/, @cList);
|
||||||
|
|
||||||
|
### Get current CalculatorValue
|
||||||
|
my $CalculaterValueCurrent = ReadingsVal($ElectricityCalcName, $SearchResult[0], 0);
|
||||||
|
|
||||||
|
### Get current Offset from Attribute
|
||||||
|
my $CounterOffsetCurrent = AttrVal($ElectricityCalcName, "ElectricityCounterOffset", 0);
|
||||||
|
|
||||||
|
### Calculate CounterValue
|
||||||
|
my $CounterValueCurrent = $CalculaterValueCurrent - $CounterOffsetCurrent;
|
||||||
|
|
||||||
|
### Calculate new Offset
|
||||||
|
my $CounterOffsetNew = $value - $CounterValueCurrent;
|
||||||
|
|
||||||
|
### Calculate Ceck
|
||||||
|
# my $CounterValueNew = $CounterValueCurrent + $CounterOffsetNew;
|
||||||
|
|
||||||
|
### Create Log entries for debugging
|
||||||
|
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " - Search Result : " . Dumper(@SearchResult);
|
||||||
|
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " - CounterValueNew Given : " . $value;
|
||||||
|
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " - CounterValueCurrent Result : " . $CalculaterValueCurrent;
|
||||||
|
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " - CounterOffsetCurrent Result : " . $CounterOffsetCurrent;
|
||||||
|
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " - CounterValueCurrent Result : " . $CounterValueCurrent;
|
||||||
|
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " - CounterOffsetNew Result : " . $CounterOffsetNew;
|
||||||
|
# Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " - CounterValueNew Check : " . $CounterValueNew;
|
||||||
|
|
||||||
|
### Set new Offset in Attributes
|
||||||
|
$attr{$ElectricityCalcName}{ElectricityCounterOffset} = $CounterOffsetNew;
|
||||||
|
|
||||||
|
### Create ReturnMessage
|
||||||
|
$ReturnMessage = $ElectricityCalcName . " - Successfully synchromized Counter and Calculator with : " . $value . " kWh";
|
||||||
|
}
|
||||||
|
elsif ($reading ne "?")
|
||||||
{
|
{
|
||||||
### Create Log entries for debugging
|
### Create Log entries for debugging
|
||||||
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - set " . $reading . " with value: " . $value;
|
Log3 $ElectricityCalcName, 5, $ElectricityCalcName. " : ElectricityCalculator - set " . $reading . " with value: " . $value;
|
||||||
@ -962,8 +1021,9 @@ sub ElectricityCalculator_Notify($$)
|
|||||||
<tr><td>
|
<tr><td>
|
||||||
<ul>
|
<ul>
|
||||||
The set - function sets individual values for example to correct values after power loss etc.<BR>
|
The set - function sets individual values for example to correct values after power loss etc.<BR>
|
||||||
The set - function works only for readings which have been stored in the CalculatorDevice.<BR>
|
The set - function works for readings which have been stored in the CalculatorDevice and to update the Offset.<BR>
|
||||||
The Readings being stored in the Counter - Device need to be changed individially with the <code>set</code> - command.<BR>
|
The Readings being stored in the Counter - Device need to be changed individially with the <code>set</code> - command.<BR>
|
||||||
|
The command "SyncCounter" will calculate and update the Offset. Just enter the value of your mechanical Reader.<BR>
|
||||||
</ul>
|
</ul>
|
||||||
</td></tr>
|
</td></tr>
|
||||||
</table>
|
</table>
|
||||||
@ -1547,8 +1607,9 @@ sub ElectricityCalculator_Notify($$)
|
|||||||
<tr><td>
|
<tr><td>
|
||||||
<ul>
|
<ul>
|
||||||
Die set - Funktion erlaubt individuelle Readings zu verändern um beispielsweise nach einem Stromausfall Werte zu korrigieren.<BR>
|
Die set - Funktion erlaubt individuelle Readings zu verändern um beispielsweise nach einem Stromausfall Werte zu korrigieren.<BR>
|
||||||
Die set - Funktion funktioniert nur für Readings welche im CalculatorDevice gespeichert wurden.<BR>
|
Die set - Funktion funktioniert für Readings welche im CalculatorDevice gespeichert wurden und zum update des Offsets zwischen den Zählern.<BR>
|
||||||
Die Readings welche im Counter - Device gespeichert wurden, müssen individuell mit <code>set</code> - Befehl gesetzt werden.<BR>
|
Die Readings welche im Counter - Device gespeichert wurden, müssen individuell mit <code>set</code> - Befehl gesetzt werden.<BR>
|
||||||
|
Der Befehl "SyncCounter" errechnet und update den Offset. Hierbei einfach den Wert des mechanischen Zählers eingeben.<BR>
|
||||||
</ul>
|
</ul>
|
||||||
</td></tr>
|
</td></tr>
|
||||||
</table>
|
</table>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user