← Projects
electronics intermediate 1 days ago ◯ 4 min read

Build a Plug-In AC Energy Monitor with ESP32 and a PZEM-004T

Build time: 2-3 hours
Tools needed: Wire strippers, screwdriver set, soldering iron (for header pins if not pre-populated), multimeter, non-contact voltage tester
Parts List
esp32pzem-004tenergy monitoringhome assistantpower meterelectronics project

This site already has a whole-house energy monitor built with CT clamps around the main panel. This is the smaller, more targeted version: a single outlet-level power meter you plug a tool or appliance into and get real voltage, current, power, energy-over-time, power factor, and frequency readings from, reported to Home Assistant over WiFi. It's the right tool for answering "how much does my laser actually draw at idle vs. cutting," "is this old shop fridge worth replacing," or "which 3D printer in the farm is the power hog" — questions a whole-panel monitor can't answer on its own.

How It Works

The PZEM-004T is a small AC metering module built around a dedicated energy-metering IC with an integrated current transformer rated for up to 100A, isolated from its logic-side UART output. The module itself handles the dangerous part — it sits in-line with mains voltage and current — and talks to your ESP32 over a simple isolated serial connection at 5V logic (translated to 3.3V for the ESP32's UART), reporting voltage, current, active power, energy accumulated, frequency, and power factor as register values you poll over Modbus-RTU-like serial commands.

Parts List

Wiring

The PZEM-004T's CT clamp is a split-core design on most versions, meaning it opens and closes around a single conductor — clamp it around just the hot (line) conductor feeding your outlet, never both hot and neutral together, or it will read near zero. The module's mains terminals connect to line and neutral directly (this module is designed to carry the full load current through its terminals, unlike a low-power sensor), and its 5V/TX/RX/GND header goes to the ESP32: 5V to the module's logic supply, TX/RX crossed to the ESP32's UART2 pins, and GND common.

Build this as two physically separate enclosures connected by a short low-voltage cable: a mains-rated box containing the outlet, the PZEM module, and all mains wiring, and a separate small plastic enclosure for the bare ESP32 board and its own USB power supply. Do not share a single enclosure unless you're confident in your mains isolation and have proper strain relief and clearance between mains and logic-side wiring — the PZEM module's logic header is isolated internally, but good practice is still to keep physical separation generous.

Firmware

ESPHome has a built-in pzemac platform component specifically for this module — point it at the correct UART pins and baud rate (9600 by default) and it exposes voltage, current, power, energy, frequency, and power factor as sensors automatically, no custom code required. Add a WiFi and API block as with any other ESPHome device, flash it, and it shows up in Home Assistant with all six values live within a minute of boot. From there, a simple Home Assistant automation can log daily energy totals per outlet, or alert you if a tool is pulling power while you thought it was off.

Safety

Once you've got one built, it's cheap enough in parts cost to build two or three and rotate them around the shop — one on the laser, one on the air compressor, one on whatever you're currently trying to diagnose — rather than committing to a single permanent installation.