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)

+
  • presenceThreshold

  • + The number of checks that have to result in "present" before the state of the PRESENCE definition is changed to "present". + This can be used to verify the presence of a device with multiple check runs before the state is finally changed to "present". + If this attribute is set to a value >1, the reading state and presence will be set to "maybe present" during the presence verification.

    + Default Value is 1 (no presence verification)

  • ping_count
  • (Only in Mode "ping" applicable)
    Changes the count of the used ping packets to recognize a present state. Depending on your network performance sometimes a packet can be lost or blocked.

    Default Value is 4 (packets)

    @@ -1641,12 +1665,18 @@ Options: Die Anzahl an Checks, welche in "absent" resultieren müssen, bevor der Status der PRESENCE-Definition auf "absent" wechselt. Mit dieser Funktion kann man die Abwesenheit eines Gerätes verifizieren bevor der Status final auf "absent" geändert wird. Wenn dieses Attribut auf einen Wert >1 gesetzt ist, werden die Readings "state" und "presence" auf den Wert "maybe absent" gesetzt, - bis der Status final auf "absent" oder "present" wechselt.

    - Standartwert ist 1 (keine Abwesenheitsverifizierung)

    + bis der Status final auf "absent" wechselt.

    + Standardwert ist 1 (keine Abwesenheitsverifizierung)

    +
  • presenceThreshold
  • + Die Anzahl an Checks, welche in "present" resultieren müssen, bevor der Status der PRESENCE-Definition auf "present" wechselt. + Mit dieser Funktion kann man die Anwesenheit eines Gerätes verifizieren bevor der Status final auf "present" geändert wird. + Wenn dieses Attribut auf einen Wert >1 gesetzt ist, werden die Readings "state" und "presence" auf den Wert "maybe present" gesetzt, + bis der Status final auf "present" wechselt.

    + Standardwert ist 1 (keine Anwesenheitsverifizierung)

  • ping_count
  • (Nur im Modus "ping" anwendbar)
    Verändert die Anzahl der Ping-Pakete die gesendet werden sollen um die Anwesenheit zu erkennen. Je nach Netzwerkstabilität können erste Pakete verloren gehen oder blockiert werden.

    - Standartwert ist 4 (Versuche)

    + Standardwert ist 4 (Versuche)

  • bluetooth_hci_device
  • (Nur im Modus "local-bluetooth" anwendbar)
    Sofern man mehrere Bluetooth-Empfänger verfügbar hat, kann man mit diesem Attribut ein bestimmten Empfänger auswählen, welcher zur Erkennung verwendet werden soll (bspw. hci0, hci1, ...). Es muss dabei ein vorhandener HCI-Gerätename angegeben werden wie z.B. hci0.