Presence Detection using Bluetooth and WiFi

Home automation often relies on the ability to detect whether someone is present within the house or not and perform different action as appropriate. Most people have a mobile phone on them so we can use the presence of, or lack of, these devices to relatively accurately determine whether someone is home or not.

Bluetooth Presence Detection Script

The devices dictionary holds a set of key:value pairs. In this case the key is the name of the switch set up in OpenHab to hold the status and the value is the Bluetooth device address. Additional devices can be added as necessary. Provided that Bluetooth on the device is switched on (it doesn’t have to be set to discoverable) and the device is within range, the script should be able to detect it.

WiFi Presence Detection Script

The devices dictionary holds a set of key:value pairs. In this case the key is the name of the switch set up in OpenHab to hold the status and the value is the IP address assigned to the device. Additional devices can be added as necessary. This script assumes that a device will always have the same IP address so your router should be set up accordingly. This will send one ping packet (
-c1 ) silently (
-q ) to the device, waiting a maximum of one second (
-W1 ) for a response. As the script calls the ping silently, the exit code is used to determine whether the device was found: