diff --git a/fhem/FHEM/73_PRESENCE.pm b/fhem/FHEM/73_PRESENCE.pm index f8b2f9497..b0b2c3eef 100755 --- a/fhem/FHEM/73_PRESENCE.pm +++ b/fhem/FHEM/73_PRESENCE.pm @@ -63,9 +63,9 @@ PRESENCE_Define($$) my @a = split("[ \t]+", $def); my $dev; - if($a[2] ne "lan-bluetooth" and not (@a == 4 or @a == 5)) + if($a[2] ne "lan-bluetooth" and not (@a == 4 or @a == 5 or @a == 6)) { - my $msg = "wrong syntax: define PRESENCE [ ]"; + my $msg = "wrong syntax: define PRESENCE [ [ ] ]"; Log 2, $msg; return $msg; } @@ -82,16 +82,18 @@ PRESENCE_Define($$) my $address = $a[3]; my $timeout = (defined($a[4]) ? $a[4] : 30); + my $presence_timeout = (defined($a[5]) ? $a[5] : $timeout); + $timeout = (defined($a[5]) ? $a[5] : 30) if($destination eq "lan-bluetooth"); - + $presence_timeout = (defined($a[6]) ? $a[6] : 30) if($destination eq "lan-bluetooth"); $hash->{ADDRESS} = $address; - $hash->{TIMEOUT} = $timeout; - + $hash->{TIMEOUT_NORMAL} = $timeout; + $hash->{TIMEOUT_PRESENT} = $presence_timeout; if(defined($timeout) and not $timeout =~ /^\d+$/) { - my $msg = "timeout must be a number"; + my $msg = "check-interval must be a number"; Log 2, "PRESENCE: ".$msg; return $msg; } @@ -99,11 +101,27 @@ PRESENCE_Define($$) if(defined($timeout) and not $timeout > 0) { - my $msg = "timeout must be greater than zero"; + my $msg = "check-interval must be greater than zero"; Log 2, "PRESENCE: ".$msg; return $msg; } + + if(defined($presence_timeout) and not $presence_timeout =~ /^\d+$/) + { + my $msg = "presence-check-interval must be a number"; + Log 2, "PRESENCE: ".$msg; + return $msg; + } + + + if(defined($presence_timeout) and not $presence_timeout > 0) + { + my $msg = "presence-check-interval must be greater than zero"; + Log 2, "PRESENCE: ".$msg; + return $msg; + } + if(($destination eq "local-bluetooth" or $destination eq "lan-bluetooth") and not $address =~ /^\s*([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}\s*$/) { my $msg = "given address is not a bluetooth hardware address"; @@ -357,7 +375,7 @@ PRESENCE_DoInit($) unless($hash->{helper}{DISABLED}) { - DevIo_SimpleWrite($hash, $hash->{ADDRESS}."|".$hash->{TIMEOUT}."\n", 0); + DevIo_SimpleWrite($hash, $hash->{ADDRESS}."|".$hash->{TIMEOUT_NORMAL}."\n", 0); } else { @@ -627,7 +645,7 @@ PRESENCE_ProcessLocalScan($) unless($local) { RemoveInternalTimer($hash); - InternalTimer(gettimeofday()+$hash->{TIMEOUT}, "PRESENCE_StartLocalScan", $hash, 0) unless($hash->{helper}{DISABLED}); + InternalTimer(gettimeofday()+($a[2] eq "present" ? $hash->{TIMEOUT_PRESENT} : $hash->{TIMEOUT_NORMAL}), "PRESENCE_StartLocalScan", $hash, 0) unless($hash->{helper}{DISABLED}); } } 1; @@ -652,17 +670,17 @@ PRESENCE_ProcessLocalScan($) Define

    Mode: lan-ping

    - define <name> PRESENCE lan-ping <ip-address> [ <check-interval> ]
    + define <name> PRESENCE lan-ping <ip-address> [ <check-interval> [ <present-check-interval> ] ]

    Checks for a network device via PING requests and reports its presence state.

    Mode: fritzbox

    - define <name> PRESENCE fritzbox <device-name> [ <check-interval> ]
    + define <name> PRESENCE fritzbox <device-name> [ <check-interval> [ <present-check-interval> ] ]

    Checks for a network device by requesting the internal state on a FritzBox via ctlmgr_ctl. The device-name must be the same as shown in the network overview of the FritzBox

    Mode: local-bluetooth

    - define <name> PRESENCE local-bluetooth <bluetooth-address> [ <check-interval> ]
    + define <name> PRESENCE local-bluetooth <bluetooth-address> [ <check-interval> [ <present-check-interval> ] ]

    Checks for a bluetooth device and reports its presence state. For this mode the shell command "hcitool" is required (provided with a bluez installation under Debian via APT), as well as a functional bluetooth device directly attached to your machine.

    @@ -845,18 +863,18 @@ Options: Define

      Modus: lan-ping

      - define <name> PRESENCE lan-ping <IP-Addresse oder Hostname> [ <Interval> ]
      + define <name> PRESENCE lan-ping <IP-Addresse oder Hostname> [ <Interval> [ <Anwesend-Interval> ] ]

      Prüft ob ein Gerät über Netzwerk (üblicherweise WLAN) auf Ping-Anfragen reagiert und setzt entsprechend den Anwesenheitsstatus.

      Modus: fritzbox

      - define <name> PRESENCE fritzbox <device-name> [ <Interval> ]
      + define <name> PRESENCE fritzbox <device-name> [ <Interval> [ <Anwesend-Interval> ] ]

      Prüft ob ein Gerät welches per WLAN mit der FritzBox verbunden ist, erreichbar durch Abfrage des Status mit dem Befehl ctlmgr_ctl. Der Gerätename (Parameter: <device-name>) muss dem Namen entsprechen, welcher im Menüpunkt "Heimnetz" auf der FritzBox-Oberfläche angezeigt wird.

      Modus: local-bluetooth

      - define <name> PRESENCE local-bluetooth <Bluetooth-Adresse> [ <Interval> ]
      + define <name> PRESENCE local-bluetooth <Bluetooth-Adresse> [ <Interval> [ <Anwesend-Interval> ] ]

      Prüft ob ein Bluetooth-Gerät abgefragt werden kann und meldet dies als Anwesenheit. Für diesen Modus wird der Shell-Befehl "hcitool" benötigt (wird durch das Paket bluez bereitgestellt), sowie ein funktionierender Bluetooth-Empfänger (intern oder als USB-Stick)