mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-15 22:26:04 +00:00
73_GasCalculator: New set command to synchronize Counters
git-svn-id: https://svn.fhem.de/fhem/trunk@21392 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
1391b59030
commit
74611e811f
@ -198,7 +198,7 @@ sub GasCalculator_Attr(@)
|
||||
####END####### Handle attributes after changes via fhem GUI ####################################################END#####
|
||||
|
||||
|
||||
###START###### Manipulate reading after "set" command by fhem #################################################START####
|
||||
###START###### Manipulate reading after "get" command by fhem #################################################START####
|
||||
sub GasCalculator_Get($@)
|
||||
{
|
||||
my ( $hash, @a ) = @_;
|
||||
@ -206,38 +206,48 @@ sub GasCalculator_Get($@)
|
||||
### If not enough arguments have been provided
|
||||
if ( @a < 2 )
|
||||
{
|
||||
return "\"get GasCalculator\" needs at least one argument";
|
||||
return "\"set GasCalculator\" needs at least one argument";
|
||||
}
|
||||
|
||||
my $GasCalcName = shift @a;
|
||||
my $reading = shift @a;
|
||||
my $value;
|
||||
my $value = join(" ", @a);
|
||||
my $ReturnMessage;
|
||||
my @cList;
|
||||
|
||||
if(!defined($GasCalculator_gets{$reading}))
|
||||
{
|
||||
my @cList = keys %GasCalculator_sets;
|
||||
return "Unknown argument $reading, choose one of " . join(" ", @cList);
|
||||
### Create Log entries for debugging
|
||||
Log3 $GasCalcName, 5, $GasCalcName. "_Get - reading : " . $reading;
|
||||
Log3 $GasCalcName, 5, $GasCalcName. "_Get - value : " . $value;
|
||||
|
||||
### Create Log entries for debugging
|
||||
Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - get list: " . join(" ", @cList);
|
||||
|
||||
if(defined($hash->{READINGS})) {
|
||||
push(@cList, " ");
|
||||
push(@cList, keys(%{$hash->{READINGS}}));
|
||||
}
|
||||
else {
|
||||
push(@cList, " ");
|
||||
}
|
||||
|
||||
### Create Log entries for debugging
|
||||
Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - set list: " . join(" ", @cList);
|
||||
|
||||
return "Unknown argument $reading, choose one of " . join(" ", @cList) if $reading eq '?';
|
||||
|
||||
if ( $reading ne "?")
|
||||
{
|
||||
### Create Log entries for debugging
|
||||
Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - get " . $reading . " with value: " . $value;
|
||||
|
||||
### Write current value
|
||||
$value = ReadingsVal($GasCalcName, $reading, undef);
|
||||
|
||||
|
||||
### Create Log entries for debugging
|
||||
Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - get " . $reading . " with value: " . $value;
|
||||
|
||||
### Create ReturnMessage
|
||||
$ReturnMessage = $value;
|
||||
}
|
||||
|
||||
return($ReturnMessage);
|
||||
}
|
||||
####END####### Manipulate reading after "set" command by fhem ##################################################END#####
|
||||
####END####### Manipulate reading after "get" command by fhem ##################################################END#####
|
||||
|
||||
###START###### Manipulate reading after "set" command by fhem #################################################START####
|
||||
sub GasCalculator_Set($@)
|
||||
@ -254,17 +264,65 @@ sub GasCalculator_Set($@)
|
||||
my $reading = shift @a;
|
||||
my $value = join(" ", @a);
|
||||
my $ReturnMessage;
|
||||
my @cList;
|
||||
|
||||
if(!defined($GasCalculator_sets{$reading}))
|
||||
{
|
||||
my @cList = keys %GasCalculator_sets;
|
||||
return "Unknown argument $reading, choose one of " . join(" ", @cList);
|
||||
### Create Log entries for debugging
|
||||
Log3 $GasCalcName, 5, $GasCalcName. "_Set - reading : " . $reading;
|
||||
Log3 $GasCalcName, 5, $GasCalcName. "_Set - value : " . $value;
|
||||
|
||||
### Create Log entries for debugging
|
||||
Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - 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 $GasCalcName, 5, $GasCalcName. " : GasCalculator - 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 $GasCalcName, 5, $GasCalcName. " - Syncing Counter with :" . $value;
|
||||
|
||||
### Sreach for the ReadingsName of the Current CounterValue
|
||||
my @SearchResult = grep(/_CounterCurrent/, @cList);
|
||||
|
||||
### Get current CalculatorValue
|
||||
my $CalculaterValueCurrent = ReadingsVal($GasCalcName, $SearchResult[0], 0);
|
||||
|
||||
### Get current Offset from Attribute
|
||||
my $CounterOffsetCurrent = AttrVal($GasCalcName, "GasCounterOffset", 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 $GasCalcName, 5, $GasCalcName. " - Search Result : " . Dumper(@SearchResult);
|
||||
Log3 $GasCalcName, 5, $GasCalcName. " - CounterValueNew Given : " . $value;
|
||||
Log3 $GasCalcName, 5, $GasCalcName. " - CounterValueCurrent Result : " . $CalculaterValueCurrent;
|
||||
Log3 $GasCalcName, 5, $GasCalcName. " - CounterOffsetCurrent Result : " . $CounterOffsetCurrent;
|
||||
Log3 $GasCalcName, 5, $GasCalcName. " - CounterValueCurrent Result : " . $CounterValueCurrent;
|
||||
Log3 $GasCalcName, 5, $GasCalcName. " - CounterOffsetNew Result : " . $CounterOffsetNew;
|
||||
# Log3 $GasCalcName, 5, $GasCalcName. " - CounterValueNew Check : " . $CounterValueNew;
|
||||
|
||||
### Set new Offset in Attributes
|
||||
$attr{$GasCalcName}{GasCounterOffset} = $CounterOffsetNew;
|
||||
|
||||
### Create ReturnMessage
|
||||
$ReturnMessage = $GasCalcName . " - Successfully synchromized Counter and Calculator with : " . $value . " kWh";
|
||||
}
|
||||
elsif ($reading ne "?")
|
||||
{
|
||||
### Create Log entries for debugging
|
||||
Log3 $GasCalcName, 5, $GasCalcName. " : GasCalculator - set " . $reading . " with value: " . $value;
|
||||
@ -916,8 +974,9 @@ sub GasCalculator_Notify($$)
|
||||
<tr><td>
|
||||
<ul>
|
||||
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 command "SyncCounter" will calculate and update the Offset. Just enter the value of your mechanical Reader.<BR>
|
||||
</ul>
|
||||
</td></tr>
|
||||
</table>
|
||||
@ -1491,8 +1550,9 @@ sub GasCalculator_Notify($$)
|
||||
<tr><td>
|
||||
<ul>
|
||||
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>
|
||||
Der Befehl "SyncCounter" errechnet und update den Offset. Hierbei einfach den Wert des mechanischen Zählers eingeben.<BR>
|
||||
</ul>
|
||||
</td></tr>
|
||||
</table>
|
||||
|
Loading…
x
Reference in New Issue
Block a user