piPlug

Introduction


piPlug uses a Raspberry Pi Pico W with its GPIO and relays/relay boards to create a minimalist smart plug. It uses a MicroPython based web server (MicroPyServer) to provide the initial configuration web interface, an overview page, and endpoints to get and set outlet states.

Background


When setting up smart plugs and other devices, I got annoyed with all the apps, hubs and other proprietary mechanisms to deal with. My intention was to communicate with devices using Node Red running on IOBroker (although I didn’t really want to lock in to IOBroker or Node Red,) but I kept having to use device specific adapters with authentication mechanisms of questionable reliability or longevity. Since my requirements are pretty simple, I decided to simply create cheap smart plugs myself that do as little as possible. I want an inexpensive device that survives getting unplugged without proper shutdowns, controls up to 5 outlets per device, communicates via HTTP, can push outlet states to configurable HTTP endpoints, can be controlled using simple HTTP requests, provides a very basic “security” mechanism to prevent household members from randomly turning outlets on and off in their web browsers, uses household wifi, emits an access point for configuration purposes if not yet configured, and can be “factory”-reset easily to reconfigure.

Hardware


Hardware

Use


Note: I don’t think it’s necessary to run a DHCP server just for the initial configuration. There is a pure python based implementation somewhere that will probably work but the overhead (and space needed) is quite significant. If you think this initial setup is too much work, just create a user_config.py manually (see below) and copy it onto the pi. In that case, you can skip all the initial configuration. The device should boot straight into the user configuration (as a wifi client using DHCP.)

Initial configuration

Headless configuration

If you don’t want to use the initial configuration mechanism, you can provide your own user_config.py. Create a file with the following contents (edit values as described) and place it into the root folder of your Pico’s internal storage.

user = {
	#Your wifi network name
	"ssid": "My Wifi SSID",
	#Your wifi network password
	"pwd": "password",
	#A custom hostname for this piPlug
	"device_name": "piplug1",
	#A custom key, or empty if not needed
	"id_key": "changeme",
	#The wifi country 2-letter code
	"country": "US",
	#An array of update URLs that will be informed 
	#after the device boots or the state of an outlet changes.
	#This MUST be unencrypted. SSL is not supported.
	"updates": ["http://my-home-server.local:8081/devices/statusupdate"]
}

Disclaimer

Everything you do based on this is at your own risk. You’ll probably be dealing with 230V or 110V that can seriously hurt or kill you. You might break equipment, cause a fire or other damage to yourself, your property, others, or other people’s property. That’s on you - I’m not taking any responsibility for any of that.