Binary sensor template reports incorrect value

I’m trying to create a binary sensor that tells me if my clothes dryer is on/off based on power consumption. I’ve tested the following template code in the Developer Tools, and it correctly reports the value:

{% set power = states('sensor.sonoff_s31_06_power') | float %}

{% if power > 10 %}
  'On'
{% else %}
  'Off'
{% endif %}

However, if I use the same code inside a binary sensor helper, it always reports ‘Off’ whether the dryer is running or not:

Am I templating this incorrectly?

Binary sensors’ state should be on or off in lower case. The front end will show title case strings, but the back end state is lower case.

A better and simpler template would return true or false like this:

{{ states('sensor.sonoff_s31_06_power')|float(0) > 10 }}

That did the trick - thank you!

1 Like