mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
Add threshhold to event-on-change-reading (by justme1968, Forum #24378)
git-svn-id: https://svn.fhem.de/fhem/trunk@6080 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
56faf322bf
commit
dc2b0f0314
@ -426,7 +426,8 @@ A line ending with \ will be concatenated with the next one, so long lines
|
|||||||
The attribute takes a comma-separated list of readings. You may use regular
|
The attribute takes a comma-separated list of readings. You may use regular
|
||||||
expressions in that list. If set, only changes of the listed readings
|
expressions in that list. If set, only changes of the listed readings
|
||||||
create events. In other words, if a reading listed here is updated with the
|
create events. In other words, if a reading listed here is updated with the
|
||||||
new value identical to the old value, no event is created.
|
new value identical to the old value, no event is created. If an optional [:threshold]
|
||||||
|
is given after a reading name events are only generated if the change is >= threshold.
|
||||||
</li>
|
</li>
|
||||||
The precedence of event-on-update-reading and event-on-change-reading is as
|
The precedence of event-on-update-reading and event-on-change-reading is as
|
||||||
follows:
|
follows:
|
||||||
|
@ -435,7 +435,9 @@ Zeilen erstreckende Befehle, indem man keine \ am Zeilenende eingeben muss.</p>
|
|||||||
Wenn nicht gesetzt, erzeugt jede Veränderung eines "readings" ein
|
Wenn nicht gesetzt, erzeugt jede Veränderung eines "readings" ein
|
||||||
Ereignis, welches z.B. von <a href="#notify">notify</a> oder<a
|
Ereignis, welches z.B. von <a href="#notify">notify</a> oder<a
|
||||||
href="FileLog"> FileLog</a> berücksichtigt wird. Wenn gesetzt erzeugen
|
href="FileLog"> FileLog</a> berücksichtigt wird. Wenn gesetzt erzeugen
|
||||||
nur Aktualisierungen der eingetragenen "readings" ein Ereignis.
|
nur Aktualisierungen der eingetragenen "readings" ein Ereignis. Wenn hinter dem
|
||||||
|
Namen eines "readings" ein optionaler Schwellwert über [:threshold] angegeben ist
|
||||||
|
wird das event nur getriggert wenn die Änderungen >= threshold ist.
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<a name="event-on-change-reading"></a>
|
<a name="event-on-change-reading"></a>
|
||||||
|
35
fhem/fhem.pl
35
fhem/fhem.pl
@ -3547,21 +3547,40 @@ readingsBulkUpdate($$$@)
|
|||||||
if($changed && defined($readings)) {
|
if($changed && defined($readings)) {
|
||||||
|
|
||||||
# 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"};
|
||||||
my $attreour = $hash->{".attreour"};
|
my $attreour = $hash->{".attreour"};
|
||||||
|
|
||||||
|
# determine whether the reading is listed in any of the attributes
|
||||||
|
my $eocr = $attreocr && (my @eocrv=grep { my $l = $_;
|
||||||
|
$l =~ s/:.*//;
|
||||||
|
($reading=~ m/^$l$/) ? $_ : undef} @{$attreocr});
|
||||||
|
my $eour = $attreour && grep($reading =~ m/^$_$/, @{$attreour});
|
||||||
|
|
||||||
|
# check if threshold is given
|
||||||
|
my $threshold_reachded = 1;
|
||||||
|
if( $eocr
|
||||||
|
&& $eocrv[0] =~ m/.*:(.*)/ ) {
|
||||||
|
|
||||||
|
my $last_value = $hash->{".attreocr-threshold$reading"};
|
||||||
|
if( !defined($last_value) ) {
|
||||||
|
$hash->{".attreocr-threshold$reading"} = $value;
|
||||||
|
} elsif( abs($value-$last_value) < $1 ) {
|
||||||
|
$threshold_reachded = 0;
|
||||||
|
} else {
|
||||||
|
$hash->{".attreocr-threshold$reading"} = $value;
|
||||||
|
}
|
||||||
|
#Log 1, "EOCR:$eocr value: $value last:$last_value threshold: $1 reached: $threshold_reachded";
|
||||||
|
}
|
||||||
|
|
||||||
# these flags determine whether the reading is listed in any of
|
|
||||||
# the attributes
|
|
||||||
my $eocr= $attreocr && grep($reading =~ m/^$_$/, @{$attreocr});
|
|
||||||
my $eour= $attreour && grep($reading =~ m/^$_$/, @{$attreour});
|
|
||||||
# determine if an event should be created:
|
# determine if an event should be created:
|
||||||
# always create event if no attribute is set
|
# always create event if no attribute is set
|
||||||
# or if the reading is listed in event-on-update-reading
|
# or if the reading is listed in event-on-update-reading
|
||||||
# or if the reading is listed in event-on-change-reading...
|
# or if the reading is listed in event-on-change-reading...
|
||||||
# ...and its value has changed.
|
# ...and its value has changed...
|
||||||
|
# ...and the change greater then the threshold
|
||||||
$changed= !($attreocr || $attreour)
|
$changed= !($attreocr || $attreour)
|
||||||
|| $eour
|
|| $eour
|
||||||
|| ($eocr && ($value ne $readings->{VAL}));
|
|| ($eocr && ($value ne $readings->{VAL}) && $threshold_reachded);
|
||||||
#Log 1, "EOCR:$eocr EOUR:$eour CHANGED:$changed";
|
#Log 1, "EOCR:$eocr EOUR:$eour CHANGED:$changed";
|
||||||
|
|
||||||
my @v = grep { my $l = $_;
|
my @v = grep { my $l = $_;
|
||||||
|
Loading…
Reference in New Issue
Block a user