Binary_sensor template

Hello,
I have a window contact as binary_sensor. When the window is closed, it returns the status ON and it is Open in HA.
How can I reverse the state?
Thank you

Which binary sensor integration did you use to define the sensor?

LCN binary sensor

Unfortunately there is no option to invert the logic included in the configuration of that sensor.

You can create a template binary sensor that inverts the logic:

binary_sensor:
  - platform: template
    sensors:
      window:
        friendly_name: "Window"
        value_template: "{{ is_state('binary_sensor.your_sensor_here', 'off') }}"
        device_class: window
1 Like

this dont help

i have all my config of LCN in lcn.yaml
where did I have to paste it? because there were errors in lcn.yaml

i added device_class: window in customize.yaml, do I have to insert it there too?

It goes under this section of your configuration.yaml file, not the LCN configuration.

Yes you need to add the entire configuration I wrote.

ok, i put it there, but it doesn’t change anything

It creates a new sensor with inverted logic. Assuming you have restarted home assistant or reloaded input helper/numbers.

ooo sorry,
now I understand, thank you
also do i have to do it for each window?

Unfortunately yes.

You could raise a feature request asking for an inverted logic option for this integration.

https://community.home-assistant.io/c/feature-requests/13

There’s a hardware hack that will work too.

If you mount another magnet near the reed switch it will turn it on. When the magnet attached to the window comes close the two magnetic fields cancel and the reed switch turns off. I’ve used this trick to turn normally open reed switches into normally closed switches before.

Finally, I’m pretty sure this won’t work but you could try it:

Put this your customize.yaml file:

binary_sensor.your_lcn_sensor_here:
  invert_logic: true

thank you but won’t work

Ok then you’ll have to either use the extra magnet or template sensor options.