9

So that is the general question, but I'll provide the scenario here.

I'm running Mosquitto server to provide mqtt comm between esp relay modules (Sonoff from Itead) and Home Assistant. Most of the time, it works just fine. Each module has its own topic, and there are as many "light" configurations in HASS as modules, so they can be controlled from the web frontend by individual toggle buttons.

I've experienced, though, inconsistent state situations where the light is actually on and the toggle in HASS is shown as off (and the opposite situation as well). By inspecting logs I've found that Mosquitto is not publishing certain messages to HASS (which should be subscribed to all module state topics). More specifically, given 4 modules and its corresponding state topics (state/sonoff_xx/POWER), HASS seems to be subscribed only to modules 2 and 4 topics, but not 1 and 3. The following is the expected behavior for module 4, the same can be verified for the other working module, but publishing to HASS is missing for the other two.

Jun 15 19:22:46 nas mosquitto[9486]: Received PUBLISH from sonoff4 (d0, q0, r1, m0, 'stat/sonoff4/POWER', ... (2 bytes))
Jun 15 19:22:46 nas mosquitto[9486]: Sending PUBLISH to home-assistant (d0, q0, r0, m0, 'stat/sonoff4/POWER', ... (2 bytes))

This is not a question regarding HASS and the relay modules, but it is about how to dig into the status of MQTT Server that is supposed to have certain clients subscribed but, by looking at the logs, it has not.

Dario
  • 339
  • 1
  • 3
  • 6

2 Answers2

8

No, you can not get a list of which clients are subscribed to what out of mosquitto.

HASS is most likely not subscribing rather than mosquitto not publishing to a subscribed client.

You can get mosquitto to log each time a subscription request is made which you could then use to build a list.

log_type subscribe, unsubscribe

This will log all clients which subscribe/unsubscribe from topics.

zs11
  • 103
  • 2
hardillb
  • 12,813
  • 1
  • 21
  • 34
4

You can Enable mosquitto log for all and subscribe to the log you will find messages that you can decode for every client action like connecting, disconnecting, subscribing and publishing even errors.

you will set

log_dest topic
log_type all

in mosquitto.conf then you will subscribe to

$SYS/broker/log/#
Anas Naguib
  • 251
  • 2
  • 3