Binary_sensor template does not work

Does anybody see what is wrong with this code?

binary_sensor:
  - platform: template
    sensors:
      rain:
        value_template: "{{ states.binary_sensor.lumi_lumi_sensor_wleak_aq1_03598439_1_1280.state }}"

The sensor is always off.

Um, not sure why you’d want to create a template binary_sensor simply from another binary_sensor.

Leaving that aside, the reason the template binary_sensor is always off is because, to be on, the result of the value_template needs to be the string true. However the state of the referenced binary_sensor is always the strings on or off, not true. This is the correct template:

value_template: "{{ is_state('binary_sensor.lumi_lumi_sensor_wleak_aq1_03598439_1_1280', 'on') }}"
1 Like

Wow, thats funny. For a binary sensor to be “on” you need True. Thanks a lot mate, I would never find that solution by myself.

Sure you would. It’s right in the documentation:

The reason for creating a binary sensor from another binary sensor is that I want to have an abstraction from the physical name. binary_sensor.rain is the logical name, binary_sensor.manufacturer1_id_code_72394343 is the physical name. Automations should use the logical name.

Ok, that makes sense. But can’t you just change the entity_id of the existing binary_sensor? I though that’s possible now, but maybe I’m mistaken.

Yes I think this is possible but I think it is useful if the physical sensor has got the mac id in its name.

1 Like