From c29eae106d4615c679298008eb6897311cef86fa Mon Sep 17 00:00:00 2001
From: rudolfkoenig <>
Date: Sun, 30 Apr 2023 08:50:41 +0000
Subject: [PATCH] fhem.pl: oldreadings enhancements (Forum #133383)
git-svn-id: https://svn.fhem.de/fhem/trunk@27498 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/docs/commandref_frame.html | 5 ++++-
fhem/docs/commandref_frame_DE.html | 3 +++
fhem/fhem.pl | 15 +++++++++------
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/fhem/docs/commandref_frame.html b/fhem/docs/commandref_frame.html
index 51dd72e82..1dfb3371c 100644
--- a/fhem/docs/commandref_frame.html
+++ b/fhem/docs/commandref_frame.html
@@ -601,7 +601,10 @@ attribute list if you want to know if a device supports these attributes.
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.
+ 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.
+
userReadings
diff --git a/fhem/docs/commandref_frame_DE.html b/fhem/docs/commandref_frame_DE.html
index 61aaf3d97..ccebd0996 100644
--- a/fhem/docs/commandref_frame_DE.html
+++ b/fhem/docs/commandref_frame_DE.html
@@ -609,6 +609,9 @@ Gerät dokumentiert.
Readings. regex sind erlaubt. Für jedes Reading aus der Liste
speichert FHEM intern den vorherigen Wert wenn sich das Reading
ändert. Zum Zugriff auf die Werte gibt es die OldReadings.* Routinen.
+ Falls der vorherige Wert immer, d.h. auch wenn es sich nicht ändert,
+ gespeichert werden soll, dann muss der letzte Werte der Komma getrennten
+ Liste oldreadingsAlways sein.
diff --git a/fhem/fhem.pl b/fhem/fhem.pl
index 12a594832..9adcec877 100755
--- a/fhem/fhem.pl
+++ b/fhem/fhem.pl
@@ -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};
}
}