diff --git a/fhem/CHANGED b/fhem/CHANGED
index 41e5683e2..c346f0e1c 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
+ - change: 20_FRM_IN: only update on change (Forum #81815)
- bugfix: 73_AutoShuttersControl: fix absent Event and ModeDown absent bug
- bugfix: 73_AutoShuttersControl: fix gone then absent bug
- feature: 49_SSCam: V7.6.0, The PTZ panel is completed by "Preset" and
diff --git a/fhem/FHEM/20_FRM_IN.pm b/fhem/FHEM/20_FRM_IN.pm
index 2a480ec4a..cf759590f 100755
--- a/fhem/FHEM/20_FRM_IN.pm
+++ b/fhem/FHEM/20_FRM_IN.pm
@@ -123,18 +123,18 @@ FRM_IN_Init($$)
}
sub
-FRM_IN_observer
+FRM_IN_observer($$$$)
{
- my ($pin,$old,$new,$hash) = @_;
+ my ($pin,$last,$new,$hash) = @_;
my $name = $hash->{NAME};
- Log3 $name,5,"onDigitalMessage for pin ".$pin.", old: ".(defined $old ? $old : "--").", new: ".(defined $new ? $new : "--");
+ my $old = ReadingsVal($name, "reading", undef) eq "on" ? PIN_HIGH : PIN_LOW;
if (AttrVal($hash->{NAME},"activeLow","no") eq "yes") {
- $old = $old == PIN_LOW ? PIN_HIGH : PIN_LOW if (defined $old);
$new = $new == PIN_LOW ? PIN_HIGH : PIN_LOW;
}
- my $changed = ((!(defined $old)) or ($old != $new));
- main::readingsBeginUpdate($hash);
+ Log3 $name, 5, "$name observer pin: $pin, old: ".(defined $old ? $old : "--").", new: ".(defined $new ? $new : "--");
+ my $changed = !defined($old) || $old != $new;
if ($changed) {
+ main::readingsBeginUpdate($hash);
if (defined (my $mode = main::AttrVal($name,"count-mode",undef))) {
if (($mode eq "both")
or (($mode eq "rising") and ($new == PIN_HIGH))
@@ -154,18 +154,17 @@ FRM_IN_observer
main::readingsBulkUpdate($hash,"count",$count,1);
}
};
+ main::readingsBulkUpdate($hash,"reading",$new == PIN_HIGH ? "on" : "off", 1);
+ main::readingsEndUpdate($hash,1);
}
- main::readingsBulkUpdate($hash,"reading",$new == PIN_HIGH ? "on" : "off", $changed);
- main::readingsEndUpdate($hash,1);
}
sub
-FRM_IN_Set
+FRM_IN_Set($@)
{
my ($hash, @a) = @_;
- return "Need at least one parameters" if(@a < 2);
- return "Unknown argument $a[1], choose one of " . join(" ", sort keys %sets)
- if(!defined($sets{$a[1]}));
+ return "set command missing" if(@a < 2 || !defined($a[1]));
+ return "unknown set command '$a[1]', choose one of " . join(" ", sort keys %sets) if(!defined($sets{$a[1]}));
my $command = $a[1];
my $value = $a[2];
COMMAND_HANDLER: {
@@ -182,23 +181,27 @@ FRM_IN_Set
}
sub
-FRM_IN_Get($)
+FRM_IN_Get($@)
{
my ($hash, @a) = @_;
- return "Need at least one parameters" if(@a < 2);
- return "Unknown argument $a[1], choose one of " . join(" ", sort keys %gets)
- if(!defined($gets{$a[1]}));
+ return "get command missing" if(@a < 2 || !defined($a[1]));
+ return "unknown get command '$a[1]', choose one of " . join(":noArg ", sort keys %gets) . ":noArg" if(!defined($gets{$a[1]}));
my $name = shift @a;
my $cmd = shift @a;
ARGUMENT_HANDLER: {
- $cmd eq "reading" and do {
+ ( $cmd eq "reading" ) and do {
+ my $last;
eval {
- return FRM_Client_FirmataDevice($hash)->digital_read($hash->{PIN}) == PIN_HIGH ? "on" : "off";
+ $last = FRM_Client_FirmataDevice($hash)->digital_read($hash->{PIN});
+ if (AttrVal($hash->{NAME},"activeLow","no") eq "yes") {
+ $last = $last == PIN_LOW ? PIN_HIGH : PIN_LOW;
+ }
};
- return $@;
+ return FRM_Catch($@) if $@;
+ return $last == PIN_HIGH ? "on" : "off";
};
( $cmd eq "count" or $cmd eq "alarm" or $cmd eq "state" ) and do {
- return main::ReadingsVal($name,"count",$gets{$cmd});
+ return main::ReadingsVal($name,$cmd,$gets{$cmd});
};
}
return undef;
@@ -305,15 +308,34 @@ FRM_IN_Attr($$$$) {
CHANGES
+ 04.11.2018 jensb
+ o bugfix: get alarm/reading/state
+ o feature: remove unused FHEMWEB input field from all get commands
+ o feature: @see https://forum.fhem.de/index.php/topic,81815.msg842557.html#msg842557
+ - use current FHEM reading instead of perl-firmata "old" value to improve change detection
+ - only update reading on change to filter updates by other pins on same Firmata digital port
+
03.01.2018 jensb
o implemented Firmata 2.5 feature PIN_MODE_PULLUP (requires perl-firmata 0.64 or higher)
=cut
=pod
+
+=head1 FHEM COMMANDREF METADATA
+
+=over
+
=item device
+
=item summary Firmata: digital input
+
=item summary_DE Firmata: digitaler Eingang
+
+=back
+
+=head1 INSTALLATION AND CONFIGURATION
+
=begin html
@@ -323,14 +345,14 @@ FRM_IN_Attr($$$$) {
that should be configured as a digital input.
Requires a defined FRM device to work. The pin must be listed in
- the internal reading "input_pins" or "pullup_pins"
+ the internal reading "input_pins" or "pullup_pins"
of the FRM device (after connecting to the Firmata device) to be used as digital input with or without pullup.
Define
define <name> FRM_IN <pin>