Wednesday, November 25, 2015

OpenHAB and Proximity

A big part of being able to automate with rules is the ability to know who is home. Proximity is one of the items that needs to be transferred from DomotiGA to openHAB. There are two main ways of doing this. OpenHAB supports a Bluetooth binding which requires a bit of working to get setup. Not wanting to mess with that, I decided to just adapt my original shell script to openHAB as well as incorporating some changes from https://code.google.com/p/openhab-samples/wiki/Tricks#Use_cheap_bluetooth_dongles_on_remote_PCs_to_detect_your_phone/w. This example page also has some good rules on using not only phones but laptops and such on the network to track who is home.  You can have all kinds of fun with that!




For example, with the Colorific bulb you need BlueZ setup so we can use the hcitool to do the scan. I opted to just do a scan for devices in range so you don't have to mess with pairing. It seems to work even if you are not discoverable. The second part will be to add WiFi scanning in case your Bluetooth is off or vice versa (WiFi is off but Bluetooth is on). Unlike the DomotiGA version which is called from a device setting this will run in a loop and use cURL to put to the HTTP rest API in openHAB.

First we need to create a few items to track the status of each person and an overall one in case we want to write a rule based on if anyone is home. Here is my items config.

all.items
 
//Proxmitiy
String  occupiedState           "Someone home"         (gNetwork)
String  device_WillPhone        "William Phone"        (gNetwork)
String  device_JennPhone        "Jenn Phone"           (gNetwork)
 

Since I am using a group for all proximity items the sitemap is really simple.  This also reduces the number of lines used on the sitemap main page.

default.sitemap
 
Frame label="Home?" {
                Group item=gNetwork
        } 
 

Finally, the shell script that makes the magic happen. This version is just the Bluetooth scanning but it is setup to add WiFi as well. I wrote it so that you can easily add more devices by adding another entry to the array. It will check each device in the array without having to change the main loop. Follow the repo on github to get the updated version when I add WiFi support like the DomotiGA version. https://github.com/FriedCircuits/Home_Automation/blob/master/openHAB/Proximity/device_scan.sh

I hope this helps you easily get proximity working. Comment below if you found it helpful and/or your variation. It's nice to see people base their setup on something you created. It's open source at its best - the community working together.  



3 comments:

  1. Thnx for sharing, will try this in the near future :)

    ReplyDelete
  2. Thnx for sharing, will try this in the near future :)

    ReplyDelete
  3. I am so glad I found your blog. It is clear, concise, and very helpful. Thanks for putting this together.

    ReplyDelete