2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-28 02:44:53 +00:00

fhem.pl: timestamp-on-change-reading from justme1968 (Forum #52483)

git-svn-id: https://svn.fhem.de/fhem/trunk@11308 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2016-04-25 08:13:57 +00:00
parent 98f0e3eed0
commit b82ecd7c4d
3 changed files with 43 additions and 7 deletions

View File

@ -478,6 +478,15 @@ attribute list if you want to know if a device supports these attributes. <br>
</ol> </ol>
<p> <p>
<a name="timestamp-on-change-reading"></a>
<li>timestamp-on-change-reading<br>
The attribute takes a comma-separated list of readings. You may use regular
expressions in that list. If set, the timestamps of the listed readings will
not be changed if event-on-change-reading is also set and it would not create
an event for this reading.
</li>
<p>
<a name="event-aggregator"></a> <a name="event-aggregator"></a>
<li>event-aggregator</li> <li>event-aggregator</li>
The primary uses of this attribute are to calculate (time-weighted) averages of The primary uses of this attribute are to calculate (time-weighted) averages of

View File

@ -450,6 +450,15 @@ Ger&auml;t dokumentiert.
"reading" auch in event-on-change-reading aufgelistet ist.</li> "reading" auch in event-on-change-reading aufgelistet ist.</li>
</ol> </ol>
<a name="timestamp-on-change-reading"></a>
<li>timestamp-on-change-reading<br>
Dieses Attribut enth&auml;lt eine durch Kommata getrennte Liste von
"readings". Wenn gesetzt, werden die Zeitstempel der gelisteten "readings"
nicht aktualisiert wenn durch ein ebenfalls gesetztes event-on-change-reading
f&uuml;r dieses "reading" kein Ereignis erzeugen w&uuml;rde.
</li>
<p>
<a name="event-aggregator"></a> <a name="event-aggregator"></a>
<li>event-aggregator</li> <li>event-aggregator</li>
The primary uses of this attribute are to calculate (time-weighted) averages of The primary uses of this attribute are to calculate (time-weighted) averages of

View File

@ -308,7 +308,8 @@ $modules{Global}{AttrFn} = "GlobalAttr";
use vars qw($readingFnAttributes); use vars qw($readingFnAttributes);
$readingFnAttributes = "event-on-change-reading event-on-update-reading ". $readingFnAttributes = "event-on-change-reading event-on-update-reading ".
"event-aggregator event-min-interval stateFormat"; "event-aggregator event-min-interval stateFormat ".
"timestamp-on-change-reading";
%cmds = ( %cmds = (
@ -3843,6 +3844,13 @@ readingsBeginUpdate($)
$hash->{".attreour"} = \@a; $hash->{".attreour"} = \@a;
} }
my $attrtocr= AttrVal($name, "timestamp-on-change-reading", undef);
if($attrtocr) {
my @a = split(/,/,$attrtocr);
$hash->{".attrtocr"} = \@a;
}
$hash->{CHANGED}= () if(!defined($hash->{CHANGED})); $hash->{CHANGED}= () if(!defined($hash->{CHANGED}));
return $fmtDateTime; return $fmtDateTime;
} }
@ -3959,6 +3967,7 @@ readingsEndUpdate($$)
delete $hash->{".attreocr"}; delete $hash->{".attreocr"};
delete $hash->{".attraggr"}; delete $hash->{".attraggr"};
delete $hash->{".attrminint"}; delete $hash->{".attrminint"};
delete $hash->{".attrtocr"};
# propagate changes # propagate changes
@ -4000,8 +4009,11 @@ readingsBulkUpdate($$$@)
} }
$changed = 0 if($hash->{".ignoreEvent"}); $changed = 0 if($hash->{".ignoreEvent"});
# check for changes only if reading already exists # if reading does not exist yet: fake entry to allow filtering
if($changed && defined($readings)) { $readings = { VAL => "" } if( !defined($readings) );
my $update_timestamp = 1;
if($changed) {
# these flags determine if any of the "event-on" attributes are set # these flags determine if any of the "event-on" attributes are set
my $attreocr = $hash->{".attreocr"}; my $attreocr = $hash->{".attreocr"};
@ -4070,6 +4082,12 @@ readingsBulkUpdate($$$@)
} }
} }
if( $attreocr ) {
if( my $attrtocr = $hash->{".attrtocr"} ) {
$update_timestamp = $changed if( $attrtocr && grep($reading =~ m/^$_$/, @{$attrtocr}) );
}
}
} }
if($changed) { if($changed) {
@ -4103,7 +4121,7 @@ readingsBulkUpdate($$$@)
} }
setReadingsVal($hash, $reading, $value, $hash->{".updateTimestamp"}); setReadingsVal($hash, $reading, $value, $hash->{".updateTimestamp"}) if( $update_timestamp );
my $rv = "$reading: $value"; my $rv = "$reading: $value";
if($changed) { if($changed) {