How to get State in condition from all configured persons?

This is what groups are for…well, usually.

But, the group will want device_trackers to give you ‘home’ or ‘not_home’. I’m pretty sure it wont work with a ‘person’ component. It might…but probably wont.

If it does, you can just check if the group is ‘home’ or ‘not_home’.

If not, you can use filters. Following this helpful guide, you could do:

# Returns the number of 'persons' that are 'home'
{{ states['person'] | selectattr('state', 'eq', 'home') | list | count }}

You can use that in a template sensor if you wanted.

binary_sensor:
  - platform: template
    sensors:
      someone_home:
        # Will be 'on' if any person is considered 'home'. 'off' otherwise. 
        value_template: "{{ states['person'] | selectattr('state', 'eq', 'home') | list | count > 0 }}"

Now just use this sensor in any of your automations.


Actually, just tested the groups with people and it seems to work.

So, just create some groups.

groups:
  family:
    entities:
    - person.family_person_1
    - person.family_person_2

  enemies:
    entities:
    - person.enemy_1
    - person.enemy_2

  pets:
    entities:
    - person.cat
    - person.dog

states(‘group.family’) will be ‘home’ if anyone in the family list is home. Same for all other groups.

2 Likes