Change "on" state to "open"

I’m using ESPHome for several binary sensors. For a door, when the door opens the sensor state changes to “on”. Can I change that so the state shows “open”

Here is the code I’m using

binary_sensor:
  - platform: gpio
    pin: 
      number: GPIO22
      mode: INPUT_PULLUP
    name: "Door Sensor"

Change the device_class to door in homeassistant.

What mf_social said but you can do it right there in the yaml. Add this under the name:

device_class: door

Yep, it is in the docs:

Awesome! Thanks!

It always pays to look at the base component, eg you won’t find the docs for device_class under gpio binary sensor docs, but under the generic binary sensor docs

I added the device class but I’m still getting on/off instead of open/close

binary_sensor:
  - platform: gpio
    pin: 
      number: GPIO23
      mode: INPUT_PULLUP
    name: "Terminal 1"
    device_class: door
  - platform: gpio
    pin: 
      number: GPIO22
      mode: INPUT_PULLUP
    name: "Terminal 3"
    device_class: door
[21:29:45][D][binary_sensor:036]: 'Terminal 3': Sending state OFF
[21:29:47][D][binary_sensor:036]: 'Terminal 3': Sending state ON
[21:29:48][D][binary_sensor:036]: 'Terminal 3': Sending state OFF
[21:29:49][D][binary_sensor:036]: 'Terminal 3': Sending state ON
[21:29:55][D][binary_sensor:036]: 'Terminal 1': Sending state OFF

I assume you recompiled and uploaded?

I believe the device_class will only change the appearance in the frontend… the actual state will still be on/off… (binary_sensor) but added to a card in the frontend will then say “Open/Closed” respectively…

1 Like

Yep, I compiled and uploaded. I have not viewed in HA yet. I’ll see what it does in HA

Confirmed that it works as intended in HA. Thanks!

1 Like