How to control a socket with multiple switches?

Hi,

I want to control a tasmota socket from few different places:

  • A on/off switch on the socket
  • a Zigbee switch
  • http request to turn the socket on or off

I have registered the socket, and zigbee button in HA. I can:

  • Switch the socket on / off using socket’s switch
  • Switch the socket on / off using http call.
  • Switch the socket using zigbee switch after adding two simple automations:
  • When zigbee switch is on - turn socket on
  • When zigbee switch is off - turn socket off.

All the socket can be controlled using zigbee button only if other methods did not control the socket. If I use any other method to control the socket - the zigbee switch control does not work as expected. As I see problem is that zigbee switch’s state goes out of sync if socket’s state is changed in any other method, and to be able to control the socket with zigbee basically I need to send minimum 2 commands: on + off or off + on depending on the state.

How can I forcefully toggle tasmota socket via automation when a command from zigbee switch comes representing the current state of the zigbee switch state?
In other words I want to trigger multiple automations on consequent event/message being sent from a zigbee device (e.g. if I send a message “switch: on” from zigbee device - run the automation, if I send “switch: on” from zigbee device once again - run the automation as I want to be sure it is on).

How to do that?

Thanks in advance.

P.s. I can not keep zigbee switches state in sync with tasmota socket’s state using state sync, because of the unresolved issue I reported earlier: Zigbee button and tasmota socket integration misbehaving