",$states);
+ my $dnh = $defs{PRESENCE2_getDaemonName()};
+
+ readingsBeginUpdate($dnh);
+ foreach (@evts){
+ my ($eName,$eSstate) = split('\|',$_);
+ readingsBulkUpdate($dnh, "evt_".$eName, $eSstate);
+ }
+ readingsEndUpdate($dnh, 1);
+
+ foreach (@evts){
+ my ($eName,$eSstate) = split('\|',$_);
+ readingsSingleUpdate($defs{$eName}, "presentState", $eSstate,1);
+ }
+}
+
+1;
+
+=pod
+=item helper
+=item summary provides PRESENCE2 detection checks
+=item summary_DE stellt eine Anwesenheitserkennung zur Verfügung
+=begin html
+
+
+PRESENCE2
+
+ The PRESENCE2 module provides several possibilities to check the PRESENCE2 devices such as mobile phones or tablets.
+ Furthermore FHEM or system level actions can be executed and parsed periodicaly
+ Additional FHEM entites can be superviced for regular activity.
+
+ This module provides several operational modes to serve your needs. These are:
+
+ - lan-ping - device PRESENCE2 check utilizing network ping.
+ - function - executing user defined FHEM command.
+ - shellscript - executing user defined OS command.
+ - bluetooth - bluetooth device scan from FHEM server .
+ - lan-bluetooth - device PRESENCE2 check via LAN network by connecting to a PRESENCE2d or collectord instance.
+
+
+ Daemon entity: A daemon entity is auto-created if not definition of a PRESENCE2 entity.
+ The daemon schedules and executes the ping and scan actions for all entites except lan-bluetooth. It cyclic executes as defined by attr intervalNormal.
+ Since the daemon executes the scan activities (except lan-bluetooth) any report and detection cannot be faster than the deamon cycle.
+
+
+ Define
+ Mode: lan-ping
+ define <name> PRESENCE2 lan-ping <ip-address>
+ Checks for a network device via PING requests and reports its PRESENCE2 state.
+ Example
+ define iPhone PRESENCE2 lan-ping 192.168.179.21
+
+
Mode: function
+ define <name> PRESENCE2 function cmd:<command> scan:<scanExpression>
+ Executes the FHEM command and parses the reply for scanExpression.
+
+ - command can be any FHEM expression such as
+ get PsnceDaemon list normal
+ {ReadingsVal("PsnceDaemon","state","empty")}
+
+
+ - scanExpression is a string or regex to parse the reply
+
+
+ Example
+ define iPhone PRESENCE2 function cmd:{snmpCheck("10.0.1.1","0x44d77429f35c")} scan:1
+
+
Mode: shellscript
+ define <name> PRESENCE2 shellscript cmd:<command> scan:<scanExpression>
+ Executes the OS command and parses the reply for scanExpression.
+ Example
+ define iPhone PRESENCE2 shellscript cmd:/opt/check_device.sh iPhone scan:1
+
+
Mode: bluetooth
+ define <name> PRESENCE2 bluetooth <address>
+ Scans for the MAC address on the FHEM server's BT interface.
+ Example
+ define iPhone PRESENCE2 bluetooth 0a:8d:4f:51:3c:8f
+
+
Mode: lan-bluetooth
+ define <name> PRESENCE2 lan-bluetooth cmd:<address> scan:<ip-address>
+ Checks for a bluetooth device with the help of PRESENCE2d or collectord. They can be installed where-ever you like, however accessible via network.
+ The given device will be checked for PRESENCE2 status.
+ The default port is 5111 (PRESENCE2d). Alternatly you can use port 5222 (collectord)
+ Example
+ define iPhone PRESENCE2 lan-bluetooth 0a:4f:36:d8:f9:89 127.0.0.1:5222
+ PRESENCE2d
+ PRESENCE2 is a perl network daemon, which provides PRESENCE2 checks of multiple bluetooth devices over network.
+ It listens on TCP port 5111 for incoming connections from a FHEM PRESENCE2 instance or a running collectord.
+
+ Executes the OS command and parses the reply for scanExpression.
+ Example
+ define iPhone PRESENCE2 lan-bluetooth 0a:8d:4f:51:3c:8f
+
+
+Usage:
+ PRESENCE2d [-d] [-p <port>] [-P <filename>]
+ PRESENCE2d [-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/PRESENCE2d.pid)
+ -d, --daemon
+ detach from terminal and run as background daemon
+ -n, --no-timestamps
+ do not output timestamps in log messages
+ -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 PRESENCE2d is available as:
+
+
+ lePRESENCE2d
+ lePRESENCE2d is a Perl network daemon that provides PRESENCE2 checks of
+ multiple bluetooth devices over network. In contrast to PRESENCE2d,
+ lePRESENCE2d covers Bluetooth 4.0 (low energy) devices, i. e.
+ Gigaset G-Tags, FitBit Charges.
+ lePRESENCE2d listens on TCP port 5333 for connections of a PRESENCE2 definition
+ or collectord.
+
+ To detect the PRESENCE2 of a device, it uses the command hcitool lescan (package:
+ bluez) to continuously listen to
+ beacons of Bluetooth LE devices.
+
+
+ If a device is present, this is send to FHEM, as well as the device name as reading.
+
+ The PRESENCE2d is available as:
+
+
+ collectord
+
+ The collectord is a perl network daemon, which handles connections to several PRESENCE2d installations to search for multiple bluetooth devices over network.
+
+ It listens on TCP port 5222 for incoming connections from a FHEM PRESENCE2 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
+ -n, --no-timestamps
+ do not output timestamps in log messages
+ -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 PRESENCE2d 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)
+ PRESENCE2_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
+ PRESENCE2_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.
+ - clearCounts - reset counter values.
+ - statusRequest daemon - (daemon only). clear all counts from deamon.
+ - statusRequest allEntities - (daemon only). clear all counts from deamon and all PRESENCE2 entities.
+
+
+
+
+ Get
+
+ - list normal - execute list command.
+ - list full - execute list command and include hidden entries.
+ - childInfo PRESENCE2 - (daemon only). show all running forked processes started by PRESENCE2.
+ - childInfo all - (daemon only). show all running forked processes.
+ - statusInfo definition - (daemon only). return a table of the definition for all PRESENCE2 entities.
+ - statusInfo stats - (daemon only). return a table of the status for all PRESENCE2 entities.
+
+
+
+
+ Attributes
+
+ - disable
+ If activated, an check is disabled and state is set to disabled.
+ - interavalAbsence
+ Time in seconds to check status, default 30. It is adjusted to the deamons cycle.
+ - interavalPresent
+ Time in seconds to check status if the device is in state present. It is adjusted to the deamons cycle.
+ Not applicable for daemon entity
+ - thresholdAbsence
+ The number of checks that have to result in "absent" before the state is changed to "absent".
+ If this attribute is set to a value >1, the reading PRESENCE2 will be set to "maybe absent" during the absence verification.
+ - prGroup
+ Assign the entity to a group for examination purpose. An entity can be assigned to multiple groups. Daemon will accumulate the status by groups.
+ - thresholdAbsence
+ Display options for group readings. Options are condensed or verbose.
+ - presentCycle
+ This attribut may be set to any (ANY) instance in FHEM. It defines the requested cycle time that a reading of the entiy needs to be renewed. The daemon will check the reading's update in its interval. Upon violation of the required timing the reading will toggle to absent.
+ The Reading to be superviced is defined in attr presentReading and defaults to state.
+ - presentReading
+ This attribut may be set to any (ANY) instance in FHEM. It defines the reading name that is supervices by presentCycle.
+
+
+
+
+ Readings/events:
+
+ General
+
+ - state: (absent|present|disabled) - The state of the device, check errors or "disabled" when the disable attribute is enabled
+ - PRESENCE2: (absent|maybe absent|present|maybe present) - The PRESENCE2 state of the device. The value "maybe absent" only occurs if thresholdAbsence is activated.
+ - appearCnt: count of entering availale
+ - lastAppear: timestamp of last appearence
+ - lastDisappear: timestamp of last disappearence
+ - thresHldCnt: current thresdold counter. 0 = threshold not active
+
+
+ Daemon specific readings/events:
+
+ - daemonMaxScanTime: maximum time the scan job used. Should be less than intervalNormal to avoid skip.
+ - daemonSkipCnt: counter of skipping the daemon job due to collision.
+ - pGrp_<group>: counter summary of entites assigned to <group>
+ - pGrp_<group>_ab: verbose counter summary of entites assigned to <group> : absent entities
+ - pGrp_<group>_dis: verbose counter summary of entites assigned to <group> : disabled entities
+ - pGrp_<group>_pres: verbose counter summary of entites assigned to <group> : present entities
+ - pr_<entity>: status of the PRESENT supervision - see presentCycle
+ - evt_<entiy>: status of the event supervision - see presentCycle
+
+
+ Bluetooth specific readings/events:
+
+ - device_name: $name - The name of the Bluetooth device in case it's present
+
+
+
+
+=end html
+
+=cut