How to control the presence using wifi to mobile phones?

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!!!

The changed trigger will only detect changes from ON to OFF, OFF to ON or uninitialized to ON or OFF. I’m pretty sure you want to trigger through “received update”, but be aware that the group will trigger multiple times per item update, and worse, it will trigger each time the nh binding will send an update. The better solution would be to trigger through single items:

rule "Coming home"
when
    Item phone1 changed or //maybe better: ... changed to ON
    Item phone2 changed
then
    //...
end

Danke Udo!

I’m trying to write on screen when someone is at home or not. If the last check was less than 5 minutes ago and was ON, then he is at home. Otherwise show this person as “away”. Any Idea how could I do this?

Thank you!