import org.openhab.model.script.actions.Timer
var Timer myTimer = null
rule "Presence Timer"
when
Item Person1 changed or Item Person2 changed
then
if(Person1.state == ON || Person2.state == ON)
Presence_Timer.sendCommand(ON)
else
if(myTimer!==null) {
myTimer.cancel
myTimer=null }
myTimer=createTimer(now.plusMinutes(5), [|
Presence_Timer.sendCommand(if(Person1.state == OFF && Person2.state == OFF) OFF)
])
end
So, very simple, Presence_Timer is a dummy switch which is a member of Presence group switch, and it will not allow for Presence group to go down for 5 minutes after all members went OFF. for coming ON (coming back home) there is no delay.
Hi, the Presence group switch is switched on by one of these devices and switched off by both devices correct.
This timer is a protection for cases like this:
1 person left the apartment. The whole presence group now depends on 1 phone which might be crappy and had showed loss of wifi connection for periods of few minutes during the night.
I dont want my lights to go on off during the night because my Lineage OS google-free phone is not so reliable on keeping the wifi connection stable
So if your phone reports as OFF for few minutes and then comes back ON (or you went out to take out the trash) your apartment will not go to all systems shutdown mode as the timer will override it and it will not allow the Presence group to go immediately OFF.
Also to mention, I am not using arping network binding, Iām running openwrt on a router, and I have a script on the router that runs every minute, checks wlan0 interface for connected clients with my MAC addresses, if he finds them he updates Person1,2 items with ON or OFF via REST API.
minute update seems to me as a overkill as dhcp lease is usually 24h in home environment⦠so I donāt see much added value to the timer tho and as well it seems to be bit tight as phone can be discharged,not on signal etc.
but if it is reliable enough for you, thats fine.
I just wanted to understand why there is need for additional timer, when timer itself can be handled on thing level.
Hi,
This has nothing to do with DHCP. router can see the wifi ACTIVE connected clients. as soon as you disconnect the device from the router, in 2 seconds the device disappears from the list of active wifi clients. (I dont know about your router, but this is how routers usually behave when you check for active wifi clients list (nothing to do with DHCP clients).
I am thinking of reducing the script to 30 seconds actually, as router is not doing anything anyway, and its a really small light script.
So, rather then pinging the phone all the time (every second), I opted in for an approach that router tells openhab if the client is here or not here.
When I walk in the apartment, in less then 1 minute music starts playing, AC starts running, and if its after sunset, some lights come on.
I dont want all this to come off when I accidentaly drop wireless connection. I am actually using 10 minute timer as I never lost wifi for more than that. And I will probably replace the crappy phone anyway and reduce the timer as my wifeās samsung had never dropped a connection for a minute.
(we charge phones every night so there is no discharged situations)
I donāt understand what do you mean additional timer when timer can be handled on thing level?
Itās very simple and common, there is other scripts from people online with timers doing the same thing, people dont want Presence group to flop OFF immediately when all phones are disconnected.
Previously I had a timer within āGoing outā rule (which looks at Presence group state), but I found itās better to handle it on the Presence group level then in every separate rule you might have that involves Presence group.
Hi,
I dont understand from your rule what happens with your Presence_Timer Item when both phones go to OFFā¦and how it prevents Presence group to go OFF in that caseā¦
since I have multiple hotspots around the house, checking connection on each of those would be quite tidious proces, not to mention that phones usually use deepsleep eg they are not actively connected when not needed.
I like this very simple Rule but if you need to add more sensors it might get unruly.
To expand this same approach to include multiple sensors for each person (often users must include multiple presence sensors for accurate presence detection, e.g. wifi and BT) see Generic Presence Detection. The big difference is it uses Expire timers like Vincent demonstrated, and it relies on Group aggregation functions rather than doing tests on individual Items in the Rule itself.
well if you had openwrt on all access points it would be a piece of cake, and mobile phones in deep sleep are still on wifi (have you noticed you still receive whatsapp messages)
or if you are not on openwrt you can use arping that forces phones to answer to ping even in deep sleep (this is the method network binding is using).
OK, clearly you are not interested in presence detection via mobile phone devices, so what are you doing about it, motion sensors, other sensors, nothing?
am using arping for mobile presence detection, but indeed i will never ever use this information to trigger anything inhouse because from real world experience this is very unreliable and not always wanted so there is no place for it it my general ruleset.
I do use it for some weekend additional lake lights as there is no point to have it running when nobody is home, but for home itself am not using it at all.
On top of it, me and my family is not phone-centric based so there are situations which makes phones not really indicators of actual presence as well
I just pointed out that those 5mins timer is not doing anything different than whole group on/off trigger anyway no big deal, was just asking
my main in-house / out-house presence is my alarm being armed or not and doors have been opened or not in certain period between arming/disarming zones
no not really, as these apps are using push and they will work on data or wifi as they want, my iphone is disconnecting from wifi when itās not using for some time as well as my wifeās
Phones are not constantly on wifi for battery saving, am not telling it is general behaviour but some of them are doing that quite often
The timer is doing something different. There is a proxy Item, Presence_Timer. This proxy Item is what the Rules use to determine whether someone is present or not.
When Person1 or Person2 change to ON, Presence_Timer is immediately set to ON.
When Person1 and Person2 changed to OFF, the Rule waits 5 minutes before setting Presence_Timer to OFF. Should Person1 or Person2 return within that 5 minutes, Presence_Timer remains ON.
The Group Presence isnāt actually use at all in this example and could be eliminated. But the point is Presence isnāt actually used by the OH Rules to determine if someone is present. Thatās what Presence_Timer is for.
This filters out the situations described where the presence sensors erroneously detect all people are away when in fact they were just momentarily out of range or there was a network issue or something.
I think thereās a snag with the expire version; if āphonesā stay ON for ten minutes, it will expire OFF.
You could manage ways around that by separating command from state and using another rule to filter/retrigger at OFF time - but then you might as well manage all by Timer.
You canāt rely on the Group because itās state will not follow the anti-flapping timer. You either need to use Present_Timer to represent the actual presence in which case rossko57ās right and there is a snag. Or you need to add another proxy Item to represent the anti-flapped presence state.
So, if the phones stay ON for more than five minutes, the Group will remain ON. The Phones will remain ON. But Presence_Timer will be expired to OFF.
Since Presence_Timer represents whether or not everyone is home the house will go into away mode even though everyone is still home.
To work as written, Presence_Timer will need to be updated or commanded to ON every 5 minutes or less to keep the expire binding from expiring it to OFF while any of the sensor Items or the Group remain ON.