Lightray22's Mildly-Terrifying Raspberry Pi-Powered Smart Plug Costs as Little as $27 a Unit
"I built this with a whole lot of hot glue and soldering. It's still a little bit ridiculous but it almost crosses the line to practical."
Pseudonymous maker "lightray22" has put together a somewhat dangerous-looking but admittedly low-cost home-brew smart plug, designed to be controlled over a raw network socket and powered by a Raspberry Pi Zero W single-board computer (SBC).
"I wanted to see if I could make something functionally equivalent to a TP-Link HS100 smart plug, and I don't think this is too far off," lightray22 writes of their build. "The HS100s are nice, but while they can be controlled locally with OpenHAB they are a bit of a pain to set up for local use and they still try to call home randomly."
"I wanted something fully local and open source, so I built this with a whole lot of hot glue and soldering. It's still a little bit ridiculous but it almost crosses the line to practical."
The heart of the system is a Raspberry Pi Zero W single-board computer, which costs just $10, mated to a cheap power cord, a 5V power supply, a mains-capable relay which triggers on 3.3V logic from the Raspberry Pi's general-purpose input/output (GPIO) header, and some parts from a starter kit packed with buttons, LEDs, and resistors.
""For software, I wrote a few Python scripts on Raspbian Lite using RPi.GPIO," lightray22 explains. "To make the plug relatively 'easy' to configure, I created a separate config partition on the SD card. The Pi runs an init script at boot which reads the config partition and copies over Wi-Fi credentials, the hostname, and the public key to use for SSH. This way you don't have to go searching through root to configure it for a new network."
The project can be controller in three ways: "You can either a) physically use the button, b) SSH into the Pi, or c) use telnet or netcat to control it over the LAN," lightray22 explains. "I might eventually write a binding for OpenHAB."
More details on the project, which lightray22 estimates would cost around $27 per unit to put together in batches of five, are available on Reddit. Source code, meanwhile, has been published to GitHub under the reciprocal GNU General Public License 3. Those looking to replicate the feat are warned, however, that hot-glue, cardboard, and tape do not make for the safest of mains-powered device.