How to get State in condition from all configured persons?

Tags: #<Tag:0x00007fc40763f970>

Is there an easy way to get the state of all configured persons.

In some automations you want to check if the configured persons are “home”

using the following condition:

- condition: state
   entity_id: all

are in the examples, but this would also include all devicetrackers who are not added to a person.

Of course i could add every person in a OR clause, but thats not how it was before the automatic groups where removed

Any suggestions?

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

Thnx, i didn’t read the changelog well enough, i tought that groups was also depricated, but only the old state UI. Marked it as solution.