Zry.IO

Back

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:

pzem

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.

schematic

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

overview

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:

ct-clamp-installed

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

breaker-box

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:

done

Software#

ESPHome configuration example:

Now you can add it to Home Assistant and select sensor.energy as the Energy platform data source.

hass-energy

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: daily
yaml

Then add a lovelace glance card:

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
yaml
Whole Home Energy Monitoring based on PZEM-004T V3
https://zry.io/smart-home/whole-home-energy-monitoring-based-on-pzem-004t-v3/
Author zry98
Published at February 9, 2022
Copyright CC BY-NC-SA 4.0
  1. sanjay

    Is it required to use level shifter ic - like this https://robu.in/product/level-converter-4-channel/

    1. zry98

      Yes, I used an exact same one as you linked

  2. Josip

    Which program is installed on esp8266?

  3. Gemul

    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.

    1. zry98

      Thanks for pointing that out! Fixed in the yaml.