mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
userReadings offset/monotonic modifier by justme1968
git-svn-id: https://svn.fhem.de/fhem/trunk@3380 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
b603bbd0bc
commit
c9855c30de
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII
|
# Add changes at the top of the list. Keep it in ASCII
|
||||||
- SVN
|
- SVN
|
||||||
|
- feature: offset and monotonic added to userReadings modifier (justme1968)
|
||||||
- feature: HUEDevice: support SVG icons for LWB001 living whites bulb
|
- feature: HUEDevice: support SVG icons for LWB001 living whites bulb
|
||||||
- feature: HUEDevice: support more than one bridge
|
- feature: HUEDevice: support more than one bridge
|
||||||
- feature: updateInBackground global attribute
|
- feature: updateInBackground global attribute
|
||||||
|
@ -440,6 +440,14 @@ A line ending with \ will be concatenated with the next one, so long lines
|
|||||||
seconds between the current and the previous evaluation. Granularity
|
seconds between the current and the previous evaluation. Granularity
|
||||||
of time is one second. No value is calculated if the time past is
|
of time is one second. No value is calculated if the time past is
|
||||||
below one second. Useful to calculate rates.</li>
|
below one second. Useful to calculate rates.</li>
|
||||||
|
<li>offset: if the current evaluated value is smaler than the previously
|
||||||
|
evaluated value the reading is incremented by the previous value.
|
||||||
|
the reading can then be used as an offset correct for a counter that
|
||||||
|
is reset for example due to a power loss.</li>
|
||||||
|
<li>monotonic: if the difference between the current and the previously
|
||||||
|
evaluated value is positive the reading is incremented by this difference.
|
||||||
|
this allows to derive a monotonic growing counter from an original counter
|
||||||
|
even if the original will be rest by a power loss</li>
|
||||||
</ul>
|
</ul>
|
||||||
Example:<br>
|
Example:<br>
|
||||||
<ul><code>attr myPowerMeter userReadings power
|
<ul><code>attr myPowerMeter userReadings power
|
||||||
|
@ -447,8 +447,15 @@ Zeilen erstreckende Befehle, indem man keine \ am Zeilenende eingeben muss.</p>
|
|||||||
<li>differential: das Reading wird auf die Differenz zw. dem aktuellen und
|
<li>differential: das Reading wird auf die Differenz zw. dem aktuellen und
|
||||||
dem vorherigen Wert, geteilt durch die Sekunden zw. der aktuellen Zeit
|
dem vorherigen Wert, geteilt durch die Sekunden zw. der aktuellen Zeit
|
||||||
und der letzten Auswertung, sekundengenau. Kein Wert wird berechnet,
|
und der letzten Auswertung, sekundengenau. Kein Wert wird berechnet,
|
||||||
falls der Unterschied unter eine Sekunde liegt.
|
falls der Unterschied unter eine Sekunde liegt.</li>
|
||||||
</li>
|
<li>offset: wenn der aktuellen Wert kleiner als der vorherige Wert ist
|
||||||
|
wird der vorherige Wert zum Reading addiert. Das Reading kann dann
|
||||||
|
als offset verwendet werden um einen Zähler der durch Sromverlust zurückgesetzt
|
||||||
|
wird zu korrigieren.</li>
|
||||||
|
<li>monotonic: wenn die Differenz zw. dem aktuellen und dem vorherigen Wert
|
||||||
|
positiv ist wird diese Differenz zum Reading addiert. Damit lässt sich von
|
||||||
|
einem Zähler der bei Stromverlust zurückgesetzt wird ein monoton
|
||||||
|
wachsender Zähler ableiten.</li>
|
||||||
</ul>
|
</ul>
|
||||||
Beispiel:
|
Beispiel:
|
||||||
<ul><code>
|
<ul><code>
|
||||||
|
10
fhem/fhem.pl
10
fhem/fhem.pl
@ -1885,7 +1885,7 @@ CommandAttr($$)
|
|||||||
my $perlCode= $6;
|
my $perlCode= $6;
|
||||||
#Log 1, sprintf("userReading %s has perlCode %s with modifier %s%s",
|
#Log 1, sprintf("userReading %s has perlCode %s with modifier %s%s",
|
||||||
# $userReading,$perlCode,$modifier,$trigger?" and trigger $trigger":"");
|
# $userReading,$perlCode,$modifier,$trigger?" and trigger $trigger":"");
|
||||||
if(grep { /$modifier/ } qw(none difference differential)) {
|
if(grep { /$modifier/ } qw(none difference differential offset monotonic)) {
|
||||||
$trigger =~ s/^:// if($trigger);
|
$trigger =~ s/^:// if($trigger);
|
||||||
$userReadings{$userReading}{trigger}= $trigger;
|
$userReadings{$userReading}{trigger}= $trigger;
|
||||||
$userReadings{$userReading}{modifier}= $modifier;
|
$userReadings{$userReading}{modifier}= $modifier;
|
||||||
@ -3163,6 +3163,14 @@ readingsEndUpdate($$)
|
|||||||
if(defined($deltav) && defined($deltat) && ($deltat>= 1.0)) {
|
if(defined($deltav) && defined($deltat) && ($deltat>= 1.0)) {
|
||||||
$result= $deltav/$deltat;
|
$result= $deltav/$deltat;
|
||||||
}
|
}
|
||||||
|
} elsif($modifier eq "offset") {
|
||||||
|
$oldvalue= 0 if( !defined($oldvalue) );
|
||||||
|
$result = ReadingsVal($name,$userReading,0);
|
||||||
|
$result += $oldvalue if( $value < $oldvalue );
|
||||||
|
} elsif($modifier eq "monotonic") {
|
||||||
|
$oldvalue= 0 if( !defined($oldvalue) );
|
||||||
|
$result = ReadingsVal($name,$userReading,0);
|
||||||
|
$result += $value - $oldvalue if( $value > $oldvalue );
|
||||||
}
|
}
|
||||||
readingsBulkUpdate($hash,$userReading,$result,1) if(defined($result));
|
readingsBulkUpdate($hash,$userReading,$result,1) if(defined($result));
|
||||||
# store value
|
# store value
|
||||||
|
Loading…
Reference in New Issue
Block a user