The PRESENCE module provides several possibilities to check the presence of mobile phones or similar mobile devices such as tablets.
This module provides several operational modes to serve your needs. These are:
- lan-ping - A presence check of a device via network ping in your LAN/WLAN
- fritzbox - A presence check by requesting the device state from the FritzBox internals (only available when running FHEM on a FritzBox!)
- local-bluetooth - A presence check by searching directly for a given bluetooth device nearby
- function - A presence check by using your own perl function which returns a presence state
- shellscript - A presence check by using an self-written script or binary which returns a presence state
- lan-bluetooth - A presence check of a bluetooth device via LAN network by connecting to a presenced or collectord instance
Each mode can be optionally configured with a specific check interval and a present check interval.
- check-interval - The interval in seconds between each presence check. Default value: 30 seconds
- present-check-interval - The interval in seconds between each presence check in case the device is present. Otherwise the normal check-interval will be used.
Define
Mode: lan-ping
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.
Example
define iPhone PRESENCE lan-ping 192.168.179.21
Mode: fritzbox
define <name> PRESENCE fritzbox <device-name/mac-address> [ <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 or can be substituted by the MAC address with the format XX:XX:XX:XX:XX:XX
This check is only applicable when FHEM is running on a FritzBox! The detection of absence can take about 10-15 minutes!
Example
define iPhone PRESENCE fritzbox iPhone-6
define iPhone PRESENCE fritzbox 00:06:08:05:0D:00
Mode: local-bluetooth
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.
Example
define iPhone PRESENCE local-bluetooth 0a:8d:4f:51:3c:8f
Mode: function
define <name> PRESENCE function {...} [ <check-interval> [ <present-check-interval> ] ]
Checks for a presence state via perl-code. You can use a self-written perl function to obtain the presence state of a specific device (e.g. via SNMP check).
The function must return 0 (absent) or 1 (present). An example can be found in the FHEM-Wiki.
Example
define iPhone PRESENCE function {snmpCheck("10.0.1.1","0x44d77429f35c")}
Mode: shellscript
define <name> PRESENCE shellscript "<path> [<arg1>] [<argN>]..." [ <check-interval> [ <present-check-interval> ] ]
Checks for a presence state via shell script. You can use a self-written script or binary in any language to obtain the presence state of a specific device (e.g. via SNMP check).
The shell must return 0 (absent) or 1 (present) on console (STDOUT). Any other values will be treated as an error
Example
define iPhone PRESENCE shellscript "/opt/check_device.sh iPhone"
Mode: lan-bluetooth
Checks for a bluetooth device with the help of presenced or collectord. They can be installed where-ever you like, just must be accessible via network.
The given device will be checked for presence status.
define <name> PRESENCE lan-bluetooth <bluetooth-address> <ip-address>[:port] [ <check-interval> ]
The default port is 5111 (presenced). Alternatly you can use port 5222 (collectord)
Example
define iPhone PRESENCE lan-bluetooth 0a:4f:36:d8:f9:89 127.0.0.1:5222
presenced
The presence is a perl network daemon, which provides presence checks of multiple bluetooth devices over network.
It listens on TCP port 5111 for incoming connections from a FHEM PRESENCE instance or a running collectord.
Usage:
presenced -d [-p <port>] [-P <filename>]
presenced [-h | --help]
Options:
-p, --port
TCP Port which should be used (Default: 5111)
-P, --pid-file
PID file for storing the local process id (Default: /var/run/presenced.pid)
-d, --daemon
detach from terminal and run as background daemon
-v, --verbose
Print detailed log output
-h, --help
Print detailed help screen
It uses the hcitool command (provided by a bluez installation)
to make a paging request to the given bluetooth address (like 01:B4:5E:AD:F6:D3). The devices must not be visible, but
still activated to receive bluetooth requests.
If a device is present, this is send to FHEM, as well as the device name as reading.
The presenced is available as:
collectord
The collectord is a perl network daemon, which handles connections to several presenced installations to search for multiple bluetooth devices over network.
It listens on TCP port 5222 for incoming connections from a FHEM presence instance.
Usage:
collectord -c <configfile> [-d] [-p <port>] [-P <pidfile>]
collectord [-h | --help]
Options:
-c, --configfile <configfile>
The config file which contains the room and timeout definitions
-p, --port
TCP Port which should be used (Default: 5222)
-P, --pid-file
PID file for storing the local process id (Default: /var/run/collectord.pid)
-d, --daemon
detach from terminal and run as background daemon
-v, --verbose
Print detailed log output
-l, --logfile <logfile>
log to the given logfile
-h, --help
Print detailed help screen
Before the collectord can be used, it needs a config file, where all different rooms, which have a presenced detector, will be listed. This config file looks like:
# room definition
# ===============
#
[room-name] # name of the room
address=192.168.0.10 # ip-address or hostname
port=5111 # tcp port which should be used (5111 is default)
presence_timeout=120 # timeout in seconds for each check when devices are present
absence_timeout=20 # timeout in seconds for each check when devices are absent
[living room]
address=192.168.0.11
port=5111
presence_timeout=180
absence_timeout=20
If a device is present in any of the configured rooms, this is send to FHEM, as well as the device name as reading and the room which has detected the device.
The collectord is available as:
Set
- statusRequest - Schedules an immediatly check.
- power - Executes the given power command which is set as attribute to power (on or off) the device (only when attribute "powerCmd" is set)
Get
Attributes
- do_not_notify
- readingFnAttributes
- disable
If this attribute is activated, an active check will be disabled.
Possible values: 0 => not disabled , 1 => disabled
Default Value is 0 (not disabled)
- ping_count
(Only in Mode "ping" on non-Windows machines 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)
- fritzbox_speed
(only for mode "fritzbox")
When this attribute is enabled, the network speed is checked in addition to the device state.
This only makes sense for wireless devices connected directly to the FritzBox.
Possible values: 0 => do not check speed, 1 => check speed when device is active
Default value is 0 (no speed check)
- powerCmd
Define a FHEM command, which powers on or off the device.
When executing the powerCmd (set command: power) following placeholders will be replaced by there corresponding values:
%NAME - name of the PRESENCE definition
%ADDRESS - the address of the PRESENCE definition as given in the define statement
%ARGUMENT - the argument given to the power set command (e.g. "on" or "off)
Example FHEM commands:
set PowerSwitch_1 on
set PowerSwitch_1 %ARGUMENT
"/opt/power_on.sh %ADDRESS"
{powerOn("%ADDRESS", "username", "password")}
Generated Events:
General Events:
- state: $state (absent|present|disabled|error|timeout) - The state of the device or "disabled" when the disable attribute is enabled
- powerCmd: (executed|failed) - power command was executed or has failed
Bluetooth specific events:
- device_name: $name - The name of the Bluetooth device in case it's present
presenced/collectord specific events:
- command_accepted: $command_accepted (yes|no) - Was the last command acknowleged and accepted by the presenced or collectord?
- room: $room - If the module is connected with a collector daemon this event shows the room, where the device is located (as defined in the collectord config file)
=end html
=begin html_DE
PRESENCE
Das PRESENCE Module bietet mehrere Möglichkteiten um die Anwesenheit von Handys/Smartphones oder anderen mobilen Geräten (z.B. Tablets) zu erkennen.
Dieses Modul bietet dazu mehrere Modis an um Anwesenheit zu erkennen. Diese sind:
- lan-ping - Eine Erkennung auf Basis von Ping-Tests im lokalen LAN/WLAN
- fritzbox - Eine Erkennung aufgrund der internen Abfrage des Status auf der FritzBox (nur möglich, wenn FHEM auf einer FritzBox läuft)
- local-bluetooth - Eine Erkennung auf Basis von Bluetooth-Abfragen durch den FHEM Server. Das Gerät muss dabei in Empfangsreichweite sein, aber nicht sichtbar sein
- function - Eine Erkennung mithilfe einer selbst geschriebenen Perl-Funktion, welche den Anwesenheitsstatus ermittelt.
- shellscript - Eine Erkennung mithilfe eines selbst geschriebenen Skriptes oder Programm (egal in welcher Sprache).
- lan-bluetooth - Eine Erkennung durch Bluetooth-Abfragen via Netzwerk (LAN/WLAN) in ein oder mehreren Räumen
Jeder Modus kann optional mit spezifischen Prüf-Intervallen ausgeführt werden.
- check-interval - Das normale Prüfinterval in Sekunden für eine Anwesenheitsprüfung. Standardwert: 30 Sekunden
- present-check-interval - Das Prüfinterval in Sekunden, wenn ein Gerät anwesend (present) ist. Falls nicht angegeben, wird der Wert aus check-interval verwendet
Define
Modus: lan-ping
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.
Beispiel
define iPhone PRESENCE lan-ping 192.168.179.21
Modus: fritzbox
define <name> PRESENCE fritzbox <Gerätename/MAC-Adresse> [ <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: <Gerätename>) muss dem Namen entsprechen, welcher im Menüpunkt "Heimnetz" auf der FritzBox-Oberfläche angezeigt wird oder kann durch die MAC-Adresse im Format XX:XX:XX:XX:XX:XX ersetzt werden.
Dieser Modus ist nur verwendbar, wenn FHEM auf einer FritzBox läuft! Die Erkennung einer Abwesenheit kann ca. 10-15 Minuten dauern!
Beispiel
define iPhone PRESENCE fritzbox iPhone-6
define iPhone PRESENCE fritzbox 00:06:08:05:0D:00
Modus: local-bluetooth
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)
Beispiel
define iPhone PRESENCE local-bluetooth 0a:4f:36:d8:f9:8
Modus: function
define <name> PRESENCE function {...} [ <Interval> [ <Anwesend-Interval> ] ]
Prüft den Anwesenheitsstatus mithilfe einer selbst geschriebenen Perl-Funktion (z.B. SNMP Abfrage).
Diese Funktion muss 0 (Abwesend) oder 1 (Anwesend) zurückgeben. Ein entsprechendes Beispiel findet man im FHEM-Wiki.
Beispiel
define iPhone PRESENCE function {snmpCheck("10.0.1.1","0x44d77429f35c")
Mode: shellscript
define <name> PRESENCE shellscript "<Skript-Pfad> [<arg1>] [<argN>]..." [ <Interval> [ <Anwesend-Interval> ] ]
Prüft den Anwesenheitsstatus mithilfe eines selbst geschrieben Skripts oder Programmes (egal in welcher Programmier-/Skriptsprache)
Der Aufruf dieses Skriptes muss eine 0 (Abwesend) oder 1 (Anwesend) auf der Kommandozeile (STDOUT) ausgeben. Alle anderen Werte/Ausgaben werden als Fehler behandelt.
Beispiel
define iPhone PRESENCE shellscript "/opt/check_device.sh iPhone"
Modus: lan-bluetooth
Prüft ein Bluetooth-Gerät auf Anwesenheit über Netzwerk mit Hilfe von presenced oder collectord. Diese können auf jeder Maschine installiert werden,
welche eine Standard-Perl-Umgebung bereitstellt und über Netzwerk erreichbar ist.
define <name> PRESENCE lan-bluetooth <Bluetooth-Adresse> <IP-Adresse>[:Port] [ <Interval> ]
Der Standardport ist 5111 (presenced). Alternativ kann man den Port 5222 (collectord) nutzen. Generell ist der Port aber frei wählbar.
Beispiel
define iPhone PRESENCE lan-bluetooth 0a:4f:36:d8:f9:89 127.0.0.1:5222
presenced
Der presenced ist ein Perl Netzwerk Dienst, welcher eine Bluetooth-Anwesenheitserkennung von ein oder mehreren Geräten über Netzwerk bereitstellt.
Dieser lauscht standardmäßig auf TCP Port 5111 nach eingehenden Verbindungen von dem PRESENCE Modul oder einem collectord.
Usage:
presenced -d [-p <port>] [-P <filename>]
presenced [-h | --help]
Options:
-p, --port
TCP Port which should be used (Default: 5111)
-P, --pid-file
PID file for storing the local process id (Default: /var/run/presenced.pid)
-d, --daemon
detach from terminal and run as background daemon
-v, --verbose
Print detailed log output
-h, --help
Print detailed help screen
Zur Bluetooth-Abfrage wird der Shell-Befehl "hcitool" verwendet (Paket: bluez)
um sogenannte "Paging-Request" an die gewünschte Bluetooth Adresse (z.B. 01:B4:5E:AD:F6:D3) durchzuführen. Das Gerät muss dabei nicht sichtbar sein, allerdings ständig aktiviert sein
um Bluetooth-Anfragen zu beantworten.
Wenn ein Gerät anwesend ist, wird dies an FHEM übermittelt zusammen mit dem Gerätenamen als Reading.
Der presenced ist zum Download verfügbar als:
collectord
Der collectord ist ein Perl Netzwerk Dienst, welcher Verbindungen zu mehreren presenced-Instanzen verwaltet um eine koordinierte Suche nach ein oder mehreren Bluetooth-Geräten über Netzwerk durchzuführen.
Er lauscht auf TCP port 5222 nach eingehenden Verbindungen von einem PRESENCE Modul.
Usage:
collectord -c <configfile> [-d] [-p <port>] [-P <pidfile>]
collectord [-h | --help]
Options:
-c, --configfile <configfile>
The config file which contains the room and timeout definitions
-p, --port
TCP Port which should be used (Default: 5222)
-P, --pid-file
PID file for storing the local process id (Default: /var/run/collectord.pid)
-d, --daemon
detach from terminal and run as background daemon
-v, --verbose
Print detailed log output
-l, --logfile <logfile>
log to the given logfile
-h, --help
Print detailed help screen
Bevor der collectord verwendet werden kann, benötigt er eine Konfigurationsdatei in welcher alle Räume mit einem presenced-Agenten eingetragen sind. Diese Datei sieht wie folgt aus:
# Raum Definitionen
# =================
#
[Raum-Name] # Name des Raumes
address=192.168.0.10 # IP-Adresse oder Hostname
port=5111 # TCP Port welcher benutzt werden soll (standardmäßig 5111)
presence_timeout=120 # Prüfinterval in Sekunden für jede Abfrage eines Gerätes, welches anwesend ist
absence_timeout=20 # Prüfinterval in Sekunden für jede Abfrage eines Gerätes, welches abwesend ist
[Wohnzimmer]
address=192.168.0.11
port=5111
presence_timeout=180
absence_timeout=20
Wenn ein Gerät in irgend einem Raum anwesend ist, wird dies an FHEM übermittelt, zusammen mit dem Gerätenamen und dem Raum, in welchem das Gerät erkannt wurde.
Der collectord ist zum Download verfügbar als:
Set
- statusRequest - Startet einen sofortigen Check.
- power - Startet den powerCmd-Befehl welche durch den Parameter powerCmd angegeben ist (Nur wenn das Attribut "powerCmd" definiert ist)
Get
Attributes
- do_not_notify
- readingFnAttributes
- disable
Wenn dieses Attribut aktiviert ist, wird die Anwesenheitserkennung nicht mehr durchgeführt.
Mögliche Werte: 0 => Erkennung durchführen , 1 => Keine Erkennungen durchführen
Standardwert ist 0 (Erkennung durchführen)
- ping_count
(Nur im Modus "ping" anwendbar auf Nicht-Windows-Maschinen)
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)
- fritzbox_speed
(Nur im Modus "fritzbox")
Zusätzlich zum Status des Geräts wird die aktuelle Verbindungsgeschwindigkeit ausgegeben
Das macht nur bei WLAN Geräten Sinn, die direkt mit der FritzBox verbunden sind. Bei abwesenden Geräten wird als Geschwindigkeit 0 ausgegeben.
Mögliche Werte: 0 => Geschwindigkeit nicht prüfen, 1 => Geschwindigkeit prüfen
Standardwert ist 0 (Keine Geschwindigkeitsprüfung)
- powerCmd
Ein FHEM-Befehl, welcher das Gerät schalten kann.
Wenn der power-Befehl ausgeführt wird (set-Befehl: power) werden folgende Platzhalter durch ihre entsprechenden Werte ersetzt:
%NAME - Name der PRESENCE-Definition
%ADDRESS - Die überwachte Addresse der PRESENCE Definition, wie sie im define-Befehl angegeben wurde.
%ARGUMENT - Das Argument, was dem Set-Befehl "power" übergeben wurde. (z.B. "on" oder "off")
Beispielhafte FHEM-Befehle:
set PowerSwitch_1 on
set PowerSwitch_1 %ARGUMENT
"/opt/power_on.sh %ADDRESS"
{powerOn("%ADDRESS", "username", "password")}
Generierte Events:
Generelle Events:
- state: $state (absent|present|disabled|error|timeout) - Der Anwesenheitsstatus eine Gerätes (absent = abwesend; present = anwesend) oder "disabled" wenn das disable-Attribut aktiviert ist
- powerCmd: (executed|failed) - Ausführung des power-Befehls war erfolgreich.
Bluetooth-spezifische Events:
- device_name: $name - Der Name des Bluetooth-Gerätes, wenn es anwesend (Status: present) ist
presenced-/collectord-spezifische Events:
- command_accepted: $command_accepted (yes|no) - Wurde das letzte Kommando an den presenced/collectord akzeptiert (yes = ja, no = nein)?
- room: $room - Wenn das Modul mit einem collectord verbunden ist, zeigt dieses Event den Raum an, in welchem dieses Gerät erkannt wurde (Raumname entsprechend der Konfigurationsdatei des collectord)
=end html_DE
=cut
| |