Display the upcoming prices on the Octopus Energy "Agile" tariff.
Display the upcoming prices on the Octopus Energy "Agile" tariff.
Octopus is an energy provider in the uk. Agile is a package they provide with half hourly energy prices. https://octopus.energy/agile/ Amazingly they offer an API to allow us nerds to code things.
It's for displaying current prices. It runs in python on a raspberry pi. This is great because it means you don't need to install anything*. The current version of Raspbian has the two things it needs: python and SQLite.
image of it working here -> https://imgur.com/hymxfbq
There's 2 versions right now. The first one I wrote was for the pimoroni "display-o-tron" hat, which is a three line LCD with RGB frontlighting. It's good, but it's not graphical, and it made a whine noise (a fault in my unit).
So I wrote a second version for the pimoroni inkyphat https://shop.pimoroni.com/?q=inkyphat. This is silent, doesn't self light, consumes no extra power, and oh, it looks awesome!
(* other than the libraries for whatever display device you want...)
currently:
This is actually more of a tutorial on what I've found to be the best way to just set up a pi to run arbitrary code without the hassle of a mouse keyboard and monitor. It's the path of least resistance!
Once imaged, put the SD card in your Pi and wait a while for it to boot (it can take 5-10 minutes). It should connect to your wifi, then you can ssh to it using ssh <username>@<hostname>.local
replacing the username and hostname for those entered when imaging
Once you have an ssh terminal, you can get started with setting up our project
Install the libraries for inky phat using the one line script from pimoroni
curl https://get.pimoroni.com/inky | bash
Install git:
sudo apt install git
Clone our project
git clone https://github.com/pufferfish-tech/octopus-agile-pi-prices.git
cd octopus-agile-pi-prices
Install requirements
pip install -r requirements.txt
Setup the database
python3 create_price_db.py
You'll need to obtain some information from Octopus for the next step. Go to the octopus developer page and scroll to "Unit rates". There you will see a URL, for example "https://api.octopus.energy/v1/products/AGILE-FLEX-22-11-25/electricity-tariffs/E-1R-AGILE-FLEX-22-11-25-M/standard-unit-rates/". Look at this part: "E-1R-AGILE-FLEX-22-11-25-M". This is in the format E-1R-AGILE-<tariff>-<region>
. The tariff is the part following "AGILE-", e.g. "FLEX-22-11-25". The region is the letter at the end, e.g. "M".
Now its time to test our scripts:
Get prices
python3 store_prices.py -r <your region> -t <your tariff>
Update the display
python3 octoprice_main_inky.py
You should see your display update with the current price!
Run crontab -e
on the pi and add:
@reboot sleep 10; cd /home/$USER/octopus-agile-pi-prices; /usr/bin/python3 octoprice_main_inky.py > /home/$USER/cron.log
*/30 * * * * sleep 20; cd /home/$USER/octopus-agile-pi-prices; /usr/bin/python3 octoprice_main_inky.py > /home/$USER/cron.log
05 16 * * * cd /home/$USER/octopus-agile-pi-prices; /usr/bin/python3 store_prices.py -r <your region> -t <your tariff> > /home/$USER/cron.log
Substituting the tariff and region as before.
The first line runs the script if you reboot, the second line runs every half hour (but delay by 20s to avoid time based issues!), the third line runs every day at 4:05pm to get the next set of prices.
Done! Fix it to the wall!
NOTE: If you are using the DOThat, you need to edit the above to use octoprice_main_dot.py instead of octoprice_main_inky.py. You will also need to run pimoroni's one line curl install script for the DOThat instead of inkyphat. You can go find that yourself, it exists :)
Another NOTE: I tried to make this code simple and readable. If you see any issues let me know.
If you do appreciate this code and are thinking about joining octopus, I'll leave my referral link here https://share.octopus.energy/rust-heron-863 - We both get £50 which is pretty spectacular.
Also if you're into home automation or random tinkering then subscribe to my youtube stuff here -> https://www.youtube.com/channel/UCl_uGYJe9KW9fJWBMq1A9kw