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.
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.
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.)
piPlug-
. Connect to it - the password is 12345678
.192.168.0.2
, subnet mask 255.255.255.0
. You don’t need a default gateway or DNS.SSID
: your wifi’s namePassword
: your wifi’s passwordCountry
: the two-letter code of your country (important for the wifi bands to be used and cannot be omitted) - something like US
, DE
, CN
, PL
etcName
: choose a name for this piPlug. It will be its new hostname, and visible like this to your DHCP server. The name will also be communicated back when HTTP requests are made, so you can use it to identify the device laterIdentification
: optional - an arbitrary string, e.g. a uuid or a salt, that you can use as a very, very basic, unencrypted security key. If you set this, you will need to provide this string every time you call one of the endpoints (i.e., to turn an outlet on or off.) If you leave this empty, you won’t need to provide this key when calling endpoints.Status updates
: optional - provide a URL (must be http - SSL is not supported) that this piPlug calls whenever an outlet changes its state. It will also call this endpoint right after it boots, so you can use this request to advertise the DHCP-assigned IP address.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"]
}
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.