I'm using an iPhone connecting to my Unifi router as a way to track presence for someone that doesn't want to run apps which could help.
What is the best way? The router will tell Hubitat when they connect, but iPhone's are notorious for dropping off when not in use. I use this to trigger different morning and nighttime rules.
I'm sure I could start a timer anytime they connected and let it run and run and run...and even it would really need to stay connected for that to work it seems since I also need to know when they are gone.
Is there an easy way to define a rule that says for example...if X has happened anytime in the last 8 hours do Y?
It sounds like you want the routines to be conditional on the phone having connected within the last 8 hours. You should be able to do this with rule machine.
Set a virtual presence sensor to 'present' when the router reports they connected and use 'virtual presence sensor is present' as a required condition on whatever rules are involved in the morning and nighttime routines.
In rule machine:
Trigger: router event happens
Actions:
Set virtual presence to present
Wait for event: elapsed time 8 hours
Set virtual presence to not present
Since you didn't explain how the router tells the hub of the phone connection, you'd have to confirm that this retriggers on each reconnect of the phone or periodically when it remains connected. This should keep them present until there's an 8 hour gap.
the Unifi app works great for passing that info to Hubitat. (as an ex router jock I will say that even the Unifi home stuff has a very "enterprise" type network interface)...anyway...
I don't know why I always think that having a rule waiting for something impacts the load...I've been told otherwise. It's probably because I do get some severe CPU load type warnings occasionally...and have eliminated that by running another rules actions vs a switch just changing state that triggers that other rule to kick off and run at the same time. Clearly, a rule waiting for an event is not "really" another "running" rule.
I'm really glad you offered that approach to remind me that's OK! THANKS!
I do a similar thing for my daughter when she is home. When her iPhone connects to our WIFI the rule is triggered and it sets a virtual switch that says she is home. This switch is used for various rules for having a guest. Like not turning off the lights in the guest bedroom if we go to bed before her or setting the house to away mode if she is here and we leave,
When her iPhone disconnects it then waits for it to stay disconnected for 4 hours. If it doesn't reconnect within that 4 hours then the rule turns off the switch, unless its between 10PM and 10AM then it waits until 10AM. Won't show her as away when she is in Bed. If at 10AM it is still disconnected then it turns off the switch.
If the iPhone reconnects during any of the waits the whole process starts up again.
Kind of the same general approach for me… I’d love it to be a little more real time, but since it’s only running routines that run in the morning and in the evening… At least at this point… Just confirming it has been there anytime in a window works.