Building a DIY Energy Monitor with a Raspberry Pi

Rob Hammond
5 min readSep 22, 2022

--

Incorrect data from our IHD (left) vs DIY homeAnalytics data (right)

Read instructions on how to set up your own energy monitor here

Background

Until January this year, electricity costs haven’t really been something I’ve paid much attention to.

However after installing a heat pump last year, and switching to an EV for our main family car in December 2021, the monthly bill for January hit over £500, which was a bit of a shock.

Receiving the bill, one other thing that hit me was just how opaque electricity bills still are in 2022.

The detail I got from Ecotricity was woeful — the raw number of kWh used, the cost, and a crude year-on-year comparison (useless as I hadn’t been with them 12 months):

Ecotricity bill detail leaves a lot to be desired

I wanted a better way to break this down and see what was driving the increased costs.

Existing Smart Meter Device

Our ‘smart’ meter device was supplied a few years ago, and shows real-time information on kWh consumed. But that’s about it —the device itself (a Chameleon IHD7) stinks — the tariff data doesn’t update if you switch suppliers (and there’s no over-ride option), doesn’t support peak/off-peak tariffs, has a horrible resistive touch screen and poor visuals.

A Chameleon IHD7 — a device straight out of the 1990s

Making a better Energy Monitor

Finding a data source for our electricity consumption was a long slog — Ecotricity have no API, but after a lot of Googling I found the Loop Energy app, which gave me access to almost a year’s worth of half-hourly usage data.

Loop had a couple of key issues though — they didn’t support custom tariff data, so their cost information was wrong, and they don’t offer an API, so getting that information programmatically was a problem.

I kept searching and eventually I found that every smart meter sends its data to an obscure data processing company called n3rgy. This is where Loop get their data from, and n3rgy offer a free (largely undocumented) API, with half-hourly usage data going back 90 days. It’s not real-time but does offer data with only a few hours lag.

Breaking down usage data

The next step was splitting out the consumption into different categories.

We have a reasonable amount of smart devices in our house, but no way to pull all the data together, so I investigated a bunch of options such as HomeAssistant and HomeBridge, which are great, but didn’t offer the analytical approach I was after.

After playing around with MITMProxy and some Python packages though, I managed to get enough incoming data from other sources to make the idea of building something bespoke worthwhile.

Building the homeAnalytics Energy Monitor

With this in mind I started putting together a rough idea of a website for my local network that I could run on a Raspberry Pi and check in on occasionally.

Once I had a basic project up & running, it occurred to me I could probably build an In-Home Display (IHD) better than the Chameleon smart meter if I put a display directly on the Pi . I found a decent capacitive touch display for £40 at The Pi Hut.

After a good deal more hacking away, I now have an IHD that not only gives me an overview of my energy usage, but also shows a split of where that energy is going:

Breakdown of where energy is going shown on the home-brewed IHD (right)

Now the basics were in place I started exploring other useful smart home info it would be cool to see in my DIY IHD.

One thing I like about EVs is the ability to check if I have enough fuel to get me to a destination without opening up the car. But opening up an app is a pain, so an IHD is a perfect place to passively monitor state of charge.

This is especially useful now I’m on a variable rate tariff with Octopus Energy, so I can reduce the amount I have to charge on the peak rate.

At-a-glance state of charge info for EVs in homeAnalytics

Conclusion

The software behind the Pi display is homeAnalytics, and can be used entirely free of charge. It offers not just the Pi display, but also a Google Analytics-style web interface where you can do deeper analysis of your energy usage:

homeAnalytics web UI

I’ve hacked together a lot of stuff over the years, but building for a small, always-on, fixed-size screen was a new experience — there were some different rules to play by:

  1. Use black as the background colour — initially using white caused a good degree of glare in the evening coming from the cubby hole where the Pi is kept
  2. Information density must be very low — every time I wanted to add in a new metric, I ended up either cutting it down or removing it entirely
  3. Perfecting the layout can turn into a frustrating battle with available pixels vs CSS rules, but at least responsive layouts aren’t a concern
  4. Useful/interesting information needs to have a reasonable freshness — ie data that is only updated on a monthly basis becomes stale and uninteresting quickly

There are many more interesting things that can be done with the data being collected by the homeAnalytics project, and hopefully it can be part of a push to democratise energy usage data, increase energy efficiency and bring home energy reporting into the 21st century.

--

--

Rob Hammond
Rob Hammond

Written by Rob Hammond

PS Director, EMEA at BrightEdge. Technologist, SEO, renewable energy enthusiast