Templated binary sensor defined in configuration.yaml not working, yet the developer tool template shows it's fine

Hi, the following templated binary sensor:

  - default_entity_id: binary_sensor.low_temp
    name: low_outside_temp
    state: >
      '{% if states("sensor.acurite_outside_temperature") | float(0.0) < -5.0 -%}
         {{true}}
       {% else -%}
         {{false}}
       {% endif %}'

isn’t working. Outside temperature is -16C so its value should be true, which is confirmed while running the template in the Developer Tools Template:

But the state of the sensor is false (off) as shown here:

Not sure what I’m doing wrong. Home Assistant was restarted and no errors are flagged when checking the configuration. Thanks.

Remove the quotes surrounding the template.
Only on single line templates on the same line as state: should you add quotes.
You used > and new line, that should not have quotes

Thanks! That was it. TIL. It also allowed me to figure out that hitting “All YAML configuration” is enough to reload templated entities in configuration.yaml. A full restart isn’t necessary.

As Hellis said, you were using quotes where they weren’t needed… but you are also using if/then where it isn’t needed. Just use the comparison directly in an expression:

  - default_entity_id: binary_sensor.low_temp
    name: low_outside_temp
    state: '{{ states("sensor.acurite_outside_temperature") | float(0) < -5.0  }}'

LO, yeah, that’s much simpler.

A restart is necessary when adding a new file or a new integration. If you’re only reloading template entities, you don’t even need to use “All YAML configuration”. You can just scroll down to the “Template Entities” button in the YAML tool and use that.

Thanks, I’ll give it a try next time.