Trying to extract the state of my lock to a binary sensor

I got this set up:

  - platform: template
    sensors:
      lock_frontdoor:
        friendly_name: "Hoveddør lås"
        device_class: lock
        value_template: "{{ states('lock.poly_control_danalock_v3_btze_locked') }}"

if I put

{{ states('lock.poly_control_danalock_v3_btze_locked') }}

in the template check in developer tools, it shows the state correctly, but not in the binary sensor?
I want it in a binary sensor, as I don’t want it to be able to lock/unlock in that card, only show the state.

Confirm that it looks like this in your config:

sensor:
  - platform: template
    sensors:
      lock_frontdoor:
        friendly_name: "Hoveddør lås"
        device_class: lock
        value_template: "{{ states('lock.poly_control_danalock_v3_btze_locked') }}"

You’ll also need to restart Home Assistant after adding it.

1 Like

Make sure your code is under binary_sensors: NOT sensors:
Your lock state will return locked or unlocked, which is not a valid state for a binary_sensor (on/off)
You therefore need to adjust your template as such (assuming on means unlocked here, amend as necessary)

 - platform: template
    sensors:
      lock_frontdoor:
        friendly_name: "Hoveddør lås"
        device_class: lock
        value_template: "{{ states('lock.poly_control_danalock_v3_btze_locked') == 'unlocked' }}"
1 Like

Ahaaa, that makes sense, thankyou!

1 Like

Ah, my bad.

@lolouk44 and I couldn’t wait to test, despite that it’s past midnight, and it worked perfectly :grin:

1 Like

sweet dreams. Don’t let the bed bugs bite you :laughing:

1 Like