diff --git a/fhem/CHANGED b/fhem/CHANGED
index 2a2ce386e..c95a3ddb4 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -1,5 +1,8 @@
# 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.
+ - feature: PRESENCE: new attribute presenceThreshold to define a number of
+ checks that have to result in "present" before the state of
+ PRESENCE is changed to present. See commandref for details.
- feature: colorpicker: new modes HSV and HSVp
- bugfix: PRESENCE: fix generating readings when definition is disabled
- changed: 49_SSCam: Workaround for problems with SVS version 7.2
diff --git a/fhem/FHEM/73_PRESENCE.pm b/fhem/FHEM/73_PRESENCE.pm
index 1ba7e8b9e..1e57377c0 100755
--- a/fhem/FHEM/73_PRESENCE.pm
+++ b/fhem/FHEM/73_PRESENCE.pm
@@ -53,6 +53,7 @@ PRESENCE_Initialize($)
"ping_count:1,2,3,4,5,6,7,8,9,10 ".
"bluetooth_hci_device ".
"absenceThreshold:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 ".
+ "presenceThreshold:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 ".
"powerCmd ".$readingFnAttributes;
}
@@ -1094,13 +1095,14 @@ PRESENCE_ProcessState($$)
{
my ($hash, $state) = @_;
my $name = $hash->{NAME};
- my $threshold = AttrVal($name, "absenceThreshold", 1);
+ my $absenceThreshold = AttrVal($name, "absenceThreshold", 1);
+ my $presenceThreshold = AttrVal($name, "presenceThreshold", 1);
if($state eq "absent")
{
my $count = ($hash->{helper}{ABSENT_COUNT} ? $hash->{helper}{ABSENT_COUNT} : 0);
- if(++$count >= $threshold)
+ if(++$count >= $absenceThreshold)
{
readingsBulkUpdate($hash, "state", "absent");
readingsBulkUpdate($hash, "presence", "absent");
@@ -1112,13 +1114,30 @@ PRESENCE_ProcessState($$)
readingsBulkUpdate($hash, "state", "maybe absent");
readingsBulkUpdate($hash, "presence", "maybe absent");
- Log3 $name, 4, "PRESENCE ($name) - device is absent after $count check".($count == 1 ? "" : "s").". ".($threshold-$count)." check".(($threshold-$count) == 1 ? "" : "s")." left before going absent";
+ Log3 $name, 4, "PRESENCE ($name) - device is absent after $count check".($count == 1 ? "" : "s").". ".($absenceThreshold-$count)." check".(($absenceThreshold-$count) == 1 ? "" : "s")." left before going absent";
}
+
+ delete($hash->{helper}{PRESENT_COUNT}) if(exists($hash->{helper}{PRESENT_COUNT}));
}
elsif($state eq "present")
{
- readingsBulkUpdate($hash, "state", "present");
- readingsBulkUpdate($hash, "presence", "present");
+ my $count = ($hash->{helper}{PRESENT_COUNT} ? $hash->{helper}{PRESENT_COUNT} : 0);
+
+ if(++$count >= $presenceThreshold)
+ {
+ readingsBulkUpdate($hash, "state", "present");
+ readingsBulkUpdate($hash, "presence", "present");
+ }
+ else
+ {
+ $hash->{helper}{PRESENT_COUNT} = $count;
+
+ readingsBulkUpdate($hash, "state", "maybe present");
+ readingsBulkUpdate($hash, "presence", "maybe present");
+
+ Log3 $name, 4, "PRESENCE ($name) - device is present after $count check".($count == 1 ? "" : "s").". ".($presenceThreshold-$count)." check".(($presenceThreshold-$count) == 1 ? "" : "s")." left before going present";
+ }
+
delete($hash->{helper}{ABSENT_COUNT}) if(exists($hash->{helper}{ABSENT_COUNT}));
}
else
@@ -1357,6 +1376,11 @@ Options:
This can be used to verify the absence of a device with multiple check runs before the state is finally changed to "absent".
If this attribute is set to a value >1, the reading state and presence will be set to "maybe absent" during the absence verification.
Default Value is 1 (no absence verification)
+
hci0.