Mqtt monitoring / syncing states, need bit of help

Just one word of caution on this. What you have here is a closed loop system. Inputs come in from the Sonoff devices, the flow decides what to do and outputs commands to the Sonoffs, this in turn causes more inputs at the front, which again may cause further outputs, and so on. It is possible that there may be some combination of inputs at just the right times (clicking multiple switches at almost the same time for example) that would cause the system to enter an unstable state with messages running round the loop and the lights switching on and off rapidly. I don't even know if it is possible to calculate whether your system may have any such unstable states.
It would be possible to remove such possibilities if you could determine whether a state change input was as a result of an output sent by your system or whether it was caused by an external event (someone pressing a switch). I don't know whether it is possible to know that or not. If you could tell then the system should be told to ignore inputs that come from commands generated by the flow. This would break the loop and it would not be possible to have an unstable situation.
In practice what you have will very likely be fine but if once in a blue moon when more than one switch gets pressed at almost the same time then it enters such a mode you will know why. Quite possibly in that event clicking the switches again will kick it out of that mode, or possibly not :slight_smile:
It would be worth trying to see if you can make it go unstable by clicking buttons randomly just so you know how likely it is.