One of the most powerful abilities of Home Assistant is the ability to easily create automation based on the current location of our home users.
For instance, start the vacuum cleaner and 9:00 am, only if you’re not home.
This of course can be done with the built-in automation editor, but the condition for the scenario can be rather long, particularly if there is more than one person in the house.
One of the ways to simplify the Automation is using only one sensor in the condition section, in this case, a sensor that will tell us how many people (or adults) are in the house.
Based on that information, we can easily initiate or postpone automation.
For this to work, you’ll need to have all the persons in the house use one of the presence detection (preferably the home assistant companion app) and define your home location.
Add to your configuration.yaml file this under the sensor section:
1 2 3 4 5 6 7 8 9 10 11 12 |
sensors: adults_home: friendly_name: "Number Of Adults Home" value_template: > {% set ps = namespace(states=[]) %} {% if is_state('person.roei', 'home') %} {% set ps.states = ps.states + [ 1 | int] %} {% endif %} {% if is_state('person.wife', 'home') %} {% set ps.states = ps.states + [ 1 | int] %} {% endif %} {{ ps.states | sum | round(2) }} |
A sensor that counts home many adults are in the house.
Add the if part for every person in the house and that’s it 🙂