Whole Home Energy Monitoring based on PZEM-004T V3
Peacefair PZEM-004T Version 3.0
The PZEM-004T V3 is a single phase AC power monitoring module that supports measurement of 80-260 V voltage, 100 A max current, frequency and power factor (datasheet), 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 +5V supply, for convenience, a WeMos D1 mini module which has a built-in USB 5V to 3.3V power supply circuit was chosen, instead of a bare ESP-12F.
An additional logic level shifter is required to convert the 5V TTL of the PZEM to the 3.3V accepted by the ESP.
Completed circuit board, PZEM and voltage probe (just a standard plug):
The relay on the circuit board is prepared for controlling the building gate 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 panel, find the main live or neutral wire (usually the thickest, and goes into the main breaker), clamp the current probe on it:
Put back the panel and lead the probe cable out from a hole:
Connect the voltage and current probes to the PZEM module respectively according to the instructions printed on its enclosure, then connect power to the ESP module and it's done:
Software
Example ESPHome configuration:
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
api:
ota:
password: !secret ota_password
uart: # enable a software UART
tx_pin: 5
rx_pin: 4
baud_rate: 9600
modbus: # enable Modbus
sensor:
- platform: pzemac
address: 1 # specify the PZEM Modbus custom address, this is useful when there is multiple PZEM connected
current:
name: 'Current'
voltage:
name: 'Voltage'
energy:
name: 'Energy'
# convert it to kWh
filters:
- multiply: 0.001
unit_of_measurement: 'kWh'
accuracy_decimals: 3
power:
name: 'Power'
frequency:
name: 'Frequency'
power_factor:
name: 'Power Factor'
update_interval: 30s
Now you can add it to HASS 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 first:
energy_monthly:
source: sensor.energy
cycle: monthly
energy_daily:
source: sensor.energy
cycle: daily
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: Monthly
4 Comments
Gemul · 2022-05-22 at 16:56
Hi, just want to let you know that the rx/tx wiring in diagram and the given code is not correct. the code says TX is GPIO4, which is D2, and in diagram, D2 is connected to the TX pin (next to GND) of the PZEM. TX should be connected to RX and vice versa.
zry98 · 2022-07-02 at 03:15
Thanks for pointing that out! Fixed in the yaml.
Josip · 2022-12-07 at 15:27
Which program is installed on esp8266?
zry98 · 2022-12-08 at 14:19
ESPHome.