stjohnjohnson / smartthings-mqtt-bridge

Bridge between SmartThings and MQTT
https://hub.docker.com/r/stjohnjohnson/smartthings-mqtt-bridge/
MIT License
363 stars 241 forks source link

Certain switches/dimmers get stuck in a infinite loop during fast toggling from HA server #164

Open etc6849 opened 6 years ago

etc6849 commented 6 years ago

I am using the ST MQTT bridge with my home automation system that supports MQTT (not Home Assistant).

I have my home automation server set lighting states by appending cmd to the MQTT message, and I have my home automation server receiving MQTT messages from the ST bridge ending in state. I am using Mosquitto as the MQTT broker, and running the ST MQTT Bridge under windows (npm and node.js are installed).

Everything works great for z-wave plus light I tried, SmartThings motion and SmartThings contact sensors. However, the SmartThings zigbee outlet causes duplicate MQTT states to be set. This causes no harm unless someone toggles the outlet fast on my home automation server, then the duplicate MQTT states sent from the ST MQTT Bridge get mixed up as shown in bold below, and an infinite loop/tail chasing begins!

info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = off info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = off info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on info: Incoming message from MQTT: smartthings/thirdbedroom.outlet/switch/cmd = on info: Incoming message from SmartThings: smartthings/thirdbedroom.outlet/switch/state = on

What is more interesting is that z-wave plus dimmer I have setup with the same SmartThings hub works flawlessly. I can toggle power on/off very fast on my home automation server, and see the light change the appropriate number of times (e.g. no tail chasing). This is because I am using cmd appended to the MQTT topic when my server sends a command. If I didn't do this and replaced cmd with state in the ST MQTT bridge config file, tail chasing certainly would occur.

I'm really not sure how to proceed. Hopefully someone has ran into this issue with zigbee lights and has some suggestions. A similar issue occurred when I controlled my Hue lights via the ST MQTT bridge, so I just went back to using the Hue HTTP API from my home automation server.

I'm really not sure why the z-wave plus dimmer (Leviton DZ6HD) works so well. Must be something to do with how the SmartThings hub handles zigbee that is causing the issue? Regardless, the duplicate MQTT topic writes really needs fixed if possible. Please help if you have any suggestions.