MQTT Homie: trigger channel silent after reboot

Tags: #<Tag:0x00007f0146057000> #<Tag:0x00007f0146056d80>

(Fischerman) #1

I’ve set up MQTT 2.4 bindings with Homie and an ESP8266 which has a single button to control some lights. I’ve linked the button to a switch item using the rawbutton-toggle-switch profile (via Paper UI). The first problem I experienced is that a single press triggered multiple events (which makes my lights go crazy):

2019-01-09 19:22:23.580 [vent.ChannelTriggeredEvent] - mqtt:homie300:f4feb5ec:b361d0:button#button triggered PRESSED
2019-01-09 19:22:23.585 [vent.ChannelTriggeredEvent] - mqtt:homie300:f4feb5ec:b361d0:button#button triggered PRESSED
2019-01-09 19:22:23.588 [vent.ChannelTriggeredEvent] - mqtt:homie300:f4feb5ec:b361d0:button#button triggered PRESSED
2019-01-09 19:22:23.592 [vent.ChannelTriggeredEvent] - mqtt:homie300:f4feb5ec:b361d0:button#button triggered PRESSED
2019-01-09 19:22:23.780 [vent.ChannelTriggeredEvent] - mqtt:homie300:f4feb5ec:b361d0:button#button triggered RELEASED
2019-01-09 19:22:23.784 [vent.ChannelTriggeredEvent] - mqtt:homie300:f4feb5ec:b361d0:button#button triggered RELEASED

When I subscribe to the channel via Mosquitto I only observe a single message (so ESP and transmission seem to work fine). I thought a restart of OpenHab may help. However, now I don’t see any such messages in the log and the item does not toggle. I can still see the messages in Mosquitto and also the device status is updated in OpenHab

2019-01-09 20:33:14.874 [hingStatusInfoChangedEvent] - 'mqtt:homie300:f4feb5ec:b361d0' changed from ONLINE (CONFIGURATION_PENDING) to ONLINE

QoS is at least once, which might explain the first problem but not the recent problem. Any ideas?

(David Graeff) #2

I think a rawbutton produces events as long as it is clicked.

Does it work without the profile?

(Vincent Regaud) #3

What firmware do you use?
Is that button debounced?

(Fischerman) #4

Does it work without the profile?

As far as I understand a link always has a profile and in case of a button (channel itself is correctly auto-discovered as trigger channel of type system.rawbutton as documented the only profile Paper UI let’s me select is Raw Button Toggle. The docs explicitly mention the switching lights example as a use case for that profile.

What firmware do you use?

I use Homie for ESP8266 (Homie v3 patch). Essentially I follow this:

Is that button debounced?

No, but it’s not the issue as I can confirm by mqtt logs (i pressed the button twice):

$ mosquitto_sub -t '#' -F '@Y-@m-@dT@H:@M:@S@z \e[92m%t \e[96m%p\e[0m' -q 2
2019-01-10T22:01:30+0100 homie/b361d0/button/button PRESSED
2019-01-10T22:01:31+0100 homie/b361d0/button/button RELEASED
2019-01-10T22:01:35+0100 homie/b361d0/button/button PRESSED
2019-01-10T22:01:35+0100 homie/b361d0/button/button RELEASED

Might still be a good idea to add debounce, though.

(Fischerman) #5

Removing and recreating the Thing entirely solves the problem. Now, I have exactly one message per button press. But only until the next reboot. A reboot seems to consistently break the setup. Do I need to save something explicitly?

(David Graeff) #6

No. There seem to be a bug hidden somewhere. But without knowing your setup it’s hard to replicate.

(Fischerman) #7

I think the two issues (no toggle and too many toggles) are related. I can also reproduce the latter. Every time a Homie device goes offline and online again I get an additional log of a press (see above). I suspect that multiple handler run in parallel. And on boot no handler is started.

My setup is OpenHab 2.4.0 on Openhabian (Pi). I’ve created a single switch item and linked the button channel to the item. I’ve noticed in the logs, that on boot all links are recreated (not only mqtt):

2019-01-10 22:59:10.713 [temChannelLinkRemovedEvent] - Link 'Light => mqtt:homie300:f4feb5ec:b361d0:light#on' has been removed.
2019-01-10 22:59:10.716 [temChannelLinkRemovedEvent] - Link 'Light => mqtt:homie300:f4feb5ec:b361d0:button#button' has been removed.
2019-01-10 22:59:10.734 [temChannelLinkRemovedEvent] - Link 'Light => zwave:device:707546a4:node98:switch_binary' has been removed.
2019-01-10 22:59:10.740 [temChannelLinkRemovedEvent] - Link 'Light => mqtt:homie300:66080c3d:button#button' has been removed.
2019-01-10 23:00:37.647 [.ItemChannelLinkAddedEvent] - Link 'Light-mqtt:homie300:f4feb5ec:b361d0:light#on' has been added.
2019-01-10 23:00:37.655 [.ItemChannelLinkAddedEvent] - Link 'Light-zwave:device:707546a4:node98:switch_binary' has been added.
2019-01-10 23:00:37.660 [.ItemChannelLinkAddedEvent] - Link 'Light-mqtt:homie300:f4feb5ec:b361d0:button#button' has been added.
2019-01-10 23:00:37.664 [.ItemChannelLinkAddedEvent] - Link 'Light-mqtt:homie300:66080c3d:button#button' has been added.

Is this on purpose? Is there any other data that might be helpful?

(Fischerman) #8

I also tried the embedded mqtt broker. Same behavior.

(Steve) #9

I’ve also just noticed missing Homie messages after restarting. There is an issue in SmartHome that sounds a lot like the same thing: