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
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
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.
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.
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.
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.
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 184.108.40.206 - 2023-02-07.
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.
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.
Once the device has been paired all the entities are available in Home Assistant and in the Energy Dashboard.