Automation condition question

Hello! Short question
Could anyone say how can I make this condition?
There is only one device_tracker at home

And no matter who.

You can use groups:

  people_home:
    name: Anyone home
    entities:
      - device_tracker.phone1
      - device_tracker.phone2
      - device_tracker.phone3

Status of the group is home if anyone is home.

Unless lost in translation that may not be what they were after

Sorry for being unclear
I need the condition to work only in situation, when 1 person is at home, not more.

And guys, how would I ask that correct? Do a little English lesson for me, please :slight_smile:

Disregard, misread you request.

assuming they are all device trackers

- condition: template
  value_template: >
    {{ states.device_tracker | selectattr('state','eq','home') | list | length == 1 }}

Or if you want to check against a group of device trackers or on/off sensors.

- condition: template
  value_template: >
    {% set group = 'group.people_home' %}
    {{ states | selectattr('entity_id','in', state_attr(group,'entity_id')) | selectattr('state','in',['on', 'home']) | list | length == 1 }}
2 Likes

Seems to work just fine! I used second one with group because I have 2 device trackers on 1 person.
Thank you!

2 Likes

Could you say what to read to get into that kind of templates?
Should I start here?

Yeah that’s a good start. That’s the API. It can be cryptic though. And it doesn’t really cover much in relation to examples. I learned by reading that and cruising these forums. Learning python doesn’t hurt either because there are a lot of similarities, especially with object types.

1 Like