ESP8266 or modifying Livolo switches

4 years ago I bought a new apartmentlivolovye switches. Then still not knowing about any smart homes and ESP. And when I met ESP, I found that they could be screwed to Livolo. This allows remote control of switches, both from a computer and from a telephone, and, if desired, from another continent. As well as performing certain scenarios.

Attention. For the doped circuit breaker to work, it is necessary that both the phase and zero are suitable for the circuit breaker.
So. What we need for this. First of all, the switch itself. They have been repeatedly reviewed here and with the schemes and with some doping. I use the UK version, simply because when I bought them, beige Europeans were not available. But they have an "advantage." It is more convenient to hide the power supply behind the switch, since the box is larger. Of course, the ESP reviewer, a few resistors, a pair of condenders, a pair of optocouplers (I used PC817) and the AMS1117-3.3 stabilizer will be needed.

My management was divided into two parts. A small board with optocouplers and a little more with the ESP itself.
Some loot:



And in the end it turns out something like that.

and

We attach the board with optocouplers to the circuit board of the switch from the inside and solder the wires to the power, ground, sensor and red LED:

Then we solder the wires to connect with the ESP card.

We put the board in place, draw the wires through the “extra” holes in the switch case, glue the main board on the back of the case and solder the wires to it

At this "iron" part is over.
You can also flash the already soldered ESP by soldering toIt has 3 wires (RX, TX and GND) and connecting GPIO-0 to ground. But I prefer to do this in advance, using the Wemos board with a comb soldered on it. Very comfortably.

The module is put on the comb, stitched, then unsoldered.
I use the firmware ESPEasy Mega. Much has already been written about it, so I’ll dwell only on the moment of feedback from the switch to Domoticz. In the homespace, as usual, we create a dummy device. There is a virtual switch on it and in the command for switching on and off we register the same command imitating the touch of the switch:
http://192.168.3.50/control?cmd=pulse,14,1,200

On the ESP page, go to the Devices tab and create a Normal Switch there.

In Tools - Advanced we turn on the rules and on the Rules tab that appears we prescribe actions when the switch state changes:
on Light # Switch do
publish domoticz / in, {"idx": 34, "nvalue": [Light # Switch]}
endon

I pay attention, it is necessary to register in nvalue 0 or 1. If you register in svalue On or Off, then when controlling from Domotics, the switch will immediately turn on / off.
And of course, you need to set up a MQTT server in controllers.
You can also control two-buttonswitches, just change the number of used GPIO and optocouplers. It also works with dimmer switches, but only for switching on and off. The adjustment has not yet mastered, and I doubt that this is possible.
In general, in the long evenings I transferred all the switches to WI-Fi

Something like that. I hope someone will come in handy.