Home Monitoring with eMonTX, ESP8266, OpenHAB and Friends

Several people have now asked me what I’m doing for home energy monitoring and suchlike, so this is a summary for anyone interested in pursuing their own experiments.

Energy Monitoring

At first glance, getting a “smart meter” seemed like a good idea. Turns out though that the whole implementation seems to have been designed by morons, so even without wearing a tinfoil hat there are several problems¹ :

  • Staggeringly, these meters seem to have been rolled out without a thought to compatibility between suppliers! So change supplier — meter might become ‘dumb’ again.

Dumb Meters

I have a grand total of 3 electric meters (supply, solar PV, domestic), and one gas meter. Each of the electric meters, being ‘relatively’ modern, have an LED that emits a pulse for every Wh consumed. Perversely, they state “1000 imp / kWh” just in case you had no idea what a Wh was.

One of these? You’re in luck

eMonTX

Power can be measured — with a margin of accuracy — with a current clamp. There are several different ways to go with this, but IMO the superior option is eMonTX.

Glue : ESP8266, MQTT

For the uninitiated, the ESP8266 is a module with bundled CPU (quite powerful), flash, WiFi — and plenty of I/O pins, a usable toolchain for both C, Ardunio and LUA.

ESP8266; ESP-12E board

Nodes

I currently have 3x ESP nodes

Optical Sensors
  • Boiler. I have two zones on my system, this ESP monitors which are on/off (the zone valve power triggers a relay), and also measures the temperature of the feeds and return (though this is a bit approximate since it’s just some DS18B20s strapped to the copper).

Charts And Graphs To Back Us Up

In addition, I also have other systems (Evohome heating, various ‘smart bulb’ lights, sonoff switches, LED light controllers, Solar Inverter) that I want to integrate into a central system. For just pulse monitoring, you could probably wire MQTT directly into a graphing stack, but I wanted something more of an “integration engine”. My first approach was to do the obvious thing — write a script. But then I had a play with OpenHAB.

import org.openhab.core.library.types.*
import java.util.Date
var long LastUpdateHouse = 0rule "House Meter"
when
Item CurrentHouse changed
then
// power = current watts in use
var Number power = CurrentHouse.state as DecimalType
var Number energyTotal = 0
var Number energyToday = 0
try {
energyTotal = MeterHouse.state as DecimalType
} catch(Exception ex) {
}try {
energyToday = MeterHouseToday.state as DecimalType
} catch(Exception ex) {
}var long currentTime = now.millisif( LastUpdateHouse != 0 ) {
var long timeElapsed = currentTime - LastUpdateHouse
if( timeElapsed > 0 ) {
var Number energyUsed = (power * timeElapsed) / 3600000
postUpdate(MeterHouse, energyTotal + energyUsed)
postUpdate(MeterHouseToday, energyToday + energyUsed)
postUpdate(MeterHouseUse, energyUsed)
}
}
LastUpdateHouse = currentTimeend

Charts!

So the standard OpenHAB UIs give you charts that look a bit like this:

Rocking 230V. Not.

Charts the better

Long story short: pump the OpenHAB data into prometheus, then view it with grafana.

Bring on the Fancy
Meters meters meters

Analytics

This is where having control over your own data really shines. Here’s 24hrs in the life of our heating:

Heating

I don't exist when you don't see me.