Skip to content

IvanVeloz/smart-usb-plug

Repository files navigation

Smart USB Plug

Photo of the USB plug PCB assembly.

Motivation

Smart plugs are ubiquitous. Smart plugs with energy measurement are a little rarer. With Matter, evern rarer. This project started out of my frustrations and ever-niching demands. Let me explain.

I recently got back into the aquarium hobby. In this hobby, nano tanks are in, and with that comes nano equipment. I was delighted to find the equipment needed the tank is USB A. So I set up my aquarium, my plants, added some snails, some shrimp. I then went to put the light on a timer. But timers are so 2006. We're in 2026 and aquarists are using smart plugs. Ugh.

Where do I start... Ideally I'd want smart plugs with energy monitoring so I can check on the equipment. Aquariums are life support systems for fish. A filter or a heater fails and the fish are dead. The plants need light on a schedule.

So I spent way too much time on the internet looking for the smart plug I wanted, to no avail. I settled for some Zigbee 120V smart plugs. They're nice, but they are inadequate for the task.

I tried to make the traditional 120V smart plugs work, but I found a few issues:

  • They are bulky. This 1.6 gallon shrimp tank needed a whole 6 outlet power strip because the plugs block 2 outlets each. The original power brick is the size of an iPhone's and blocks nothing.
  • They are not sensitive enough. The aquarium draws 3W total. The smart plugs struggled with this: their resolution is too low to be useful. One of them jumped between 0W and 1W and I'm pretty sure its average is meaningless.
  • They are innefficient. In terms of energy, space, and conceptually. You need one USB brick per smart plug. I rest my case.

I went to look for USB switches and found only one option on Amazon. It didn't have energy monitoring. So here we are, I designed my own.

Overview

This is a smart plug that uses USB A instead of the usual 120/240V mains plugs. Crucially, it has energy monitoring too.

Render of the USB plug PCB assembly.

Features

  • Communication over Matter, Thread, Zigbee, WiFi, and Bluetooth. So far Thread and WiFi have been tested with great results.
  • Can switch currents up to 1.5A. It also has overcurrent protection.
  • Measures current with sub-milliamp resolution and voltage with millivolt resolution.
  • USB data can be passed through the device or disconnected.
  • The microcontroller, an ESP32-C6, can be programmed and even debugged over the USB port. Easy hacking.
  • WiFi is 802.11ax. I don't want any more 802.11n 2.4GHz pollution on my WLAN. It is time to move on.
  • Has a NeoPixel, because everything gets a NeoPixel now.
  • It's flat and narrow enough that you can stack multiple of them on most hubs and charging stations.

Demo

Video clip of the USB switch turning a lamp on and off, being controlled by Apple Home on an iPhone.

Building your own

There are production files on the production directory ready to be added to JLCPCB. Just upload the zip file to their service. I also had success with OSHPark, though I did not have success hand-soldering the ESP32 module, so beware. If you plan to hand-solder a stencil is a must, and a hot plate or reflow oven are highly recommended.

Regarding the firmware, I am using HomeAssistant and ESPHome for the moment. ESPHome made the bringup so so easy and enjoyable. I was very impressed that I got Thread working as well as it has. It's been rock solid and development took only a couple of hours. You can find a copy of my ESPHome template here.

Future work

I would like to write a Matter firmware for this hardware. The end product would be something that behaves like a commercial product from a UX point of view. Honesly, ESPHome is 90% of the way there (if you have Home Assistant). But I would still like to write this Matter firmware for personal development. Also I feel Matter is a lot more approachable to the casual user (especially Matter over WiFi).

A parallel goal is trying for a Made for ESPHome certification. It looks attainable and it's something I feel would bring value to enthusiasts.

About

A smart plug for USB with energy measurement and Matter over Thread support

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors