Home Energy Monitoring

This article documents my energy monitoring site at http://solar.cae.me.uk.

Energy Monitoring microsite screenshot
Energy Monitoring Screenshot

In 2011 I had 4kW of solar panels fitted to a house I was moving into, and supplied with them was an inverter that was reachable via Bluetooth for configuration and querying. Clearly this data needed graphing so I had a long-term record of my power generation.

My first incarnation simply revolved around smatool which dumped all the data it could read from my inverter into a MySQL database at regular intervals. I do a little post-processing in Ruby to create summary tables of daily/monthly/yearly data.

All that was left was to knock up a Padrino microsite to display this data (screenshot on the right). The graphs are generated with Flot and the layout is based on Semantic-UI with bits of my own CSS.
There’s also quite a bit of Javascript to produce realtime displays in the header (the Ruby backend translates multicast from the ESP8266 into an event-stream, supported by all modern browsers).

At some point I migrated from Padrino over to Roda – I felt Padrino was stagnating and I didn’t need most of what the framework offered anyway. Roda is much leaner – more of a toolkit than a framework – and is more actively developed (I’ve made occasional contributions myself).

Adding Consumption & Export Data

As you can see on the website/screenshot, in 2015 I added Consumption data to my graphs.

Initially this was achieved with an electricity meter monitor that watched the spinning disc (very old style meter!) and counted revolutions. This device presents the number of revolutions counted in a JSON structure over Ethernet, from which electricity used can be calculated. However, this can’t monitor exported electricity.

Energy Monitoring PCB
Energy Monitoring PCB

In 2015 I started tinkering with electronics and microcontrollers. I discovered the amazingly cheap ESP8266 microcontroller and designed a PCB around it to monitor two current clamps (one for solar generation input, and one for house consumption/export).

This was my first electronics project and I learnt quite a lot. I won’t get into it all here, but essentially there’s a pair of op-amps to normalise the clamp inputs to a DC voltage range, which are fed into an ADC chip, which the ESP8266 communicates with over SPI. Finally a little maths works out kWh used since the last reading. I give a lot of credit to the guides and references on openenergymonitor.org for getting me started with this. I had to adapt some of it to work with the ESP8266 rather than the Arduino they use (it runs on 3.3v, not 5v).

You can see my finished PCB on the right. The ESP8266 is top-right, along with serial header pins for debugging and initial programming. The ADC is in the centre, and the op-amps top-left. The button puts the microcontroller in programming mode if held down while power is applied. There’s a voltage regulator to convert 5v input (I generally use USB powerbricks) down to 3.3v for the ESP8266 and ICs. Along the bottom are connections to the sensors and relays. The hastily added large capacitor was to help stabilise some readings from the ADC. Excuse some of my shoddy soldering, it was the first I’d done since school!

The main selling point of the ESP8266 is that it has WiFi onboard, so it can broadcast all this observed energy data to the network – it multicasts it as JSON every few seconds. This replaces the previous smatool and disc-watching monitor with a clean unified solution, and allows realtime data display via Javascript in the browser.

The PCB can control a couple of relays in software too (for example, turn on if exporting, but not if consuming energy, and so on) though I don’t use that functionality yet – it scales much better to add more microcontrollers with their own relay boards and control those via the network. The ESP8266 is so cheap it’s a non-issue.

Future Development

The relays on the PCB can be controlled in software on the ESP8266. They can be switched for any combination of inputs – including reading data from the network as the ESP8266 is on the LAN like any other PC would be – so the sky really is the limit for decisions about when to turn the relays on.

The eventual aim is to store energy when it’s not otherwise being used (ie, when it would be exported). Plenty of other systems do this already, such as the Tesla Powerwall. The main problem is it’s quite expensive to store energy because most batteries actually expire as you use them – they have limited charge cycles. At this point it is not economically viable for me to maintain the batteries; it’s cheaper to just buy the electricity.

[tags: electronics, project, ruby, webapp]