CSR Labs - High Availability with home hardware

DIY ZigBee Energy Monitor based on PZEM-004T

Mains Power Warning Sign

SAFETY FIRST!

This project requires you to deal with mains voltage, which is extremely dangerous and can cause severe injuries and even death.

Connecting this equipment to your home electrical wiring might void its certification, and your insurance can and will refuse to pay if something bad happens.

If you believe you lack the necessary skills and knowledge, I strongly advise you to hire a professional electrician and DO NOT ATTEMPT IT YOURSELF!

I take no responsibility. You have been warned!

 

The PZEM-004T module

PZEM-004T v3 module

The PZEM-004T is a module designed for measuring voltage, current, power, energy and frequency in AC electrical systems. It can communicate with a microcontroller or computer via RS485 or UART interface and it can also be connected to a power meter.
The module can be used to monitor the power consumption of appliances and other electrical devices, and can also be used to measure the performance of solar panels and other renewable energy systems. It is widely used in smart home, industrial control, power metering and other fields.

The PZEM-004T module can be integrated with Home Assistant, an open-source home automation platform, to monitor and control the electrical devices in your home.
You will also have the ability to create custom dashboards and graphs in Home Assistant, to visualize the data in a more user-friendly way. This module can be a great addition to any smart home setup, as it allows you to have a better understanding of your energy usage, and make changes to reduce costs, increase efficiency and monitor the energy consumption of your devices.

 

PZEM-004T Energy Monitor with DIN rail enclosure

PZEM-004T DIN rail box

In this project, I built a wireless energy monitor system designed around a Texas Instruments CC2652RB ZigBee module running the PTVO custom firmware. It has been running for more than a year in my home and has proven to be very reliable and accurate. I got practically the exact same energy consumption reading as was in my electricity bill.

ZigBee module PCB

The printed circuit board has been designed with KiCad and manufactured by PCBWay, and is available for ordering in their Shared Projects area.

Download gerber files here.

 

Wiring Connection

PZEM-004T mains wires soldering

The 230V power supply of the ZigBee module can be taken from the PZEM-004T PCB.
To connect 230V mains wires, scrape off the solder mask to expose copper, then tin the cleaned area and solder the first wire for mains voltage. The second wire must be soldered to the yellow capacitor pin as shown in the picture above.
These wires must then be connected to the ZigBee module according to the schematic.

Download schematic PDF

Modules wiring connection

 

PTVO firmware and custom ZHA Quirk

I use this energy monitor with Home Assistant ZHA. In order for a custom ZigBee device to be correctly integrated into Home Assistant, a sort of device driver has to be loaded. In the Home Assistant project, this driver is called ZHA Device Handler or Quirk.

I developed a custom Quirk for this project that can be downloaded from my GitHub repository.

Please notice that Home Assistant detects any custom ZigBee device based on its "signature" which means that the device has to be configured exactly as shown here below.

PTVO gui

PTVO gui

Any change to this configuration will make the device different from what Home Assistant expects, therefore it will not be loaded and the related entities will not be created.

In addition, from time to time, PTVO devs make changes to their firmware adding or changing the ZigBee attributes that are sent to the coordinator.
Even these small changes prevent the device from being properly detected by Home Assistant.
I will try to update the Quirk when the PTVO firmware gets updated, but for convenience I provide a compiled firmware that proved to work well with my device.
This firmware is based on PTVO executable version 1.8.0.8 - 2023-02-07.

Download Firmware hex file for CC2652RB

In this article I explain how to load the firmware to the CC2652RB module using the Texas Instruments XDS110 JTAG emulator.

Here is how the finished project enclosure looks like.

pzem-004t din rail enclosure

 

Pairing with Home Assistant

A long press of the pushbutton makes the device in pairing mode so that it can be detected by Home Assistant ZHA as shown below.

Home Assistant ZHA pairing

Once the device has been paired all the entities are available in Home Assistant and in the Energy Dashboard.

Home Assistant entities

Home Assistant energy dashboard

 

Parts used

   
Buy this item on AliExpress     Buy this item on AliExpress
EBYTE E72-2G4M05S1F  
   
Buy this item on AliExpress     Buy this item on AliExpress
Hi-Link HLK-PM03  
   
Buy this item on AliExpress     Buy this item on AliExpress
PZEM-004T module  

 

 

Support this blog


Please consider making a donation if you liked my blog and found it useful for your project.
It will support me in producing fresh articles and conducting more hardware testing.

PcbWay partnership program

Social

  1. GitHub
  2. Twitter