2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

fhem.pl: oldreadings enhancements (Forum #133383)

git-svn-id: https://svn.fhem.de/fhem/trunk@27498 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2023-04-30 08:50:41 +00:00
parent 64bc0311eb
commit c29eae106d
3 changed files with 16 additions and 7 deletions

View File

@ -601,7 +601,10 @@ attribute list if you want to know if a device supports these attributes. <br>
This attribute takes a comma-separated list of readings. You may use
regular expressions in that list. For each reading in the list FHEM will
internaly store the previous value if the readings value changes. To access
the storead value use the OldReadings.* functions.</li>
the storead value use the OldReadings.* functions.
If the previous value is always to be stored (even if it didn't changed),
then set the last value of the comma-separated list to oldreadingsAlways.
</li>
<a name="userReadings"></a>
<li>userReadings<br>

View File

@ -609,6 +609,9 @@ Ger&auml;t dokumentiert.
Readings. regex sind erlaubt. F&uuml;r jedes Reading aus der Liste
speichert FHEM intern den vorherigen Wert wenn sich das Reading
&auml;ndert. Zum Zugriff auf die Werte gibt es die OldReadings.* Routinen.
Falls der vorherige Wert immer, d.h. auch wenn es sich nicht &auml;ndert,
gespeichert werden soll, dann muss der letzte Werte der Komma getrennten
Liste oldreadingsAlways sein.
</li>
<a name="userReadings"></a>

View File

@ -4799,12 +4799,15 @@ setReadingsVal($$$$)
return if($rname eq "IODev" && !fhem_devSupportsAttr($hash->{NAME}, "IODev"));
if($hash->{".or"} && grep($rname =~ m/^$_$/, @{$hash->{".or"}}) ) {
if(defined($hash->{READINGS}{$rname}) &&
defined($hash->{READINGS}{$rname}{VAL}) &&
$hash->{READINGS}{$rname}{VAL} ne $val ) {
$hash->{OLDREADINGS}{$rname}{VAL} = $hash->{READINGS}{$rname}{VAL};
$hash->{OLDREADINGS}{$rname}{TIME} = $hash->{READINGS}{$rname}{TIME};
my $or = $hash->{".or"};
if($or && grep($rname =~ m/^$_$/, @{$or}) ) {
my $rd = $hash->{READINGS};
if(defined($rd->{$rname}) &&
defined($rd->{$rname}{VAL}) &&
($or->[@{$or}-1] eq "oldreadingsAlways" ||
$rd->{$rname}{VAL} ne $val) ) {
$hash->{OLDREADINGS}{$rname}{VAL} = $rd->{$rname}{VAL};
$hash->{OLDREADINGS}{$rname}{TIME} = $rd->{$rname}{TIME};
}
}