Binary Sensor Template stopped working

I have a binary_sensor template that’s been working for a few years, but recently stopped working. Can someone look at this template and tell me if it still should work?

{% set pauls_state = (is_state('device_tracker.paul', 'home')
            or is_state('binary_sensor.pauls_iphone_presence', 'on')) %}
          {% if pauls_state %}
            {{ pauls_state }}
          {% else %}
            {{ states.binary_sensor.pauls_home_tracker.state }}
          {% endif %}

Also I should note none of the entity names have changed as far as I can tell. If you look in the history it shows the two entities changing states but the binary_sensor template just stays on

Can we see the full entry, not just the template please?

Here you go

binary_sensor:
  - platform: template
    sensors:
      pauls_home_tracker:
        value_template: >-
          {% set pauls_state = (is_state('device_tracker.paul', 'home')
            or is_state('binary_sensor.pauls_iphone_presence', 'on')) %}
          {% if pauls_state %}
            {{ pauls_state }}
          {% else %}
            {{ states.binary_sensor.pauls_home_tracker.state }}
          {% endif %}     

Yeah, your template references the entity it is inside of, causing a loop.

Seems like the loop is unnecessary though, surely this will do the same thing…

binary_sensor:
  - platform: template
    sensors:
      pauls_home_tracker:
        value_template: "{{ is_state('device_tracker.paul', 'home') or is_state('binary_sensor.pauls_iphone_presence', 'on') }}"
1 Like

Yeah that reference to itself was supposed to show its previous state in case of a restart. Maybe that doesn’t work anymore? I will try it without the reference and see if it works. Thanks.

1 Like