Hi, hoping someone can help me as have spent the day going mad with this. I’m trying to do presence detection of my iPhone using a combination of the network binding and mqtt with user-defined Regions in Owntracks (i’m using OpenHAB 2, so unable to use mqttitude) I have these items declared:
Group StuMobiles
Switch Presence
Switch Stu_MainPhone (StuMobiles) {channel="network:device:192_168_0_8:online"}
String StuRegionAction {mqtt="<[mosquitto:owntracks/stu/iPhone6/event:state:JSONPATH($.event)]"}
Now when I check my event.log file, i get things like:
2016-04-09 19:55:22.905 [GroupItemStateChangedEvent] - StuMobiles changed from OFF to ON through Stu_MainPhone
2016-04-09 19:55:22.906 [ItemStateChangedEvent ] - Stu_MainPhone changed from OFF to ON
2016-04-09 19:53:53.315 [ItemStateChangedEvent ] - StuRegionAction changed from leave to enter
…which is all good.
Unfortunately it’s well-known fact that the iPhone flaps around a bit on WiFi when it sleeps and checks in again, so all I want to do is say that when StuMobiles is ON, and StuRegionAction is enter, then set Presence to ON. And when StuMobiles is OFF, and StuRegionAction is leave, then set Presence to OFF. I’ve written this rules file, but it disregards the StuRegionAction setting, despite the conditions in the When, so Presence just switches on and off with StuMobiles. Where am I going wrong please?
import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*
rule "Stu is home"
when
Item StuMobiles changed from OFF to ON and
Item StuRegionAction changed from leave to enter
then
logInfo("PresenceCheck", "Stu is home")
sendCommand(Presence, ON)
sendMail("xxxxx@gmail.com","Stuart is home","Stuart's iPhone has arrived home")
end
rule "Stu has left home"
when
Item StuMobiles changed from ON to OFF and
Item StuRegionAction changed from enter to leave
then
logInfo("PresenceCheck", "Stu has left home")
sendCommand(Presence, OFF)
sendMail("xxx@gmail.com","Stuart has left home","Stuart's iPhone has left home")
end
I also tried these “when” conditions, but they didn’t do anything at all to Presence
Item StuMobiles is ON and
Item StuRegionAction is enter
and
Item StuMobiles is OFF and
Item StuRegionAction is leave