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: https://github.com/openhab/openhab/wiki/Samples-Tricks 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 bt_check.sh to ping for my iPhones bluetooth MAC address

#!/bin/bash

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

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

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 bt_check.sh 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”
when
Time cron “0,30 * * * * ?”
then

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

end

…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: https://www.raspberrypi.org/learning/robo-butler/bluetooth-setup/
I used this to install command wassudo apt-get install –no-install-recommends bluetooth