Python Interface to PZEM AC/DC Power / Energy Monitoring Modules
Copyright(C) 2021, BrucesHobbies, All Rights Reserved
PZEM.py provides a Python scripting interface to the Peacefair PZEM AC and DC energy / power monitoring modules. The module measures the following:
- voltage (V)
- amperage (A)
- power (W-Hr)
- freq (Hz)
- power factor
- state
Consult an electrician for your local electrical codes. Also refer to the documentation that comes with the PZEM module. For devices powered off alternating house current, either 120 or 240 volt, the PZEM uses a split transformer to measure current through a wire. It is snapped around the neutral wire to sense the current flow. The module also requires connection to hot and neutral to measure the voltage being provided to the device. For Direct Current devices there is the PZEM-017 module.
As an Amazon Associate I earn a small commission from qualifying purchases. It does not in any way change the prices on Amazon. I appreciate your support, if you purchase using the links below.
For Alternating Current (AC) devices
- One of the following AC power PZEM-016 modules - may have different shipping times
For Direct Current (DC) devices
-
One of the following DC power PZEM-017 modules - may have different shipping times
-
2-conductor low voltage wire as needed (RS-485 connection from PZEM module to USB dongle)
- Raspberry Pi (any of the following)
- Power adapter for your Raspberry Pi
- Heatsinks (optional)
- SD-Card
Here are the instructions to install the Raspberry Pi Operating System. Raspberry Software Install Procedure
Before continuing make sure your operating system has been updated with the latest updates.
sudo apt-get update
sudo apt-get full-upgrade
sudo reboot now
To get a copy of the source files type in the following git command assuming you have already installed git:
git clone https://github.com/BrucesHobbies/PZEM
Download prerequisitie ModBus.
sudo pip3 install pymodbus
Verify PZEM module presence using the RPi command line (once attached by USB cable and RS-485 cable with module power on):
ls /dev/ttyUSB* # Show USB devices
lsusb -v # Show USB devices with details
Please feel free to fork and contribute or provide feedback on priorities and features
To perform a quick read of the PZEM module use the following command:
python3 pzem.py
Let us know what you think of this project and any suggestions for improvements. Feel free to contribute to this open source project.