MQTT auto discovery

@xAPPO My smoke alert is an “alert only” message. I’ve simply attached an ESP8266 to a regular smoke detector. If smoke is detected the ESP sends an alert message. If the smoke alert is reset the power to the ESP is simply cut, so there will be no “alert ended” message. This is why I configured this as a channel trigger.

@denominator I had the problem with the multiple events several times again. (Every time I changed something in the Home channels) I guess when the binding is re-initializing it simply subscribes every mqtt topic again without unsubscribing the old one’s before. Could this maybe be something that could be fixed in the binding?

Some rules are run when openHAB starys or if you change something in a file it may trigger a rule. Check to make sure the 8266 is only sendin one message it may be a qos setting. I do would do this wit another mqtt client that holds a history of messages like mqttexplorer.

hmm, but that is what it should do. The broker can see same listener subscribing to same topic. That part would be all the same if you rebooted openHAB.
Maybe what is missing is a closedown handshake, or maybe the broker should handle (i.e. not create) duplicate subscriptions.

@denominator I’ve already checked that with MQTT.fx, the device only sends one message. Also after a restart of OpenHab the rule is only triggered once.

@rossko57 I just created a small Python script to test what happens if a client subscribes multiple times to a topic and indeed I receive one message for every subscription. (in this case I received the message twice) Here is the script if you would like to test this yourself:

import paho.mqtt.client as mqtt

client = mqtt.Client(client_id="Test")

def on_message(client, userdata, msg):
    topicSplit = msg.topic
    msgPayload = msg.payload.decode("utf-8")


client.on_message = on_message
client.connect("", 1883, 60)



If I find the time I will take a look at the source code of the binding to see if I can find out why the topic is subscribed multiple times.

Have you setup the mqtt event bus?

No I just added a Thing for the broker and a Homie Thing for each of my devices.

@denominator @rossko57 I did some quick test and I was able to reproduce the problem. I’ve enabled the MQTT trace log and simply changed the name of one of the channels in PaperUI. In the log I found that only the topics of the first two Homie nodes where unsubscribed, but after that all three nodes where subscribed again. I guess this explains the doubled rule triggers I get. Here is the log after I’ve changed the channel:

13-Oct-2020 14:23:27.551 [DEBUG] [ding.mqtt.homie.internal.handler.HomieThingHandler] - About to stop Homie device RollerShutterController01
13-Oct-2020 14:23:27.571 [DEBUG] [ding.mqtt.homie.internal.handler.HomieThingHandler] - About to initialize Homie device RollerShutterController01
13-Oct-2020 14:23:27.580 [DEBUG] [org.openhab.binding.mqtt.generic.ChannelState     ] - Unsubscribed channel mqtt:homie300:4ce1d806:rollershuttercontroller01:rollershutter_5F1#calibration_5Fstate form topic: homie/rollershuttercontroller01/rollershutter_1/calibration_state
13-Oct-2020 14:23:27.582 [DEBUG] [org.openhab.binding.mqtt.generic.ChannelState     ] - Unsubscribed channel mqtt:homie300:4ce1d806:rollershuttercontroller01:rollershutter_5F1#moving form topic: homie/rollershuttercontroller01/rollershutter_1/moving
13-Oct-2020 14:23:27.583 [DEBUG] [org.openhab.binding.mqtt.generic.ChannelState     ] - Unsubscribed channel mqtt:homie300:4ce1d806:rollershuttercontroller01:rollershutter_5F1#position_5Fpercent form topic: homie/rollershuttercontroller01/rollershutter_1/position_percent
13-Oct-2020 14:23:27.584 [DEBUG] [org.openhab.binding.mqtt.generic.ChannelState     ] - Unsubscribed channel mqtt:homie300:4ce1d806:rollershuttercontroller01:rollershutter_5F2#calibration_5Fstate form topic: homie/rollershuttercontroller01/rollershutter_2/calibration_state
13-Oct-2020 14:23:27.584 [DEBUG] [org.openhab.binding.mqtt.generic.ChannelState     ] - Unsubscribed channel mqtt:homie300:4ce1d806:rollershuttercontroller01:rollershutter_5F2#moving form topic: homie/rollershuttercontroller01/rollershutter_2/moving
13-Oct-2020 14:23:27.585 [DEBUG] [org.openhab.binding.mqtt.generic.ChannelState     ] - Unsubscribed channel mqtt:homie300:4ce1d806:rollershuttercontroller01:rollershutter_5F2#position_5Fpercent form topic: homie/rollershuttercontroller01/rollershutter_2/position_percent
13-Oct-2020 14:23:27.586 [DEBUG] [ding.mqtt.homie.internal.handler.HomieThingHandler] - About to start Homie device RollerShutterController01
13-Oct-2020 14:23:27.597 [DEBUG] [org.openhab.binding.mqtt.generic.ChannelState     ] - Subscribed channel mqtt:homie300:4ce1d806:rollershuttercontroller01:rollershutter_5F1#calibration_5Fstate to topic: homie/rollershuttercontroller01/rollershutter_1/calibration_state
13-Oct-2020 14:23:27.598 [DEBUG] [org.openhab.binding.mqtt.generic.ChannelState     ] - Subscribed channel mqtt:homie300:4ce1d806:rollershuttercontroller01:rollershutter_5F1#moving to topic: homie/rollershuttercontroller01/rollershutter_1/moving
13-Oct-2020 14:23:27.599 [DEBUG] [org.openhab.binding.mqtt.generic.ChannelState     ] - Subscribed channel mqtt:homie300:4ce1d806:rollershuttercontroller01:rollershutter_5F1#position_5Fpercent to topic: homie/rollershuttercontroller01/rollershutter_1/position_percent
13-Oct-2020 14:23:27.600 [DEBUG] [org.openhab.binding.mqtt.generic.ChannelState     ] - Subscribed channel mqtt:homie300:4ce1d806:rollershuttercontroller01:rollershutter_5F2#calibration_5Fstate to topic: homie/rollershuttercontroller01/rollershutter_2/calibration_state
13-Oct-2020 14:23:27.600 [DEBUG] [org.openhab.binding.mqtt.generic.ChannelState     ] - Subscribed channel mqtt:homie300:4ce1d806:rollershuttercontroller01:rollershutter_5F2#moving to topic: homie/rollershuttercontroller01/rollershutter_2/moving
13-Oct-2020 14:23:27.601 [DEBUG] [org.openhab.binding.mqtt.generic.ChannelState     ] - Subscribed channel mqtt:homie300:4ce1d806:rollershuttercontroller01:rollershutter_5F2#position_5Fpercent to topic: homie/rollershuttercontroller01/rollershutter_2/position_percent
13-Oct-2020 14:23:27.602 [DEBUG] [org.openhab.binding.mqtt.generic.ChannelState     ] - Subscribed channel mqtt:homie300:4ce1d806:rollershuttercontroller01:system#calibration_5Fselection to topic: homie/rollershuttercontroller01/system/calibration_selection
13-Oct-2020 14:23:27.602 [DEBUG] [org.openhab.binding.mqtt.generic.ChannelState     ] - Subscribed channel mqtt:homie300:4ce1d806:rollershuttercontroller01:system#log to topic: homie/rollershuttercontroller01/system/log
13-Oct-2020 14:23:27.603 [DEBUG] [org.openhab.binding.mqtt.generic.ChannelState     ] - Subscribed channel mqtt:homie300:4ce1d806:rollershuttercontroller01:system#rssi to topic: homie/rollershuttercontroller01/system/rssi

In this example I changed the mqtt:homie300:4ce1d806:rollershuttercontroller01:system#rssi channel. Only the rollershutter_1 and rollershutter_2 nodes where unsubscribed. All the properties in the system node where not unsubscribed, but then subscribed again. After this the rule for the mqtt:homie300:4ce1d806:rollershuttercontroller01:system#log triggered twice every time something was published on the topic.

Should I report this as an issue on GitHub?

If it’s making the effort to unsubscribe some channels, it sounds like a bug if it’s failing to get 'em all. Present you evidence and analysis in a Github issue.

Presumably this is just a nuisance during development for you now, and will not occur during normal running.

1 Like

I’ve just reported this issue:

1 Like