Like many OpenHAB users, I wanted to create rules based on when my wife and I arrived or left our home. When I enabled the “Home Location” settings in my Hue iPhone app, I noticed a new item in the CLIP API Debugger. Then I realized I had an easy geofencing solution already in my pocket.
Here’s what the iPhone presence looks like in the Hue CLIP API Debugger (https://www.developers.meethue.com/documentation/getting-started).
"13": {
"state": {
"presence": false,
"lastupdated": "2018-04-16T12:05:02"
},
"config": {
"on": true,
"reachable": true
},
"name": "iPhone",
"type": "Geofence",
"modelid": "HA_GEOFENCE",
"manufacturername": "Philips",
"swversion": "1.0",
"uniqueid": "L_02_Z4AX6",
"recycle": false
},
With this info I created OpenHAB items like this:
String HUE_Presence_Joseph_iPhone <present> (gSkur) { http="<[HTTP://10.0.0.126/api/<API KEY>/sensors/13:3000:JS(getHuePresence.js)]" }
and getHuePresence.js
(function(i) {
var json = JSON.parse(i);
return ((json['state']['presence'])) == true ? "ON" : "OFF";
})(input)
The == true ? “ON” : “OFF”; is needed due to a problem with using “true” in OpenHAB rules (Item item_name changed from true to false does not work).
So far, I have just played with voice & text notifications using the new binding to control amazon echo devices (https://github.com/openhab/openhab2-addons/issues/3083).
import org.joda.datetime.DateTime
rule "Hue Joseph Presence OFF"
when
Item HUE_Presence_Joseph_iPhone changed from ON to OFF
then
sendMail("4153850297@vtext.com", "HUE_Presence_Joseph_iPhone", "Item HUE_Presence_Joseph_iPhone changed from ON to OFF.")
logInfo("HUE", "HUE_Presence_Joseph_iPhone: " + HUE_Presence_Joseph_iPhone.state)
end
rule "Hue Joseph Presence ON"
when
Item HUE_Presence_Joseph_iPhone changed from OFF to ON
then
sendMail("4153850297@vtext.com", "Security Master Bedroom", "Item HUE_Presence_Joseph_iPhone changed from OFF to ON.")
logInfo("HUE", "HUE_Presence_Joseph_iPhone: " + HUE_Presence_Joseph_iPhone.state)
//hue_0100_0017882c2e3c_23_brightness.sendCommand("100")
if (HUE_Presence_Rachel_iPhone.state == ON ) //If my wife is home, have Alexa tell her so her boyfriend has time to get the hell out of the house.
{
if(now.getHourOfDay > 9 && now.getHourOfDay < 22 ) //but only between 9am and 10om
{
//FF_Office_Light.sendCommand(100)
OfficeBot_Remind.sendCommand("Joseph is home")
Bedroom_Remind.sendCommand("Joseph is home")
//hue_0100_0017882c2e3c_23_brightness.sendCommand("2")
logInfo("HUE", "HUE_Presence_Joseph_iPhone: its between 9 and 22: " + now.getHourOfDay)
}
else
{
//hue_0100_0017882c2e3c_23_brightness.sendCommand("2")
logInfo("HUE", "HUE_Presence_Joseph_iPhone: its NOT between 9 and 22: " + now.getHourOfDay)
}
}
end
Also when you are using the Hue CLIP API Debugger you can simulate arrival and departure like this:
OR conversely using
{"state":{"presence":true}}
or
{"state":{"presence":false}}
So you don’t need to leave your house to test your rules.