Great idea! I haven’t used AppDeamon yet, why do you it could handle the race conditions we get Aqara & HA automations?
Sure - let me try to explain. A traditional 3 way switch has two switches controlling the same light (or set of lights). There are different ways to do it but he most common is here:
The problem is that the Aqara Wall Switches don’t support this kind of wiring because they only have live & switched live (the version with neutral has neutral too, but it is not relevant for this problem). When I replaced the traditional switches with the Aqara ones I had to hack the wiring: now one switch act as master, actually switching on & off the lights. The circuit on the other switch end is instead permanently closed: the switch is powered but it doesn’t switch on/off the lights.
An alternative to the approach above would have been to put the two Aqara switches in series or in parallel: in both cases it is required to create an automation to keep them in sync, plus - due to their internal electronic there was a real risk of having issues: lights blinking with the parallel setup or switches offline with the in-line option.
Back to my choice… I had to “decouple” the slave switch and create an automation in the Xiaomi app: when click on the slave switch is detected then toggle the master switch. It works as a real 3-way setup but there is a small delay (that is killing me…) when the lights are operated from the slave switch (due to the Xiaomi automation implementation based on a mix of cloud and LAN).
The two automations I’ve posted are an attempt to disable the decouple mode and use the slave switch as a click button. The main point is that when I trigger the slave switch I don’t want the Xiaomi relay (inside the switch) to stay on when the lights are off, this would shorten its lifespan. Hence either I keep the two switches in sync or I use the slave to go on and then off (a fake button).
In some other switches I’ve successfully implemented the 3-way switches with the Aqara wireless wall switch, but I didn’t want to use them in the rooms that I use more frequently because the idea of changing batteries of a wall switch is quite unusual.
I hope it makes sense, otherwise I’ll try to make a drawing to explain the wiring.
Everything would have been easier is Xiaomi had thought about adding hardware support (switched live 1 & switched live 2) to the switches.
Finally, a part from this issue with the 3 way setup, I am quite happy with the Xiaomi switches and HA integration: I’ve now 25 switches (a mix of wall / wireless & single / double) and they are all controlled via HA and Google Assistant.