Smart Switch

Greg Abbas

A Programmable Switch

Sonoff is a line of inexpensive smart switches that use WiFi for communication, and they're remarkable because it's possible to reprogram them by loading custom firmware. Then, instead of working with a proprietary app from the manufacturer, you can integrate them with your own MQTT-based home automation system.

I've tried a few other smart switches that I wasn't satisfied with for one reason or another. For instance Insteon (a.k.a. Smart Home) makes several models of plug-in switches and dimmers, but their communication technology is frustratingly slow and unreliable. Lutron Caseta has a plugin device that's reliable, but it's a dimmer (not a switch) and even when turned off it lets through a pulsing trickle of electricity that can make LEDs flash.

So I gave Sonoff a try. I had heard about them from other DIY-ers, and the S31 (pictured above) is available for only about $17 (you can buy a pair of them on Amazon). In addition to being a relay, it has the nice feature that it can measure and report energy usage.

There's a great tutorial by Matt and Diana about how to replace the firmware on an S31 with "Tasmota", a flexible, open-source implementation. You open up the switch, connect it to your computer, load the new firmware onto it, and then close it back up again.

I won't repeat all of their instructions here, because they already did a great job explaining the process. You should just basically just follow what they did.

A Custom Tool

The one place where I deviated from their tutorial is that they suggest soldering four wires onto each S31 in order to program it. I didn't really want to do that, so instead I made a probe to electrically connect to an S31 without soldering to it. If I'm being honest, this was motivated less by needing to program a large number of S31's and more by having just gotten a Prusa i3 MK3S+ 3D printer for Christmas and wanting to play with it.

The PCB inside the S31 has little pads that you need to connect a serial signal to (VCC, RX, TX, and GND) in order to do the programming. There are no headers (or holes to solder a header onto), just metal pads. (Credit to Matt and Diana for this photo)

I had a small compression spring handy, so I designed a clothes-pin-like device in Fusion 360 to hold pins gently against the pads. I put a circular indentation in the back to hold the spring in place, and a small hole in the middle for a nail to serve as an axle.

In the front, there are 12 holes in a 2x6 pattern (0.1 inch spacing) to hold the contact pins and a 1x6 header. I sliced it in PrusaSlicer and printed it in PLA with the stock settings on the i3 MK3S+.

I originally tried just using the header pins as contacts, but that doesn't work because they're rigid and may not all make contact with the pads on the S31. So I replaced them with tiny spring-loaded "pogo pins" (Amazon). That way, each pin can adjust to the correct height individually, and they all make contact.

I used a small 2x6 PCB (cut out with a dremel) to hold the pogo pins and connect them to the header. To hold the pogo pins at the right height and keep them from falling out while I soldered them, I made a little header block. Theoretically this could have been modeled as a single piece instead of two pieces, but doing it this way meant I could print without using supports.

I printed the pieces out (two copies of the clip arms and one copy of the head) and glued the head onto one of the clips. I then put a pogo pin in each of the six front holes, placed the PCB over them, and soldered them to it. Then I slid the header in and soldered it onto the PCB also.

I put the two clip arms together with their axle holes aligned, and slid the nail axle into place.

Finally, I pinched the spring and slid it into place on the back.

Now programming an S31 is easier: open the clip by pinching it on the tail, align the clip's pins with corresponding pads on an S31 and gently let it clamp on.

When you're done, just pinch the clip's tail again to release it from the S31.

Assorted details

Download the STL files from Thingiverse: https://www.thingiverse.com/thing:4707561

Hardware list:

Questions or comments? Email me at .

2021 Jan 2