[homeassistant.components.mqtt.binary_sensor] No matching payload found for entity

Hello. I just added a binary sensor in the way described by this page:

I only modified the name to “CM_1”, the state_topic to “CMS_OUT” and excluded these lines:

    availability_topic: "home-assistant/window/availability"
    payload_available: "online"
    payload_not_available: "offline"

However, when I send:

mosquitto_pub -h 127.0.0.1 -t home-assistant/window/contact -m "OFF"

It has no effect on the sensor and the Log says:

2019-04-04 22:17:00 WARNING (MainThread) [homeassistant.components.mqtt.binary_sensor] No matching payload found for entity: CM_1 with state_topic: CMS_OUT

How can I fix that?
thanks

You said that you changed the state topic to “CMS _OUT” but the command you ran posts to a topic of “home-assistant/window/contact”. Try running this instead:

mosquitto_pub -h 127.0.0.1 -t CMS_OUT -m "OFF"

I used the right command and did not work too.
Meanwhile, I found the issue

The snippet provided by the doc is not good anymore and the line with

value_template: ‘{{ value.x }}’

has to be removed (it overrides payload_on/off fields)

Edited:
Hi, I had similar problem.

Documentation is very weak for this topic.

What I found (reverse engineered), you have to send available message first and then you will be able to change state. I am not 100% sure, it works for me.

Fix for you:

  1. put those lines back to your configuration.yaml (or other config).
  2. remove value_template: ‘{{ value.x }}’
  3. send mqtt message “online” to your availability topic.
  4. update state on your binary sensor.

This code works for me:

binary_sensor:
  - platform: mqtt
    name: "Window Contact Sensor"
    state_topic: "home-assistant/window/contact"
    payload_on: "ON"
    payload_off: "OFF"
    availability_topic: "home-assistant/window/availability"
    payload_available: "online"
    payload_not_available: "offline"
    qos: 0
    device_class: opening

Then:
mosquitto_pub -h 192.168.1.1 -p 1883 -t 'home-assistant/window/availability' -m "online"
Then:
mosquitto_pub -h 192.168.1.1 -p 1883 -t 'home-assistant/window/contact' -m "ON"q