Binary Sensor not changing - Solved

I’m really struggling with binary sensor templates.

Plugging the value_template into the Template Dev Tools it results correctly. So based on the on/off result I then assumed that is converted into open/closed based on the device_class.

But then when viewed under States in the UI it shows as closed, and never changes. Not sure where I am going wrong.

binary_sensor:
  - platform: template
    sensors:
      door_window_garage:
        friendly_name: 'Garage'
        value_template: '{{ states.binary_sensor.door_window_sensor_158d0001a3df26.state }}'
        entity_id: binary_sensor.door_window_sensor_158d0001a3df26
        device_class: opening

After many, many, many hours of trial and error, I finally figured it out.

For others reading this in the future, the following is working. I just need to better understand the formatting. I previously tried this with Open and Close, but instead needed True and False.

  - platform: template
    sensors:
      door_garage:
        friendly_name: 'Garage'
        device_class: opening
        value_template: >-
          {%- if is_state("binary_sensor.door_window_sensor_158d0001a3df26", "off") -%}
          False
          {%- else -%}
          True
          {%- endif %}
        entity_id: binary_sensor.door_window_sensor_158d0001a3df26
1 Like

Sorry to bump this, but just wanted to say thanks – your solution worked!

Most other examples that I checked just didn’t!