MQTT not receiving subscribed messages

Hi, i have an odd issue which seems to only have appeared after upgrading to 83.x

I use zigbee2mqtt to connect to my zigbee plugs and sensors. I have a weird case where if i restart the Z2M service, HASS stops receiving messages on my occupancy sensor topics.

If i:

  1. start Z2M, then HASS - it works as expected
  2. restart Z2M, everything except occupancy sensors work
  3. If i then restart HASS, it works as expected.

I can see in the logs that when it is not working that i am subscribing to the correct topic:
2018-12-09 14:47:44 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to zigbee2mqtt/Motion_Toilet

But i do not receive any messages. I have confirmed that they are being sent with mosquito_sub, as well as sending fake messages using mosquito_pub.

This is driving me insane, any help would be appreciated!

Cheers,

A first guess would be that the sensor is receiving an offline message, but not an online message, but its purely a guess.

You need to paste your configuration and the MQTT messages being sent so someone can really help.

Here it is:

home assistant Configuration.yaml

mqtt:
  broker: localhost
  port: 1883
  client_id: home-assistant-1
  keepalive: 60
  protocol: 3.1.1
  discovery: true
  birth_message:
    topic: 'hass/status'
    payload: 'online'
  will_message:
    topic: 'hass/status'
    payload: 'offline'

logger:
  default: warning
  logs:
    homeassistant.components.mqtt: debug

zigbee2mqtt configuration

  '0x00158d000120cdc3':
    friendly_name: Motion_Toilet
    retain: false
    occupancy_timeout: 90

When all running

home-assistant.log:

2018-12-09 15:08:06 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to homeassistant/#
2018-12-09 15:08:06 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on homeassistant/binary_sensor/0x00158d000120cdc3/occupancy/config: b'{"payload_on":true,"payload_off":false,"value_template":"{{ value_json.occupancy }}","device_class":"motion","json_attributes":["linkquality","battery","voltage"],"state_topic":"zigbee2mqtt/Motion_Toilet","availability_topic":"zigbee2mqtt/bridge/state","name":"Motion_Toilet"}'
2018-12-09 15:08:06 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: binary_sensor 0x00158d000120cdc3 occupancy
2018-12-09 15:08:13 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to zigbee2mqtt/Motion_Toilet

2018-12-09 15:08:28 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zigbee2mqtt/Motion_Toilet: b'{"occupancy":false,"linkquality":86,"battery":99,"voltage":3025}'
2018-12-09 15:09:22 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zigbee2mqtt/Motion_Toilet: b'{"occupancy":true,"linkquality":89,"battery":99,"voltage":3025}'
2018-12-09 15:10:52 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zigbee2mqtt/Motion_Toilet: b'{"occupancy":false,"linkquality":89,"battery":99,"voltage":3025}'
2018-12-09 15:11:43 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zigbee2mqtt/Motion_Toilet: b'{"occupancy":true,"linkquality":86,"battery":99,"voltage":3025}'

After Restarting Z2M, Not working:

home-assistant.log

2018-12-09 16:20:34 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on homeassistant/binary_sensor/0x00158d000120cdc3/occupancy/config: b'{"payload_on":true,"payload_off":false,"value_template":"{{ value_json.occupancy }}","device_class":"motion","json_attributes":["linkquality","battery","voltage"],"state_topic":"zigbee2mqtt/Motion_Toilet","availability_topic":"zigbee2mqtt/bridge/state","name":"Motion_Toilet"}'
2018-12-09 16:20:34 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zigbee2mqtt/Motion_Toilet: b'{"occupancy":false,"linkquality":86,"battery":99,"voltage":3025}'
2018-12-09 16:20:35 INFO (MainThread) [homeassistant.components.mqtt] Got update for entity with hash: ('binary_sensor', '0x00158d000120cdc3 occupancy') '{'payload_on': True, 'payload_off': False, 'value_template': '{{ value_json.occupancy }}', 'device_class': 'motion', 'json_attributes': ['linkquality', 'battery', 'voltage'], 'state_topic': 'zigbee2mqtt/Motion_Toilet', 'availability_topic': 'zigbee2mqtt/bridge/state', 'name': 'Motion_Toilet', 'platform': 'mqtt', 'discovery_hash': ('binary_sensor', '0x00158d000120cdc3 occupancy')}'
2018-12-09 16:20:35 INFO (MainThread) [homeassistant.components.mqtt] Updating component: binary_sensor.motion_toilet
2018-12-09 16:20:35 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to zigbee2mqtt/Motion_Toilet

from Zigbee2MQTT logs:
zigbee2mqtt:info 2018-12-9 08:22:28 MQTT publish, topic: 'zigbee2mqtt/Motion_Toilet', payload: '{"occupancy":true,"linkquality":84,"battery":99,"voltage":3025}'

from Mosquito_sub:
zigbee2mqtt/Motion_Toilet {"occupancy":true,"linkquality":84,"battery":99,"voltage":3025}

So as you can see, everything up to actually receiving the messages seems to work. Z2M is publishing the messages appropriately.

Any help would be super!

cheers,

What mrssages do ypu see on this topic?

That topic is for all of Z2M, and other switches are working just fine.

mosquitto_sub -v -t zigbee2mqtt/bridge/state
zigbee2mqtt/bridge/state online

From the logs it looks like it might have to do with discovery.

in the first logs it says it found a binary_sensor that has the same ID as your motion sensor then automatically subscribes to the topic.

I’m not sure how it’s supposed to work (since I don’t use dioscovery) but i looks like if you restart HA after Z2M then it doesn’t do the discovery and therefore doesn’t subscribe to the topic.

try to explicitly define the MQTT topics in your HA config to see if that works.

Maybe it’s a bug that needs to be addressed but I don’t know if it would be on the HA or the Z2M side.

2 Likes

I have raised a HA bug report.

I’ll update here if they come up with anything.

cheers,

Yep - all fixed in 84.1.

thanks.