Binary sensor status not updating

Hello,

i have binary sensor (Z-Wave windows sensor Shenzhen Neo Electronics Co Ltd) named binary_sensor.sensor_window_office. Everything works fine, but it is not visible on the phone in the Apple Homekit application. I try add device_class: window via “Customization” but still not working.

So, i add to configuraton.yaml :

binary_sensor:

  • platform: template
    sensors:
    window_office:
    friendly_name: “Window office”
    device_class: window
    value_template: >
    {% if is_state(‘binary_sensor.sensor_window_office’, ‘on’) %}
    On
    {% else %}
    Off
    {% endif %}

When i open window - binary_sensor.sensor_window_office change state to on, when close - to off.

Now, i have visible binary_sensor.window_office on Lovelace and in phone HomeKit application. But this sensor have always status “off”.

When i try this template in Developer Tools i get:

  • platform: template
    sensors:
    window_office:
    friendly_name: “Window office”
    device_class: window
    value_template: >

            On
    

And when i try state in Developer Tools i get state “off”

What’s im doing wrong?

Welcome to the community Piotr!

Please have a look at Nr. 11 of How to help us help you - or How to ask a good question. We need you to format your code, else it’s pretty much unreadable, especially since YAML uses spacing as well.

Current template, still not working.

Into configuration.yaml:

binary_sensor: !include binary_sensors.yaml

Into binary_sensors.yaml:

  - platform: template
    sensors:
     window_office:
        friendly_name: "Window office"
        device_class: window
        entity_id: binary_sensor.sensor_window_office
        value_template: >
          {% if is_state('binary_sensor.sensor_window_office', 'on') %}
          On
          {% else %}
          Off
          {% endif %}

Ah, I see.
Looking at the documentation the value_template needs to be True for it to switch on. Because of that you can have this short solution:

  - platform: template
    sensors:
     window_office:
        friendly_name: "Window office"
        device_class: window
        entity_id: binary_sensor.sensor_window_office
        value_template: {{ is_state('binary_sensor.sensor_window_office', 'on') }}

I don’t understand.
You are taking one binary sensor and creating another one (with the same sense)
Why ?

Just customise the sensor you have as window
Edit: Sorry I see you’ve tried that

1 Like

Maybe it’s an availability issue?
In that case you should disable autostart though.

Yes, I have a delayed start homekt but this should not affect the operation of the created binary_sensor, because it should change its status depending on the status of the original sensor, which it does not want to do.

I think you need quotes around your single-line template:

value_template: "{{ is_state('binary_sensor.sensor_window_office', 'on') }}"

Covered in automation templating docs, probably applies here too.

1 Like

Yes, that’s true, sorry I missed that :laughing: