Hi there,
I’m a complete newbie with OpenHab. I’m trying to just creating a screen where monitor if someone is at home or not.
I’m using this sample, the part of "Check presence by detecting WiFi phones/tablets"
So my presence.items looks like:
Group gMobiles
Switch Presence
Switch phone1 (gMobiles) {nh="android-xxxxx"} // Here I have replaced "android-xxxxx" with my mobile phone wifi SID
Switch phone2 (gMobiles) {nh="android-yyyyy"}
My presence.sitemap looks like this:
sitemap default label="Presencia" {
Frame label="Presencia" {
Switch item=phone1
Switch item=phone2
Switch item=Presence label="Presence"
}
}
And presence.rules like this. I have commented some lines because I got a couple of errors in openHAB Designer (Couldn’t resolve reference to JvmIdentifiableElement’now’ and the same for minus.Minutes)
rule "Periodically check presence"
when
Time cron "0 */5 * * * ?"
then
if (Presence.state == ON)
{
if(gMobiles.members.filter(s | s.state == ON).size == 0) {
logInfo("PresenceCheck", "No phone within reach, checking for flapping")
if(gMobiles.members.filter(s | s.changedSince(now.minusMinutes(5))).size == 0) {
logInfo("PresenceCheck", "Nobody is at home")
sendCommand(Presence, OFF)
}
}
}
else
{
//For initialisation. If Presence is undefined or off, although it should be on.
if(gMobiles.members.filter(s | s.state == ON).size > 0) {
sendCommand(Presence, ON)
}
else if (Presence.state == Undefined || Presence.state == Uninitialized) {
sendCommand(Presence, OFF)
}
}
end
rule "Coming home"
when
Item gMobiles changed
then
if (Presence.state != ON) {
if(gMobiles.members.filter(s | s.state == ON).size > 0) {
logInfo("PresenceCheck", "Somebody is home")
sendCommand(Presence, ON)
}
}
end
It doesn’t work. Any ideas about what I’m doing wrong?
Thank you!!!