MQTT doorsensor how to show in dashboard

Hi!

I am pretty new to HO and coming from fhem.
I programed a door sensor with mqtt and it is publishing the state using MQTT.
However, I added a mqtt sensor entry for it:

- name: wt_tuer
    unique_id: wt_tuer
    state_topic: wt/door_sensor

Sensor is 0 when closed, 1 when opened - this works fine with HA so far.
Now, I would like to show it an open/closed door in the dashboard, but I am a little bit helpless how to do this.
Could anyone please give me some hints?
Best regards and thanks in advance,
Otto

sensor or binary sensor?

If it is a binary sensor all you need to do is this:

mqtt:
  - binary_sensor:
      - name: wt_tuer
        unique_id: wt_tuer
        state_topic: wt/door_sensor
        device_class: door

Hi!

thanks, this helped a lot :slight_smile:
just had to add the payloads:

binary_sensor:
  - name: wt_tuer
    unique_id: wt_tuer
    state_topic: wt/door_sensor
    device_class: door
    payload_on: "1"
    payload_off: "0"

Is there also a possibility to change the icons according to state?

Here are the built in device classes and their icons: https://www.home-assistant.io/integrations/binary_sensor/#device-class

As you have given your binary sensor a unique ID you should be able to change this from the UI.

If you change the field above that (Icon) you can change the icon but it will not change with the binary sensor state.

You might like to vote for this feature request: Custom device classes

Thanks a lot!
upvoted!

1 Like