Those that know me, will vouch that I am a big lover of fancy dashboards, metrics and monitoring. I recently became a customer of Octopus Energy after a situation with Yorkshire Energy, and Scottish Power left a bad taste in my mouth (and wallet)
One of the things I really like about Octopus is that they allow you (the customer) to access an API to be able to pull pricing data and also your own consumption for both gas and electricity.
the API itself is pretty simple, a REST API with a couple of endpoints you can pass params into in order to get your data, however does come with some gotcha’s that I will dig into shortly.
In order for this to work, you need to have a SMETS1 or SMETS2 enabled smart meter that Octopus are taking readings from, it took them about a month if I remember correctly to get mine migrated over and them taking readings from it, basically if you can’t see half-hourly usage stats in the Octopus dashboard itself, then this won’t work for you sadly.
The full git repository containing the code can be found here
The code itself should be pretty clear to most how it works, and the README will explain how to run it for those who just want an out of the box solution that works. This blog post steps into the detail of how to get your InfluxDB ready and the grafana configuration done.
At some point in the future I will package this up so it can be run as a standalone binary, but that is a problem for future me.
Getting InfluxDB configured
There are a million and one posts out there already that show how to install and get InfluxDB started. As such I won’t repeat here but I will show how to create a new token and bucket in prep for the metrics to be inserted. This will ONLY work with InfluxDB 2.0 onwards, not that there are many folk on 1.X these days
You can run Influx in docker or standalone, it makes no difference here, I’m personally running it on docker swarm, with haproxy in front of it running the SSL termination, but I like to go OTT.
Log into the web interface of your Influx Server
Select Data, then buckets, then click Create bucket;
then set your bucket name, InfluxDB will allow hyphens (-) but this will cause havoc in node.js. I stuck to a simple octopus; for my bucket name, you can also set a retention period here if you wish to keep on top of disk usage. as this is quite small amounts of text data I opted to go for no retention, but your circumstances may differ
Once you have done this, head back to the main Data; menu and select the node.js option
click the button at the top that says Generate Token; and then select Read / Write Token;
Enter a description, select your bucket etc and then click save.
You can then click the token in the list, copy the value and set that on the container / code.
Building and running the code
If running with docker, you can simply build the docker image with:
docker build -t repo/octopus-energy-metrics:latest .
You can then launch the container with compose, an example below:
if running manually, you will need to install the dependencies:
create a .env file with your settings in (similar to above for docker) and then to run:
npm run start
Creating the Grafana dashboard
Again this is pretty well documented,
Create an empty dashboard with your InfluxDB as the data source, then create your panels and graphs as desired, I reccomend using the InfluxDB Query builder in the InfluxDB web interface
With a bit of tinkering you can have something like this: