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
|
||||
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
|
||||
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>
|
||||
The precedence of event-on-update-reading and event-on-change-reading is as
|
||||
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
|
||||
Ereignis, welches z.B. von <a href="#notify">notify</a> oder<a
|
||||
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>
|
||||
|
||||
<a name="event-on-change-reading"></a>
|
||||
|
31
fhem/fhem.pl
31
fhem/fhem.pl
@ -3550,18 +3550,37 @@ readingsBulkUpdate($$$@)
|
||||
my $attreocr = $hash->{".attreocr"};
|
||||
my $attreour = $hash->{".attreour"};
|
||||
|
||||
# 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 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";
|
||||
}
|
||||
|
||||
# determine if an event should be created:
|
||||
# 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-change-reading...
|
||||
# ...and its value has changed.
|
||||
# ...and its value has changed...
|
||||
# ...and the change greater then the threshold
|
||||
$changed= !($attreocr || $attreour)
|
||||
|| $eour
|
||||
|| ($eocr && ($value ne $readings->{VAL}));
|
||||
|| ($eocr && ($value ne $readings->{VAL}) && $threshold_reachded);
|
||||
#Log 1, "EOCR:$eocr EOUR:$eour CHANGED:$changed";
|
||||
|
||||
my @v = grep { my $l = $_;
|
||||
|
Loading…
Reference in New Issue
Block a user