It’s not really a “debounce” kind of situation. I haven’t found a “good” solution, but I have a “good enough” solution for my situation. The two switches I’m using are for a bathroom, and an attached laundry room with no other entrance than the one inside the bathroom.
I have set up the bathroom switch to cause the laundry room switch to match its state, whatever that happens to be, but not the other way around. Then the laundry room’s long press toggles the bathroom. This way the MQTT messages will never occur fast enough to cause this type of feedback loop.
There’s another solution where you can have the rules fire only for the switch state, and not for the power state. So like this:
on switch1#state=2 do POWER TOGGLE endon on switch1#state=2 do publish cmnd/other_switch/POWER TOGGLE endon
I use two separate rules rather than a backlog command here because the time it takes to process the backlog command is noticable. Separate rules seems to be faster, especially when it comes to control of the local relay. However, since this solution is only using toggles and not explicit on/off, the switches can get out of sync if they are operatated by means other than the switch (i.e., REST, MQTT, etc.)
Everything I’ve tried has drawbacks…I haven’t found a “perfect” solution yet.