We get our electricity and gas from a company called Octopus. We were with the Co-op, but their operation got taken over. We just had 'smart' meters fitted by them, so they can take readings without me needing to do it. They also gave us a unit so we can see what we are using. It seems to have lost track of the gas price, so we can only see the units.
I then found out that they have a REST API that lets me extract data that they get from my meters. You need an API key to access it that I will not be giving out. I have been looking for projects to work on with Python and doing something with this data looked like a good one.
They supplied me with some curl commands that would fetch the data. From those I could see that it was JSON data and get some idea of the format. It was basically a header followed by a series of readings. There are other things you can access that I have not looked into yet.
I quite like using Jupyter Notebooks as they allow you to play with the code and instantly see the results. You just have to run it and it pops up in your browser. You can enter and run blocks of code.
I used the requests library to do the fetching. I did not want to expose my API key or meter IDs, so I have stored those in a config file, also using JSON. I created that file with a script, but it is easily edited as it is just text. The code for querying each meter was the same, so it was natural to create a function.
I had to convert the returned JSON data into a dictionary. One element of that was the results which was a list of dictionaries. Each item had a value and date/time. I used list comprehension to extract that into a couple of lists I could use to plot it.
Then it was just a matter of creating a plot. I used matplotlib, which I have used at work. It can create any sort of plot you want, but can be fiddly to get the exact look you want. I may need to look at some of the alternatives.
This is what I got. It seems you get the latest three days, but there may be ways to get more. It shows that we use just about all the gas in a couple of blocks in the morning and evening. Electricity is more variable. The big spikes are likely to be from our electric oven, washing machine and dishwasher. The tumble-dryer may also have been on. Some of the family are around during the day, or consumption would be lower. Computers, TVs and consoles will consume a fair bit between them.
I will have to see what else I can do with the data. I am not sure it will reduce our usage much as we are already fairly careful. The advertising for smart meters says they can save you money, but only if they make you aware of wastage. I would quite like to have a display panel on a wall that I could use to display things like this, but it has to be family friendly. A Raspberry Pi could run the software quite easily.
I have put the code on Github in case you want a closer look. As it stands it will only be of direct use to other Octopus customers or if your supplier uses a very similar API.
Happy coding!