Here’s how I do it. This works for two people but if you have more, just keep adding entities as triggers/conditions. There is probably a more elegant way to handle multiple people, but this works and I’ve never had a problem. The key for the “last person” is the triggers have to be conditioned with every person/device tracker you want to monitor to be NOT home.
You need to figure out a bulletproof way of determining when each individual is away from the home. There are some ways to do it regarding using the person’s cell phone but it is more reliable with android than iphone and that is not bulletproof (can’t get iphone location when it is asleep, person might leave the phone at home). Figure out a way of determiing for sure for each person, when they are not home. Once you have that as a person entioty in home assistant (you add people manually to start with, then that is altered by what I was specifying before). Then , you can make a group helper in homs assistant that you would use in your automation (if true etc). A group helper returns true if all items in the group are of the same value (home or away, on or off, etc.). It’s not the perfect answer for you but that is reality as far as I see it, hope that helps you get started. I’ve been looking for some kind of foolproof GPS gizmo to put on my and my wifes keychain to resolve the issue myself but have yet to even find anything (as we NEVER leave the home without our keys)!
I’ve been using these two automations and two iPhones for nearly 5 years. Never had a problem with the GPS tracking, except because our house/neighborhood was so new that GPS reporting was a little off until more WiFi access points were around us to provide better triangulation. These are probably two of my more robust automations. We take our keys with us because they’re on the same ring as the car keys, but I can’t tell you the last time I actually used a key to enter my house, except when we were building the house and just moved and I hadn’t yet setup HA again. I have automations based on the alarm status and when it is armed, the garage door locks up, when it is disarmed, the garage door unlocks and we walk right in.
Thanks, we also uses iPhones an the HA Companion App. After using squirtbrnrs script i see you only have to use comma seperation in the visuell editor.
The zone.home state is a value indicating the number of people in that zone. If you want to trigger an automation to run when the last person leaves, try:
trigger:
- platform: state
entity_id:
- zone.home
to: "0"
If you want to trigger something when the first person comes home, try:
trigger:
- platform: state
entity_id:
- zone.home
from: "0"
One of the advantages to this is that you don’t have to remember to add entities if you add people to the zone.