I recently switched to Octopus Energy and got one of their Home Mini devices, which connects to my electricity meter via ZigBee and to my home Wi-Fi to upload meter data to the Octopus servers every 10 seconds. Using their GraphQL web API, you can check your current electricity demand anytime. I've documented how to use their API to get your current electricity demand here. Much more is possible from their API but I only need the current electricity demand.
Here is a quick project to visualise your electricity demand data with a strip of 50 colour LEDs. The colour varies, purple to red, with your current electricity demand.
I'm using a Pimoroni Plasma 2350W which is a USB-C powered controller for WS2812/Neopixel addressable LED strips with 2.4GHz Wi-Fi. The Raspberry 2350W is running MicroPython v1.27. I also have a 5m Flexible RGB LED Wire (50 lights). You could use a standard Raspberry Pico 2W but the Pimoroni version has the advantage of a set of screw terminals for easily connecting the LED strip.
The MicroPython code requests your current electricity demand data from the Octopus server every 30 seconds, which, with the limit of 125 requests per hour, is about as fast as possible.
You'll need to install the latest Pimoroni MicroPython code (plasma_2350_w-v1.1.0-micropython.uf2) from
here. You probably don't want the "with-filesystem" version as that one replaces any files already stored on the 2350W's file system with some demo files.
There are four files in this project. You can download them in a .zip file from
here.
main.py which automatically launches OctopusElec.py when turned on
OctopusElec.py which is the main code
graphqlclient.py which makes the GraphQL requests and
secrets.py shown below where you must enter four bits of your information.
WIFI_SSID = "Your WiFi SSID"
WIFI_PASSWORD = "Your WiFi Password"
OCTOPUS_ACCOUNT = "Your Octopus Account number in A-abcdabcd format"
OCTOPUS_APIKEY = "Your Octopus API Key"
To get the API Key click the "Generate my API key" on
this Octopus page (you'll need to be logged into your Octopus account).
The easiest way of getting the code onto the Plasma 2350W is to connect it to your PC with USB and to use
Thonny to copy the files onto the device. After you've modified the secrets.py file you can disconnect from the PC and power it up from any USB power socket.
Here are the steps:-
2) With a USB lead plugged into your PC power up the 2350W with the boot button pressed, it will appear as a new drive. Copy the latest firmware, plasma_2350_w-v1.1.0-micropython.uf2, onto the drive
3) Download and unzip the .zip file containing the project .py files from
here4) Edit the secrets.py file with your Wi-Fi SSID, password, Octopus account number and Octopus API key
5) Use Thonny to copy the four files (main.py, OctopusElec.py, secrets.py and graphqlclient.py) onto the 2350W
6) Press the reset button on the 2350W and it should connect to Octopus servers and start displaying your electricity demand as a colour. Logging is displayed whilst the 2350W is connected to your PC.
Near the top of OctopusElec.py there are some settings you can alter.
# ─── Configuration ────────────────────────────────────────────────────────────
LOW_W = 100 # The lowest wattage expected (violet)
HIGH_W = 6000 # the highest wattage (red)
REFRESH_MS = 30000 # How often the consumption is requested. Not too fast or API will rate limit
NUM_LEDS = 50 # The number of LEDs on the strip
ONBOARD_DIM = 0.15 # onboard LED default brightness (0‑1)
Change LOW_W and HIGH_W to set the typical demand range in your house. This might take a bit of trial and error.
Don't alter the REFRESH_MS below 30000 (30 seconds) as anything more frequent causes the API to fail with request limit exceeded errors.
No comments:
Post a Comment