Esphome binary sensors state

Hi everyone,

My esphome script is:

binary_sensor:

  • platform: gpio
    name: “Door Sensor”
    icon: “mdi:door”
    id: DOOR
    device_class: door
    pin:
    number: D3
    mode: INPUT_PULLUP
    inverted: False
    filters:

    • delayed_off: 100 ms
  • platform: gpio
    name: “Lock Sensor”
    icon: “mdi:lock”
    id: Lock
    device_class: safety
    pin:
    number: D4
    mode: INPUT_PULLUP
    inverted: False
    filters:

    • delayed_off: 100 ms

It gives me states ON and OFF
How can I get states values Locked and Unlocked?

Thx!

I’d use state class lock, not safety. But to get back to your question: the states stay the same, it is just the presentation in Lovelace that changes through translation.

1 Like

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

yeap I know, HA shows correct in lovelace, but just for perfection i’d like to get right statuses =)

i think smth like that but its not correct syntax:

  • platform: gpio
    name: “Lock Sensor”
    icon: “mdi:lock”
    id: Lock
    device_class: safety
    pin:
    number: D4
    mode: INPUT_PULLUP
    inverted: False
    filters:
    • delayed_off: 100 ms
    • lambda: |-
      if (id(‘Lock’).state) {
      return “Unlocked”;
      } else {
      return “Locked”;
      }

No one can tell. You have not formatted your post correctly for the forum as I advised earlier.

Spacing is important in yaml. We cant tell what your spacing is if you don’t format it correctly. So we can’t help you.

1 Like