Wireless Switch conversions to MQTT
I've been converting all my "home automation" stuff to MQTT, mostly using Sonoff's that have been re-flashed with Tasmota. This has worked out well and I'm very happy with the Sonoff/Tasmota reliability.
I recently realized that I have a bunch of cheapo no-name wireless switches, and decided they should be converted to WiFi control using MQTT. This seemed like it would be "easy"; the units already had power plug, power jack, power relay, LED, and pushbutton. All that was needed for the conversion was adding an ESP8266 that was flashed with Tasmota.
This turned out to be harder than I'd imagined. This was one of those projects that was financially "marginal", since the cost of the parts to convert cost almost as much as a Sonoff unit. But when has "it's cheaper to buy a new one" ever stopped a hacker ?
While I show schematics and (most) parts values, this isn't really meant to be a step-by-step guide, since you almost certainly don't have the exact units I have. Consider this more of a "rough guide" to the things you'll need to be aware of should you want to attempt to hack your own wireless switches.
The first units I attacked were the "white" ones, because I have six of them. First step would be to reverse engineer them so I could what modifications would be needed.
Note: Click on the pictures to embiggen.
No-name wireless power switches in their original packaging. The remote takes an odd-sized 12v battery. I'll call these the "white" switches, because the other ones are black.
WARNING Since these run on line voltage (120VAC in North America, 230VAC in much of the rest of the world), these are dangerous to fool around with when the enclosure is open. There's no isolation transformer, either, so this is what we used to call a "hot chassis" design. So if you want to hack around with these switches, be careful!
Circuit Description, "white" units
Original logic board schematic
The line voltage is dropped using a power resistor and a 1uF 250V cap, and then rectified and filtered, yielding about 24VDC. There's a 78L05 regulator that drops that down to 5V for the logic and radio circuits. The relay has a 24V coil, driven by an NPN transistor on the logic board.
The main board has the power supply, the power relay, and the radio receiver. There's a 4 pin connector to the logic board. The logic board uses a 4013 CMOS dual flip flop whose inputs are the radio output and the two pushbuttons, and then drives the indicator LED and the NPN relay driver.
Initially I thought I could use the already existing 5V supply, but that doesn't have anywhere near enough current to drive an ESP8266. I ended up having to replace the 1uF 250V cap with a 2uF 200V cap, which increased the current available at 24V. Then I added a switched mode power supply module to regulate the 24VDC down to 5V. The ESP8266 module is soldered to a cheapo carrier board, that contains a linear regulator that regulates the 5V down to 3.3V.
I managed to hack up the logic circuit and preserve the radio receiver function, so these units are now both MQTT/WiFi controlled and radio controlled and push-button controlled. This hacking was a pain in the neck, frankly, but once I'd bought all those parts (ESP8266, regulators, 2uF caps), I felt committed.
Modified logic board schematic. The upper flip flop acts as a one-shot multivibrator to square up the radio output, and the diode acts as an OR gate so either the radio or the push button can pull GPIO-0 low. This toggles the state of the power switch. The lower flip flop is a power on reset for the ESP8266.
The "logic" board from the "white" switches. Left LED shows the relay state, right LED lights if power is present at the input. The transistor (lower left) is an NPN that drives the relay. Left button is "ON", right button is "OFF", in the original circuit. After my hacking, left button is "ON/OFF toggle", and the right button resets the ESP8266.
View of the base/power supply after modification. The black rectangle in the middle is the 2uF 200V cap, that I put in instead of the 1uF 250V cap. Lower left is the switching power supply that takes (nominal) 24V in and outputs 5V DC. Those discretes on the right side of the board make up the radio receiver.
Underside of the "logic" board, showing two of the cut copper runs.
Underside of the "logic" board, showing some added components.
Underside of the "logic" board, showing all the added components.
Underside of the "logic" board, showing wiring harness connections. (Yes, a different unit than the other photos.)
Top side of the "logic" board, showing removed and moved components.
Logic board with ESP8266 board attached, mounted in the case. Note 100uF cap mounted on the ESP8266 carrier board. I had a problem with the board resetting without the added filtering. All the added wiring is 22ga solid telco wire.
The "black" units.
The "black" units turned out to be much easier to convert, because I wasn't lulled by the prospect of using any of the internal circuitry. For starters, the internal power supply voltage is 48V (nominal), the relay is 48V, and the radio is a pain in the neck. Every time the unit loses power, the receiver radio forgets that it's paired with the transmitter, and needs to be re-paired.
The "black" units, front view.
The "black" units, rear view. I've added a sticker with the MAC address of the ESP8266 that I've put inside this unit.
The conversion was simple.
The "black" switches, top one is stock, bottom one is modified.
Detail of modified "black" switch, showing wiring from ESP8266 carrier board to the main board.
Bottom of "black" switch main boards, showing modifications on the right.
Side view of "black" switch main boards, showing modifications on the lower board.
Flashing the ESP8266 modules with Tasmota is left as an exercise for the reader.
Q Is it possible to modify an X10 module similarly?
A I looked into it, but the X10 modules are a bit small to hold an ESP8266, and the ones I have don't use an ordinary relay, they use a relay that's a lot like a latching relay. (Or they use a triac, which would necessitate figureing out how to drive that with an ESP8266.) If anyone figures this out, I'd love to hear about it, as I have a big ol' box of X10 modules.
Q Will you help me hack my units, that are (different from || the same as) yours?
A Probably not, I'm retired now, so you can't afford my rates.
Don't electrocute yourself hacking around with these switches. If you're measuring inside a live unit, work with one hand in your pocket, or use an isolation transformer to separate the circuit from the line voltage.