Reading the meter with forty lines of code
A clamp on the meter tail, a small board and a short script give me the house's electricity use every ten seconds. Here is all of it, and what the first week showed.

The smart meter’s display gives you a number. I wanted the shape of a day — when the heat pump runs, how long the defrost cycles last, what the house uses at 3 a.m. — and I wanted it in a file I could open.
The parts
A current transformer clamps round the live tail between the meter and the consumer unit, without touching anything live. It gives a small voltage in proportion to the current, which a cheap analogue-to-digital board turns into numbers a small computer can read.
The script
This is the whole thing. It reads the sensor, works out the power, and appends a line to today’s file.
import csv, math, time
from datetime import datetime
from sensor import read_samples # the board's own library
VOLTS = 240 # close enough for a house
RATIO = 100 / 0.05 # 100 A clamp, 50 mA out
BURDEN = 33 # ohms, on the board
def power_watts():
samples = read_samples(count=2000) # one mains cycle, many times over
rms = math.sqrt(sum(s * s for s in samples) / len(samples))
amps = rms / BURDEN * RATIO
return round(amps * VOLTS)
while True:
now = datetime.now()
with open(f"power-{now:%Y-%m-%d}.csv", "a", newline="") as file:
csv.writer(file).writerow([now.isoformat(timespec="seconds"), power_watts()])
time.sleep(10)
It runs as a service so it starts again after a power cut:
[Unit]
Description=Log household power every ten seconds
[Service]
ExecStart=/usr/bin/python3 /home/pi/meter.py
WorkingDirectory=/home/pi/readings
Restart=always
[Install]
WantedBy=multi-user.target
Real power needs the voltage measured too, and the angle between voltage and current; this measures apparent power, which reads a little high for the heat pump’s motor. For seeing the shape of a day it is plenty.
What a day looks like
The first week showed two things I didn’t know. The heat pump defrosts its outdoor coil for about four minutes every hour when it’s near freezing and damp, which shows as a dip and then a spike. And a dehumidifier in the spare room had been running all day, every day, since the wood-fibre job: 300 watts I’d forgotten about.
