openHAB Proximity Update

wpsuperadmin HomeAutomation, openhab Leave a Comment

Just a quick update to the proximity tracking. The original post was just using Bluetooth which tends to not be completely reliable. So we need a backup such as WiFi. OpenHAB has a binding that can check for network devices. Between this and the device scan script for BT, we are set.

Just need to add an item for each device you want to track on the network. This can be used to see if a laptop is on or even check to make sure a sensor or something it alive.

Install the NetworkHealth binding – sudo apt-get install openhab-addon-binding-networkhealth

There isn’t much in openhab.cfg to figure. I just setup the cache period to 60. Just restart openHAB if you make a change and load it to the new binding.

Items

 
Switch wifi_Will "Will Wifi" (gNetwork) {nh="Note5"}
Switch wifi_Jenn "Jenn Wifi" (gNetwork) {nh="Jenn-iPhone"}

The devices in the items config can be an IP address or host name. Using the hostname allows you to not have to set a static IP or reservation in DHCP. I already had reservations so these host names are set in the router. It looks like in iOS you can’t change the host name but setting it in my router allowed me to control it. Android uses the device name you set in settings.

Sitemap

 
Group item=gNetwork icon="present"

I put both devices in a group and just used that to add it to the sitemap. Then you can easily add more devices to track.

Then just update the occupied rule to take the other items into account.

Rule:

 
rule "Update Presence to home"
when
Item wifi_Will changed from OFF to ON or
Item wifi_Jenn changed from OFF to ON or
Item device_WillPhone changed from OFF to ON or
Item device_WillPhone changed from OFF to ON
then
occupiedState.postUpdate(ON)
end


rule "Update Presence to away"
when
Item wifi_Will changed from ON to OFF or
Item wifi_Jenn changed from ON to OFF or
Item device_WillPhone changed from ON to OFF or
Item device_WillPhone changed from ON to OFF
then
if(wifi_Will.state==OFF && wifi_Jenn.state==OFF && device_WillPhone.state==OFF && device_JennPhone.state==OFF){
occupiedState.postUpdate(OFF)
}
end

There is a bug in the rule though, the occuipedState isn’t quite working. Everyone leaves and it’s still on. So I will need to troubleshoot that a bit more. (Hmm… I noticed I am using postUpdate vs sendCommand…)

References:
https://github.com/openhab/openhab/wiki/Network-Health-Binding
https://github.com/openhab/openhab/wiki/Samples-Tricks#check-presence-by-detecting-wifi-phonestablets

Leave a Reply