← Projects
raspberry-pi intermediate 21 hr ago ◑ 5 views ◯ 3 min read

Build a Raspberry Pi-Controlled Smart PDU for Remote Power-Cycling Shop Network Gear

Build time: A weekend (3-5 hours including enclosure wiring and testing)
Tools needed: Soldering iron (optional, for clean connections), wire strippers, screwdrivers, digital multimeter, drill for enclosure mounting holes, label maker or tape for outlet identification
raspberry pismart pdurelay moduleremote rebootpower cyclingsnmpshop network
Parts List

A camera that locks up, an access point that needs a weekly reboot, a Klipper host that occasionally wedges — every maker shop network accumulates at least one device that's more reliable after a power cycle than any amount of software troubleshooting. A commercial networked PDU (power distribution unit) solves this cleanly but starts well into three figures for a real managed unit. This build gets the same core capability — remotely power-cycling individual outlets, not just one shared switch — from a Raspberry Pi and a relay board for a fraction of the cost, with a simple web dashboard for status and control.

How It Works

A relay board switches mains power to each outlet independently, with the Pi's GPIO driving the relay coils through opto-isolation. A small Flask or Node web app running on the Pi exposes a dashboard showing each outlet's state and a button to toggle it, plus a scheduled or threshold-triggered auto-reboot option (for example, pinging a device and power-cycling its outlet automatically after several failed pings in a row). SNMP support is optional but included here as a secondary control path, letting existing network monitoring tools (Zabbix, LibreNMS, and similar — see this site's Zabbix-on-Pi guide for a monitoring pairing) query and control outlets the same way they would a commercial PDU.

Wiring the Relay Side

This is mains-voltage wiring, not a 5V breadboard project — treat it with the same care as any other mains electrical work. Each outlet's hot (live) conductor routes through one relay's normally-open contacts; neutral and ground run straight through to every outlet without passing through any relay — switching only the hot leg is both standard practice and the safer configuration. Keep the Pi's 5V logic side and the relay board's mains-switching side physically separated inside the enclosure as much as the layout allows, and never route low-voltage GPIO wiring and mains wiring through the same unshielded bundle.

StepDetail
Mount the fused IEC inletThis is the unit's own power input; the fuse protects the whole build, including the Pi, from a downstream fault
Wire inlet hot through to each relay's common terminalEach relay then switches that hot leg to its own outlet independently
Bus neutral and ground to all outlets directlyNever switch neutral or ground; only the hot conductor gets interrupted
Wire relay control pins to Pi GPIO through the board's opto-isolated inputsThe opto-isolation is what keeps a relay-side fault from ever reaching the Pi's GPIO directly
Secure all mains connections inside the enclosureLever-nuts or proper wire nuts, fully enclosed — no exposed mains conductors anywhere accessible

Software

A minimal Flask app with RPi.GPIO (or gpiozero) handling the relay toggling, SQLite for logging outlet state changes and reboot events, and a simple ping-based watchdog loop are enough for the core feature set: view status, toggle outlets manually, and configure auto-reboot rules per outlet (ping target, failure threshold, cooldown period to avoid reboot-looping a device that's failing for a non-power reason). Expose the dashboard only on your local network or behind your existing VPN/reverse proxy setup — a web-exposed relay controller for mains power is not something to put directly on the open internet.

Safety

This project puts a hobbyist board directly in line with mains voltage, and that carries real risk if built carelessly: use a genuinely rated junction box, keep all mains connections enclosed and inaccessible to a stray finger or a curious pet, double-check polarity and continuity with a multimeter before the first live power-on, and add the fused inlet rather than skipping it to save a part — it's the one component standing between a wiring mistake and a bigger problem downstream. If you're not confident reading and following basic mains wiring practice, this is a good project to build alongside someone who is, or to have the finished wiring checked before it goes live.

Once it's running, the payoff is immediate: a hung camera or wedged access point stops being a trip to the breaker panel or a crawl behind a bench, and becomes a dashboard click or an automatic ping-triggered recovery — the same capability a commercial networked PDU sells for considerably more than this build costs in parts.