OpenHAB becoming aware of me… so to speak

I need my home to know if anybody is at home. On my Indigo installation I used to check if our iPhones were visible on the wifi network buy the latency was to long and I would normally get to far inside the house before I was discovered as my and the alarm would be trickered instead. So for OpenHAB I am working on using bluetooth instead.

First of I got hold of a USB bluetooth for my pi – and installed the drivers needed  for it to work and modified the examples on this page: I didn’t use the bluetooth binding but used org.openhab.binding.exec to be able to execute command line from OPenHAB

In the OpenHAB Scripts directory I added the to ping for my iPhones bluetooth MAC address


DEVICES=`l2ping F5:F2:7A:05:CB:7A -c 1`

if [[ $DEVICES = *received* ]]
curl –max-time 2 –connect-timeout 2 –header “Content-Type: text/plain” –request PUT –data “ON”
echo “Bluetooth pingscript has been executed. Device found” >> /opt/openhab/logs/openhab.log
curl –max-time 2 –connect-timeout 2 –header “Content-Type: text/plain” –request PUT –data “OFF”
echo “Bluetooth pingscript has been executed. Device not found >> /opt/openhab/logs/openhab.log

In the  Items directory I added the file BlutoothState.items
Switch TSiPhone

In my sitemap file I added this to the file:
Frame label="Bluetooth devices" {

Switch item=TSiPhone label=”TSiPhone” icon=””

And finally I added bluetoothPing.rules to the rules directory to trickier the bluetooth ping script every 30 sek.

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

rule “BluetoothPingRules”
Time cron “0,30 * * * * ?”

var String command
command = “/opt/openhab/configurations/scripts/”
executeCommandLine(command, 20000)


…now I need to make it a little more intelligent, first thing is probably to ping me less when it has seen me …

This link was helpfull:
I used this to install command wassudo apt-get install –no-install-recommends bluetooth

Leave a Reply