Binary template sensor not working

Hi,

I’m trying to get a binary template sensor working but I have some problems.
Can you see any errors below?

  - platform: template
    sensors:
      dishwasher:
        friendly_name: "dishwasher"
        delay_off:
          minutes: 3
        value_template: >-
          {% if states('sensor.dishwasher_power')|float > 2 %}
            on
          {% elif states('sensor.dishwasher_power')|float < 1 %}
            off
          {% endif %}

The sensor state never change to “on” even if sensor.dishwasher_power is over 2. I have tested the value template in “Developer tools” and it works there.

Thanks/Nicklas

The main problem is you’re using on instead of true. A secondary problem is the value_template has no value if sensor.dishwasher_power is between 1 and 2.

I think you would be better off using a Threshold Binary Sensor. E.g.:

  - platform: threshold
    name: dishwasher
    entity_id: sensor.dishwasher_power
    upper: 1.5
    hysteresis: 0.5

This binary_sensor will go on when sensor.dishwasher_power goes above 2, and will go off when sensor.dishwasher_power goes below 1.

1 Like

Thank you! Yes, it works better with true :smile:

Will the binary sensor change from true or false if sensor.dishwasher_power is between 1 and 2? If it retain the previous value in that occasion I guess it will work anyway.
The problem with the threshold sensor is that it has no delay_off parameter.

I’m pretty sure it will just cause an error and the state will not change. To avoid the error, maybe try:

        value_template: >-
          {% if states('sensor.dishwasher_power')|float > 2 %}
            true
          {% elif states('sensor.dishwasher_power')|float < 1 %}
            false
          {% else %}
            {{ is_state('binary_sensor.dishwasher', 'on') }}
          {% endif %}

Thank you very much! :smile:

Will try!

1 Like