Most utility meters have a small red LED on the front that pulses once for every watt-hour consumed — a standard called the “pulse output” or S0 port. By pointing a photoresistor at that LED (or wiring directly to an exposed S0 terminal), an ESP board can count pulses and translate them into real-time watts and cumulative kilowatt-hours without touching any mains wiring. This recipe walks through the hardware, the ESPHome configuration, and the calibration steps to get accurate readings in Home Assistant.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/esphome/esphome.io/llms.txt
Use this file to discover all available pages before exploring further.
This recipe is non-invasive: the photoresistor approach requires no
contact with mains electricity whatsoever. If you use the S0 terminal
variant, those terminals are also low-voltage dry contacts — still perfectly
safe. Never open your main distribution board or touch live conductors unless
you are a qualified electrician. If in doubt, call one.
Hardware needed
| Component | Notes |
|---|---|
| ESP8266 or ESP32 board | Any board with a free digital GPIO |
| Photoresistor (LDR) | Match the wavelength to your meter’s LED (~630 nm red) |
| 10 kΩ resistor | Forms a voltage divider with the LDR |
| Small piece of black foam or tape | Shields the LDR from ambient light |
| Dupont wires | Short runs only |
Wiring — photoresistor voltage divider
Wiring — S0 port (alternative)
Some meters expose an S0 terminal directly. Wire it as follows:The S0 port is a dry-contact switch. When the meter fires a pulse the
contact closes, pulling the GPIO low through the resistor. Use
inverted: true in the GPIO pin configuration to account for this active-low logic.Complete YAML configuration
Configuration walk-through
Identify your meter's impulse constant
The impulse constant is printed on the front of your utility meter —
look for a label like 1000 imp/kWh or 10000 imp/kWh. This number
tells you how many LED pulses equal one kilowatt-hour.
Calculate the multiply factor
The Examples:
pulse_meter sensor reports in pulses per minute. To convert to
watts, use:- 1000 imp/kWh → factor =
60 - 10000 imp/kWh → factor =
6
multiply value under filters.Set the total energy multiply factor
The
total sub-sensor counts raw pulses. Divide by the impulse constant
to convert to kWh:- 1000 imp/kWh →
multiply: 0.001 - 10000 imp/kWh →
multiply: 0.0001
Tune internal_filter for your meter
If you see missed pulses at high load, increase
internal_filter. To
find the right value, divide one second by the maximum pulse rate your
meter can produce at its rated load limit, then subtract a small margin.
For example, a 16 kW meter at 10000 imp/kWh produces ≈ 44 pulses/sec,
so the minimum pulse width is ≈ 22 ms — set internal_filter: 20ms.Throttle updates to Home Assistant
High-load situations can produce sub-second pulses. The
throttle_average: 10s filter groups pulses into 10-second windows and sends an averaged
watt value, which is easier for Home Assistant’s history to handle.
Increase this interval if you see performance issues.Reset the kWh total
The
set_total API action lets you align the ESPHome cumulative total
with what your utility meter shows. In Home Assistant, call the
esphome.power_meter_set_total service with new_total set to the
raw pulse count you want to restore (not a kWh value — the pulse count is what
pulse_meter tracks internally; multiply your kWh reading by the impulse constant to convert).Tracking daily energy
Thetotal_daily_energy sensor resets automatically at midnight (using the time component) and accumulates kWh throughout the day. Unlike Home Assistant’s Riemann-sum integration helper, this runs on the device itself, so it continues to work through HA restarts and updates.