Custom sensor to detect when someone is home

Right now i got 2 automations if person 1 or person 2 is comming home.
both run the same stuff when status changed from not_home to home.

sometimes the automations fails when both people come home at the same time.

so i wanted to make a custom sensor that contains both person (if this is even the best way to do so)

just can´t figure how to get it working…
what i got right now:

a template sensor:

  - sensor:
      - name: "Home"
        state: >
          {% if is_state('device_tracker.iphone', 'home') %}
            home
          {% elif is_state('device_tracker.iphone2', 'home') %}
            home
          {% else %} 
            not_home
          {% endif %}

EDIT: the code works.

jsut want to leave the topic if someone has a better idea

If those are the only two person entities, you can just use the state of zone.home, which is the number of person entities in it.

1 Like

A group will also have the same logic. Anyone or both home and the group state is home. Both away and the group state will be not_home.

1 Like

probably the most easy way to do it. thanks!