Help with aqara door sensor and zigbeetomqtt

Hi
I need help with Xiaomi Aqara door sensor integration in Home Assistant using ZigbeeToMQTT.
I’m using hassio and have installed zigbee2mqtt addon.
Addon connects with mqtt broker (I’m using Mosquitto) and from log it seems to be connected

  zigbee2mqtt:info 7/5/2019, 11:50:01 PM Connected to MQTT server

When sensor is activated, message is seen in log

  zigbee2mqtt:info 7/5/2019, 11:50:18 PM MQTT publish: topic 'zigbee2mqtt/door_sensor', payload '{"contact":false,"linkquality":157,"battery":100,"voltage":3055}'
  zigbee2mqtt:info 7/5/2019, 11:50:23 PM MQTT publish: topic 'zigbee2mqtt/door_sensor', payload '{"contact":true,"linkquality":157,"battery":100,"voltage":3055}'

Added binary sensor to configuration.yaml

binary_sensor:
  - platform: mqtt
    name: "vrata"
    state_topic: "zigbee2mqtt/door_sensor"
    value_template: "{% if value_json.contact %}Closed{% else %}Open{% endif %}"

But nothing happens with sensor in home assistant
It’s off all the time, activating sensor does nothing there

One more thing that seems odd to me is, in node red i try to listen to same topic
But don’t see any messages on it (like message was never published although zigbetomqtt log claims it is)
s7

Have no idea what am I doing wrong

EDIT:
Don’t know does this matter, but for this to work, I had to add to Mosquitto configuration

"anonymous": true,

ZigbeeToMQTT wasn’t able to connect to mosquitto before that

Why not use discovery?

Tried that, but sensor is not added, have no idea why
To me it seems that mqtt message is just not published at all, but have no idea why

Made some changes
Switched back to auto discovery (removed binary sensor), changed anonymous to false in Mosquitto, added login in Mosquitto configuration, added login data to zigbetomqtt addon
Now addon can connect to mqtt broker again, but result is still the same
Addon reporting successful connection to mqtt broker and publishing when sensor state changes, but still unable to see message in node red, still no device added by auto discovery

What does mosquitto_sub tell you?

Sorry, don’t understand what are you trying to ask.
In mosquitto log I can see user connected with login data set in zigbeetomqtt addon

1562368711: New client connected from 172.30.32.1 as mqttjs_907f3d26 (p2, c1, k60, u'zigbeetomqtt').

If that is what you mean

No I mean using mosquitto_sub (or some other program that can subscribe to mqtt) to see what is actually being sent to the broker.

I’m using node red (it can subscribe)
And don’t see any message published on that topic

To really see what is going on in mqtt you need to subscribe to the discovery topics (homeassistant/#)

Minimally, two things need to connect to the mosquitto MQTT broker:

  1. zigbee2mqtt
  2. Home Assistant

For debugging MQTT issues, I recommend using an MQTT client to serve as an independent observer. It can be what Nick suggested, mosquitto_sub (and its publishing counterpart called mosquitto_pub), or MQTT Explorer or MQTT.fx, or even Node Red.

Once you have the MQTT client connected to the broker, you can confirm if other clients (zigbee2MQTT, Home Assistant, etc) are actually publishing anything to zigbee2mqtt/door_sensor

In addition, your binary_sensor’s value_template requires correction. Try this:

binary_sensor:
  - platform: mqtt
    name: "vrata"
    state_topic: "zigbee2mqtt/door_sensor"
    value_template: "{{ 'ON' if value_json.contact else 'OFF' }}"
    device_class: door

It seems problem was in mosquittto acl
According to this:


User permission to publish on certain topic should be configured like this
user zigbeetomqtt
topic #

But it doesn’t work that way, readwrite should be added like this

user zigbeetomqtt
topic readwrite #

Or in my case

user zigbeetomqtt
topic readwrite zigbee2mqtt/#

Everything is now working

OK so a basic “I failed to read the instructions” failure. We get a lot of that here. strike that.

Please read again, it seems you missed whole part about reading instructions and how there was stated something that didn’t work
As I said, I have read instructions and configure based on it, it didn’t work
Then after few hours with my friend google, found different instructions
And it worked with them

Sorry I misread your post, my mistake.

Please edit the incorrect documentation - there is an edit link on each documentation page.

Everything? Including binary_sensor.vrata with the original template?

    value_template: "{% if value_json.contact %}Closed{% else %}Open{% endif %}"

For an MQTT Binary Sensor, the default values for payload_on and payload_off are ON and OFF, respectively (see documentation). Your template uses Open and Closed which do not correspond to the default values.

As I said before, binary sensor was removed, HA created it