GithubHelp home page GithubHelp logo

jerbzz / pi-eco-indicator Goto Github PK

View Code? Open in Web Editor NEW
26.0 6.0 5.0 5.13 MB

Display at-a-glance data of carbon intensity or Octopus Agile prices on a Pimoroni Blinkt! display or a Pimoroni Inky pHAT display.

License: BSD 3-Clause "New" or "Revised" License

Python 93.67% Shell 6.33%
pimoroni-blinkt octopus-agile-prices octopus octopus-agile octopus-energy octopus-api agile octopus-energy-agile carbon-emissions carbon-intensity

pi-eco-indicator's Introduction

pi-eco-indicator

Display upcoming Octopus Agile prices (import or export), Tracker prices for electricity and gas, or carbon intensity from National Grid on the Pimoroni Blinkt! display or the Pimoroni Inky pHAT display for Raspberry Pi, with no external dependencies - data is fetched directly from public APIs and stored locally. Designed to be simple to set up and use for people with no coding knowledge. Other displays may be supported in the future.

Here's the Blinkt! display (in Agile mode for this example, but it reads the same for carbon mode or Agile mode. Tracker is currently not supported on Blinkt!). Read it from left to right. Each pixel represents between 1 and 12 half-hour slots (configurable), so you get from 4 to 48 hours of data depending on how you configure it! The leftmost pixel represents the current value. On the half hour, every half hour, the data is updated - the best way to think of this is that it all shifts half an hour to the left!

Magenta is the most expensive or most carbon intensive, then red, orange, yellow, green, cyan, and blue. You can change the thresholds and colours easily by editing a configuration file (config.yaml).

Blinkt! display in action

The Inky display looks like this in carbon mode, and very similar in Agile mode. On the right hand side are the values for the next three slots. Then, the bottom right corner shows the time at which the 3 hours (the duration of this is configurable) with the lowest price or carbon intensity occur, and the length of time until those slots begin. The graph is yellow/red when the value is above the configured "High Value" - the current value and border also change colour at or above this value. The black parts of the graph correspond to the low value slots shown in the bottom right. The dashed line is the average for the data being displayed, and the x-axis labels are the hour portion of the 24 hour time.

Inky pHAT display in action

Hardware needed

  • Pimoroni Blinkt!, or a Pimoroni Inky pHAT.
  • A Raspberry Pi of any flavour, as long as you can connect the display to it, and it can connect to the internet. This software has been tested on a Pi Zero W and a Pi 3B+.

Software needed

curl https://get.pimoroni.com/blinkt | bash

or

curl https://get.pimoroni.com/inky | bash

You can do both if desired! You will also need to install some other dependencies:

sudo apt install -y python3-yaml
sudo apt install -y python3-tzlocal
pip3 install font-roboto

How to get this code

Once you have installed the Pimoroni software as above, the easiest way to download this software is to copy and paste the following command, which will make a copy of all the files in a folder called pi-eco-indicator in your home directory. This won't work unless you've installed the Blinkt! library above (or installed git yourself).

cd ~ && git -c advice.detachedHead=false clone --depth 1 -b v2.5.0 https://github.com/jerbzz/pi-eco-indicator.git

How to use this code

This code runs unprivileged - no sudo required. It will drop a SQLite database file in its own directory when it runs.

The settings for the software are stored in config.yaml. This is provided as config.yaml.default so you will first need to make a copy:

cp config.yaml.default config.yaml

Open config.yaml:

cd ~\pi-eco-indicator
nano config.yaml

and look for DNORegion: Z at the very top. Replace this with your correct DNO region code from the list, or leave it as Z if you are looking for national carbon intensity values. (Note: I'm not a big fan of the regional carbon intensity data, I don't think it makes much sense, so I would encourage using national carbon data.) Exit nano by typing Ctrl-W then Ctrl-X.

You should initially run manually to check everything works

./store_data.py

The code will tell you what it's doing and whether it worked. You can run this as many times as you like without causing too many problems.

Then, a separate command to update the display:

./update_display.py

This will also tell you what it's doing. If you want to show a display of dummy data you can run:

./update_display.py --demo

If it's all a bit much, you can blank the display:

./clear_display.py

Running automatically

I really can't be bothered to make a systemd timer/service for this. cron is so much easier! I've included a script to install the cron jobs listed below. Run it like this:

./install_crontab.sh

You can check it's worked by running crontab -l, you should see something like this (for carbon mode, Agile or Tracker mode is a little different):

@reboot /bin/sleep 30; /usr/bin/python3 /home/pi/pi-eco-indicator/store_data.py > /home/pi/pi-eco-indicator/eco_indicator.log 2>&1
@reboot /bin/sleep 40; /usr/bin/python3 /home/pi/pi-eco-indicator/update_display.py > /home/pi/pi-eco-indicator/eco_indicator.log 2>&1
*/30 * * * * /bin/sleep 26; /usr/bin/python3 /home/pi/pi-eco-indicator/store_data.py > /home/pi/pi-eco-indicator/eco_indicator.log 2>&1
*/30 * * * * /bin/sleep 36; /usr/bin/python3 /home/pi/pi-eco-indicator/update_display.py > /home/pi/pi-eco-indicator/eco_indicator.log 2>&1
  • line 1: wait 30 seconds at startup, get new data
  • line 2: wait a further 10 seconds at startup and update the display
  • line 3: wait till a random number of seconds past every half hour and get latest carbon data
  • line 4: wait a further 10 seconds and update the display

Troubleshooting

If something isn't working, run

less ~/pi-eco-indicator/eco_indicator.log

This will show you the most recent message from any of the scripts (that were run automatically by cron). If this doesn't shed any light, run ./store_data.py and ./update_display.py and see what they moan about!

Modification

If you want to change price/carbon intensity thresholds, change mode, or fine-tune the colours, they are located in config.yaml. Open it using nano config.yaml or your favourite editor.

It's really important that you don't change the layout of the file otherwise you will encounter errors when trying to run the software. Each option has comments describing its effects - read, and change to your heart's content.

You can also create multiple config files, or store the config file in a different location, use the -c or --conf flag on the command line.

To Do:

See GitHub issues

Thanks to:

Garry Hayne on the Octopus Agile forums (https://forum.octopus.energy) for the original idea
pufferfish-tech's octopus-agile-pi-prices for inspiration (https://github.com/pufferfish-tech/octopus-agile-pi-prices)

pi-eco-indicator's People

Contributors

jerbzz avatar joeboyc2 avatar sidewinder42 avatar stickler-ci avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pi-eco-indicator's Issues

Display Agile Export prices.

As above - support Agile Export as an additional mode. Perhaps add a new configuration option for agile_price mode which is either "import" or "export".

update_display.py fails to run when mode is changed in config file and new data is not fetched

To Reproduce
Set mode to carbon, store data and update display
Then set mode to agile, and update display
Error occurs

Expected behaviour
The missing data should be handled gracefully, perhaps with a reminder to store data first

*Error

Traceback (most recent call last):
  File "/home/pi/pi-eco-indicator/./update_display.py", line 67, in <module>
    eco_indicator.update_inky(config, data_rows, args.demo)
  File "/home/pi/pi-eco-indicator/eco_indicator.py", line 261, in update_inky
    high_slots_start_idx = high_slots_list.index(max(high_slots_list))
ValueError: max() arg is an empty sequence

`os.chdir` fails when script invoked as `python x` rather than `./x`

Hi,

Firstly, great software and instructions !

I am running a Pi Zero with Inky pHat
Along with 32bit Buster with no desktop

I have only followed your instructions and not installed anything else.

After about 24 hours of usage I notice that the graphics for the graph start to not show from right to left as the day goes on?

Also if I restart the Pi, the graph doesnt come back, as though it remembers that it wasnt there!

I have fully reinstalled the system and started from scratch but the same has happened again.

Any idea on what could be wrong?

Thanks in advance

How to Test without a screen

Is your feature request related to a problem? Please describe.
Wonderful project, I'm just trying to add my own tariff FLUX-IMPORT-23-02-14/ but trying to do it on a RPi Zero is soo slow, so would like to know the best way to just test this without the Inky pHat dependencies on my host machine. As I'm having issues adding the tarrif getting

Connected to database...
Inky pHAT display selected.
Standard display orientation.
Working in Octopus Agile import mode.
Agile version set: 40p cap Flux)
Detected Black pHAT (SSD1608)
Traceback (most recent call last):
  File "/home/pi/pi-eco-indicator/./update_display.py", line 67, in <module>
    eco_indicator.update_inky(config, data_rows, args.demo)
  File "/home/pi/pi-eco-indicator/eco_indicator.py", line 372, in update_inky
    high_slots_start_idx = high_slots_list.index(max(high_slots_list))
ValueError: max() arg is an empty sequence

Describe the solution you'd like
Option to have the output as the Inky, Blinkt or terminal ( for development )

Describe alternatives you've considered
I'm trying to work through it and have forked your repo here https://github.com/GraemeDBlue/pi-eco-indicator but if I can would like to contribute back to this repo.

Additional context
Great little project got me up and running in no time, fantastic docs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.