Six Bucks and a Phototransistor: The Energy Monitor Already Bolted to Your Wall
Photo: CTIO/NOIRLab/NSF/AURA, CC BY 4.0, via Wikimedia Commons
The most accurate energy meter in your house is the one you are not allowed to open. It is revenue-grade, utility-maintained, and already bolted to the wall. The good news: many US residential meters blink an infrared LED for every unit of energy that passes through them. That blink is a sensor output. You just need to read it without touching anything metallic.
I am not going to pretend this is a utility-sanctioned integration. It is an optical tap. You are counting flashes through the meter cover. No CT clamps, no panel work, no waiting for a utility API that may never arrive. The tradeoff is resolution and legality in your jurisdiction. Check your utility rules before you tape anything to the meter. Some utilities are fine with a removable sensor; some are not. Never remove the cover, never drill, and never put anything near the terminals.
What the meter is actually telling you
Electronic meters from Itron, Landis+Gyr, and others often have a pulse LED labeled with a constant. You may see '1 kWh = 1000 imp' or 'Kh 1.0' or '10,000 imp/kWh.' The label is the whole game. If the meter says 1,000 impulses per kilowatt-hour, each flash is one watt-hour. If it says 10,000, each flash is 0.1 watt-hour. Multiply flashes by watt-hours per flash and you have energy. Divide by time and you have power.
Some meters use a visible red LED; many use infrared. Your phone camera can often see IR as a purple-ish flicker. If you see nothing, try another camera or an IR-sensitive phototransistor. Do not assume every meter has a simple blink. Some commercial meters use optical protocols, and some residential units have no accessible pulse output. If yours does not blink, stop here.
The six-dollar sensor stack
The build is almost insultingly simple: an ESP32 dev board, an IR phototransistor, a 10k resistor, a short length of black heat-shrink tube, and a way to hold the sensor against the meter glass. A purpose-built phototransistor is easier than an optocoupler. An optocoupler is designed to isolate two circuits, not to be a light sensor. If you already have one, you can sometimes use the phototransistor side, but a TEPT4400-style part or a 940nm phototransistor is the right tool. The 'optocoupler' in the title is really about isolation mindset: the meter stays sealed, and your electronics stay on the outside.
Wire the phototransistor as a simple switch. Collector to 3.3V, emitter to a GPIO pin and to ground through a 10k resistor. When the meter LED flashes, the transistor conducts and the GPIO sees a pulse. Use a falling-edge interrupt if you wire it the other way, or just use a pull-up and count active-low pulses. Add a 100nF capacitor across the GPIO to ground if you have long wires and noisy LED drivers nearby.
Mounting is where most builds fail. Ambient light, reflections, and vibration will create phantom counts. Cut a black foam gasket or a 3D-printed shade so the phototransistor only sees the meter LED. Tape it with removable painter's tape, not duct tape. Aim the sensor at the LED, not at the LCD. If the meter glass is dirty, wipe it with a dry microfiber cloth before mounting. Recheck alignment after a day; heat and gravity move things.
Firmware that counts without lying
The firmware has one job: count pulses accurately, then turn counts into energy and power. Use a hardware interrupt, not a polling loop. Debounce in software with a 30-50ms lockout. Meter pulses are slow enough that a simple millis() guard is fine.
Pseudo-code:
volatile uint32_t pulses = 0;
void IRAM_ATTR onPulse() { pulses++; }
...
attachInterrupt(digitalPinToInterrupt(PULSE_PIN), onPulse, FALLING);
...
uint32_t now = pulses;
uint32_t delta = now - lastPulses;
float wh = delta * WH_PER_PULSE;
float watts = wh * 3600.0 / intervalSeconds;
lastPulses = now;
Set WH_PER_PULSE from the meter label. For 1,000 imp/kWh, it is 1.0. For 10,000, it is 0.1. Publish watts and a cumulative energy total to MQTT. If you use ESPHome, the pulse_meter component can do much of this, but check that its filters do not smooth away real load changes. You want the raw count for calibration.
Calibration against the meter constant
The label is a promise, but calibration is proof. Pick a time when the house is quiet. Turn on a known load, like a 1,500W space heater, for 10 minutes. Count pulses and compare to expected energy. If the heater draws 1,500W for 10 minutes, that is 250Wh. At 1Wh per pulse, you should see about 250 pulses. If you see 230 or 270, your sensor is missing pulses or counting noise. Fix the mounting before you fix the math.
For a slower, more accurate check, compare your cumulative total to the meter's own kWh display over a week. Many meters show only one decimal, so give it time. Do not adjust WH_PER_PULSE to hide bad counting. That is how you get a dashboard that is confidently wrong.
Feed it into a local dashboard
I send pulses over MQTT to a local broker, then into InfluxDB and Grafana. Home Assistant works too. The point is to keep the data local. You are already avoiding the utility API; do not hand the same data to a cloud dashboard for free. A simple graph of whole-home watts, plus a daily kWh total, is enough to spot the water heater, the dryer, and the mystery load that runs at 3 a.m.
The meter is not a lab instrument, and this build will not replace a revenue-grade CT system. But it is the cheapest whole-home energy sensor you will ever install. It is already on the wall. You just have to listen to it blink.