Home assistant binary_sensor from MQTT

Hello everybody
I have a mqtt broker for information from tasmota and from an other HA with Deconz Zigbee
For Tasmota ok no problem
For sensor from the other HA --> ok no problem in sensor.yaml i have for exemple

  - platform: mqtt
    name: rpi4_couloir_temperature
    state_topic: "rpi4/sensor/couloir_temp/state"
    unit_of_measurement: "°C"

for binary sensor I can’t
I try this code in binary.yaml i have for exemple

  - platform: mqtt
    name: rpi4_couloir_motion
    state_topic: "rpi4/binary_sensor/couloir_motion/state"
    payload_on: "ON"
    payload_off: "OFF"
    qos: 0
    device_class: motion

  - platform: mqtt
    name: rpi4_sdj_open
    state_topic: "rpi4/binary_sensor/sdj_open/state"
    device_class: opening
    payload_on: "ON"
    payload_off: "OFF"
    qos: 0

But il have no modification of the binary sensor (but with mqtt.fx i see the state change from off to on and same in the other ha
Can you explain what is my error in my code

Here the state in the dev tools

binary_sensor.rpi4_couloir_motion off friendly_name: rpi4_couloir_motion device_class: motion

binary_sensor.rpi4_sdj_open| off friendly_name: rpi4_sdj_open device_class: opening

Thanks

Thomas

If you go to developer tools -> mqtt, enter # under ‘topic to subscribe to’, and then click start listening, and then open your door or trigger your motion sensor, what do you see ?

image

Message 696 reçu sur rpi4/binary_sensor/sdj_open/device_class à 19:24 :
"opening"
QoS: 0 - Retain: false
Message 695 reçu sur rpi4/binary_sensor/sdj_open/friendly_name à 19:24 :
"SDJ Open"
QoS: 0 - Retain: false
Message 694 reçu sur rpi4/binary_sensor/sdj_open/temperature à 19:24 :
23
QoS: 0 - Retain: false
Message 693 reçu sur rpi4/binary_sensor/sdj_open/on à 19:24 :
true
QoS: 0 - Retain: false
Message 692 reçu sur rpi4/binary_sensor/sdj_open/last_changed à 19:24 :
2020-05-05T17:24:38.106831+00:00
QoS: 0 - Retain: false
Message 691 reçu sur rpi4/binary_sensor/sdj_open/last_updated à 19:24 :
2020-05-05T17:24:38.106831+00:00
QoS: 0 - Retain: false
Message 690 reçu sur rpi4/binary_sensor/sdj_open/state à 19:24 :
on
QoS: 0 - Retain: false

Thanks

It is simple :

You receive

Message 690 reçu sur rpi4/binary_sensor/sdj_open/state à 19:24 :
on

but you define :

  - platform: mqtt
    name: rpi4_sdj_open
    state_topic: "rpi4/binary_sensor/sdj_open/state"
    device_class: opening
    payload_on: "ON"
    payload_off: "OFF"
    qos: 0

“ON” and “on” are not the same !

Try this :

  - platform: mqtt
    name: rpi4_sdj_open
    state_topic: "rpi4/binary_sensor/sdj_open/state"
    device_class: opening
    payload_on: "on"
    payload_off: "off"
    qos: 0

It’s work
Thank you

Please mark my post with the Solution tag. This will automatically place a check-mark next to the topic’s title, signaling to others that this topic has an accepted solution. It will also place a link below your first post leading to the Solution. All of this helps others who may be searching for answers to a similar question.

1 Like