Binary sensor template example on site is wrong?

Hi,
just triyng to set a binary sensor for the zwave smart socket attached to the dryer machine. Found this example on site:


“washng machine running”
binary_sensor:
  - platform: template
    name: Washing Machine
    value_template: '{{ sensor.washing_machine_power > 0 }}'
    off_delay:
      minutes: 5

so my config should be

  - platform: template
    sensors:
      asciugatrice_accesa:
        friendly_name: Asciugatrice Accesa
        entity_id: sensor.neo_coolcam_power_plug_12a_current
        value_template: '{{ sensor.neo_coolcam_power_plug_12a_current > 0 }}'
        off_delay:
          minutes: 5

but the result is

 Invalid config for [binary_sensor.template]: [off_delay] is an invalid option for [binary_sensor.template]. Check: binary_sensor.template->sensors->asciugatrice_accesa->off_delay. (See ?, line ?).

without the off_delay the answer is

 Could not render template Asciugatrice Accesa: UndefinedError: 'sensor' is undefined

Use '{{ states.sensor.neo_coolcam_power_plug_12a_current.state > 0 }}'. I submitted a PR to fix the docs.

1 Like

thanks it works with

 | float

conversion. Can you explain why the object value to check is states.sensor.blablabla.state and not just sensor.blabla.state ?

and for the entity_id is correct to use

 sensor.neo_coolcam_power_plug_12a_current

(i’ve commented the row entity_id)

many thanks

sensor.neo_coolcam_power_plug_12a_current refers to the entire sensor object that has all the information about the sensor, including states. Since you are comparing the state value, you need to use states.sensor.neo_coolcam_power_plug_12a_current.state to refer to the state of the sensor.

1 Like

I’m facing a similar problem with the template sensor and can’t get it to work:

- platform: template
  sensors:
    machine_running:
      friendly_name: "Machine running"
      entity_id: sensor.machine_power
      value_template: "{{ states.sensor.machine_power.state > 10 }}"
      off_delay:
        minutes: 5

Checking the config results in:
[off_delay] is an invalid option for [binary_sensor.template]

Any ideas how to fix this issue? How is my example different from the previous posting by @blackgear?

I had the same issue and was scratching my head on why it wasnt working. I had a look at the code in Github and noticed the following
https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/binary_sensor/template.py#L28-L29

So the issue as far as i can tell is the documentation has off_delay and the code has delay_off. I have tried changing my config and so far it seems to be working.

1 Like