Determine presence using Logical OR instead of AND

Has anyone managed to configure this?

I want to add a phone (companion app), and an ibeacon on my keys, to my person entity, so both can track if I’m home or not.

As soon as my ibeacon or phone+ibeacon leave home, HA should mark me as away. Currently this is impossible because the devices use AND instead of OR. If my phone leaves home, and the beacon is still there, I don’t want my status to change.

Sometimes I just leave home without my phone, but since my keys are with me, I am 100% away. Other times, if my phone dies at home, and the keys are still at home, that means I am at home.

When coming back home, if either the phone or the beacon are detected, I should be set as being at Home.

You could make a template sensor for this

1 Like

And so I did:

alias: "Presence: Update Z Tracker"
description: ""
triggers:
  - entity_id:
      - device_tracker.x
      - device_tracker.y
    trigger: state
actions:
  - data:
      topic: homeassistant/z_presence
      payload: >-
        {% if is_state('device_tracker.x', 'home') or
        is_state('device_tracker.y', 'home') %}
          home
        {% elif is_state('device_tracker.x', 'not_home') and
        is_state('device_tracker.y', 'home') %}
          home
        {% else %}
          not_home
        {% endif %}
      retain: true
    action: mqtt.publish
  • Phone and ibeacon are away → not_home
  • Phone or ibeacon are not away → home

If you’re interested, the template can be reduced to this:

alias: "Presence: Update Z Tracker"
description: ""
triggers:
  - entity_id:
      - device_tracker.x
      - device_tracker.y
    trigger: state
actions:
  - data:
      topic: homeassistant/z_presence
      payload: >-
        {{ iif(is_state('device_tracker.x', 'not_home') and
          is_state('device_tracker.y', 'not_home'), 'not_home', 'home') }}
      retain: true
    action: mqtt.publish
1 Like