Whole Home Energy Monitoring based on PZEM-004T V3
Building a whole home energy monitoring system based on the PZEM-004T V3 single phase AC power monitoring module and an ESP8266 microcontroller running ESPHome.
Peacefair PZEM-004T V3#
The PZEM-004T V3 is a single phase AC power monitoring module that supports measurement of 80-260 V voltage, 100 A max current, power, energy, frequency and power factor (datasheet ↗ [Archive] ↗), it talks Modbus protocol on RS-485 serial.
I bought one off AliExpress for a total of €8.17 with free shipping, including a noninvasive current measuring transformer sensor (which is usually called a CT clamp) for ease of installation:

Hardware#
The circuit is very simple. Since the PZEM uses a passive serial port thus requires an external +5 V supply, for convenience, I used a WeMos D1 mini module, which has a built-in USB 5 V to 3.3 V power supply circuit, instead of a bare ESP-12F.
An additional logic level shifter is required to convert the 5 V TTL of the PZEM to the 3.3 V accepted by the ESP.

As for the voltage probe, it can be made using a regular plug and plug into a wall socket; or directly connect a wire to a breaker inside the breaker box, along with the current probe.
Completed circuit board, PZEM and voltage probe (a regular plug):
The relay on the circuit board is prepared for unlocking the building door in a future project

Install the Current Probe#
⚡ DANGER! ELECTRICAL HAZARD ⚡
You probably need to extend the current probe’s cable first.
Remove the breaker box panel, find the main live or neutral wire (usually the thickest and connected to the main breaker), clamp the current probe on it:

Put back the panel and lead the probe cable out through a hole:

Connect the voltage and current probes to the PZEM module’s screw terminals respectively according to the instructions printed on its enclosure, then connect power to the ESP module and it’s done:

Software#
ESPHome configuration example:
substitutions:
device_name: 'Energy Meter'
esphome:
name: energy-meter
comment: 'PZEM-004T energy meter'
esp8266:
board: d1_mini
logger:
level: WARN
# baud_rate: 115200
wifi:
fast_connect: true
networks:
- ssid: !secret wifi_ssid
bssid: !secret wifi_bssid
password: !secret wifi_password
domain: !secret domain_name
api:
ota:
password: !secret ota_password
button:
# for hard restart
- platform: restart
id: restart_button
name: 'Restart ${device_name}'
entity_category: diagnostic
# for resetting total energy counter on PZEM
- platform: template
name: 'Reset PZEM-004T Total Energy Counter'
entity_category: diagnostic
on_press:
then:
- pzemac.reset_energy: pzemac_1
icon: mdi:numeric-0-circle-outline
status_led:
pin:
number: 2
inverted: true
uart: # enable a software UART
tx_pin: 5
rx_pin: 4
baud_rate: 9600
modbus: # enable Modbus hub
sensor:
- platform: pzemac
id: pzemac_1
address: 1 # specify the Modbus custom address when there are multiple PZEM connected
current:
name: 'Current'
accuracy_decimals: 3
voltage:
name: 'Voltage'
accuracy_decimals: 1
power:
name: 'Power'
accuracy_decimals: 1
energy:
name: 'Energy'
# convert to kWh
filters:
- multiply: 0.001
unit_of_measurement: 'kWh'
accuracy_decimals: 3
frequency:
name: 'Frequency'
accuracy_decimals: 1
power_factor:
name: 'Power Factor'
accuracy_decimals: 2
update_interval: 30syamlNow you can add it to Home Assistant and select sensor.energy as the Energy platform data source.

If you would like to add a glance card to your lovelace dashboard, configure two utility_meter sensors in YAML first:
energy_monthly:
source: sensor.energy
cycle: monthly
energy_daily:
source: sensor.energy
cycle: dailyyamlThen add a lovelace glance card:

type: glance
title: Energy Consumption
show_icon: true
show_state: true
state_color: false
entities:
- entity: sensor.power
- entity: sensor.energy_daily
name: Daily
- entity: sensor.energy_monthly
name: Monthlyyaml