ok im having trouble working out how to code a trigger that fires only when all but one person has left the house. Aka your the last person home. I also want to be able to know who the last person home is. I want to do this so i can fire an IFTTT event that launches a notification on the last persons phone telling them they are the last person home. Any ideas how to do something like this, if it is at all possible. Thanks
I haven’t found a way for Home Assistant to track variables, so I don’t know if it is possible to do entirely in Home Assistant. i’m sure there are much more elegant ways of doing it, but since it has been a couple of days with no response I will post my convoluted mess of an answer.
Method 1A
The way I would do it is once Home Assistant detects a presence change (either home or away) have it pass that information to a shell script running on your host machine. The script would do the heavy lifting of determining how many people are present, and who is the last person. Once the number of occupants equals one the scrip could send that to Home Assistant using something like CURL to change a sensor to the name of the last person home. Home Assistant could then trigger an IFTTT action based on what the sensor value was changed to.
Method 1B
Alternatively you could have a switch for each person so instead of updating a sensor the script would tell Home Assistant to turn on a switch for the last person home and use that switch turning on to trigger your IFTTT action.
Method 2
As I’m typing this I’m also realizing that you might be able to do this with switches alone. Have a switch for each person in the house, using the switches state to represent if the person is home or not. You would need to add an automation that would trigger on state change for each switch, with conditions of all other switches be on/off(depending on how you want to represent the away state).
This isn’t a well thought out suggestion, just something that came to me as I was posting my reply, but it may get you in the right direction…
This can be best achieved by writing a custom component in Python that keeps track of the number of people home. We’re in the process of updating the docs related to automation in Python.
Thanks guys, ill try come up with something when i have time and post my results here