diff --git a/fhem/docs/commandref_frame.html b/fhem/docs/commandref_frame.html index 9ae5d2ba2..9f74aa160 100644 --- a/fhem/docs/commandref_frame.html +++ b/fhem/docs/commandref_frame.html @@ -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. The precedence of event-on-update-reading and event-on-change-reading is as follows: diff --git a/fhem/docs/commandref_frame_DE.html b/fhem/docs/commandref_frame_DE.html index 012b4ec11..ba76e47f4 100644 --- a/fhem/docs/commandref_frame_DE.html +++ b/fhem/docs/commandref_frame_DE.html @@ -435,7 +435,9 @@ Zeilen erstreckende Befehle, indem man keine \ am Zeilenende eingeben muss.

Wenn nicht gesetzt, erzeugt jede Veränderung eines "readings" ein Ereignis, welches z.B. von notify oder FileLog 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. diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 8c9ee397f..659ef991a 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -3547,21 +3547,40 @@ readingsBulkUpdate($$$@) if($changed && defined($readings)) { # these flags determine if any of the "event-on" attributes are set - my $attreocr = $hash->{".attreocr"}; - my $attreour = $hash->{".attreour"}; + my $attreocr = $hash->{".attreocr"}; + 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: # 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 = $_;