How to use PZEM004T Energy Monitor with esphome

What’s the reporting response time on these with esphome?

Wondering if I could make a automatic sensor to turn on my dust collector. Table saw and other tools draw plent my of power and combined with a relay it could be an awesome solution if quick enough.

Hello,

Thank you, I found it issue. Needed logger to change it to 0:

logger:
  level: DEBUG
  baud_rate: 0

Hello,

one question appear, why these diodes needs, if all have different address?

Is there a way to reset the energy counter of the individual setups?
Also is there a way to find the address of the pzem connected to this?

Copied this code,
Got all three PZEMs (V3’s)addresses through Tasmota ModuleAddress and got “Done” answer from them.
Connected to NodeMCU
Diodes are 1N4148 that I had in hand (Maybe that’s my issue?)
10K resistor between 5v and RX
If I connect more than one PZEM I get
“[modbus:074]: Modbus CRC Check failed!”

Anyone had this issue?
I’ve been at it for days now

Hi, I have done in an other way, maybe this can help you.

First I have found the PZEM04 complete schematic below:

First before connected all RX/TX PZEM04, set the address individually.
I have done with the windows software, one connected at a time, and set a different address

I use one ESP8266, with 4 PZEM04, with following connections:
The GND of ESP8266 and 4 PZEM04 connected together.
The +5V pin of the 4 PZEM04 connected to the ESP8266 3V3.
The TX pin of ESP8266 is connected to the RX 4 PZEM04 together.
The RX pin of ESP8266 is connected to the TX 4 PZEM04 together.

  • this because the TX PZEM04 is Open Collector type
  • but to not overload the TX optocouplers, I remove the R4 and R9 on 3 PZEM04

That works fine for me.
Benefits:

  • The RX signal ESP8266 “voltage low” value is better with this solution. (may reduce CRC Check failed)
  • no need to add external components

Another recommendation:
As the CT is connected to the neutral by the PZEM04, it is better to install the CT on neutral wire.
This because the difference voltage from CT and neutral is near than 0V.
But when installing the CT on live wire, the difference voltage from CT and live is the AC grid voltage.
=> So the risk to make a short circuit live to neutral is bigger
The only protection to prevent it is the plastic insulation of the CT (which is probably not certified for this)

5 Likes

Hi @4xvince, when you say that you have removed the R4 and R9 on 3 PZEM04, you mean that you really removed the R4 and R9 so no connection anymore with TX in that line

option 1

or you have connected directly the 5V to TX with no R4 and R9?

option 2

I have five PZEM-004T ver. 3 and I’m trying to connect to Lilygo TTGO T-Internet-POE ESP32-WROOM.

I set each PZEM004v3 address individually with the Windows software, one connected at a time.

When I try to connect the fifth PZEM, no one works. When I try to connect four PZEM, they works at begin but after, only three works. Now I’m having only two PZEM working at same time.

Is my circuit bellow correct? Do I need to use a diode, resistor or something like that? Should I use 3V3 or 5V?

My power source is an AC-DC 5V 5A

My esp32:

My Code:

esphome:
  name: lilygo-ttgo-t
  platform: ESP32
  board: esp32dev
  
ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 0

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:

ota:
  password: "e25axxxxxxxxxxxxxxxxxa58"
  
web_server:
  port: 80


dallas:
  - pin: GPIO15
    update_interval: 30s
    id: dallas_gpio15
  
uart:
  rx_pin: GPIO35 
  tx_pin: GPIO14 
  baud_rate: 9600
  #stop_bits: 1
  #stop_bits: 2
  id: ubus1

sensor:

#PZEM 004T V3 100A

  - platform: pzemac
    current:
      name: "AAA - L1 - Current"
    voltage:
      name: "AAA - L1 - Voltage"
    energy:
      name: "AAA - L1 - Energy"
    power:
      name: "AAA - L1 - Power"
    frequency:
      name: "AAA - L1 - Frequency"
    power_factor:
      name: "AAA - L1 - Power Factor"
    update_interval: 10s
    address: 1
    
  - platform: pzemac
    current:
      name: "AAA - L2 - Current"
    voltage:
      name: "AAA - L2 - Voltage"
    energy:
      name: "AAA - L2 - Energy"
    power:
      name: "AAA - L2 - Power"
    frequency:
      name: "AAA - L2 - Frequency"
    power_factor:
      name: "AAA - L2 - Power Factor"
    update_interval: 10s
    address: 2
    
  - platform: pzemac
    current:
      name: "AAA - L3 - Current"
    voltage:
      name: "AAA - L3 - Voltage"
    energy:
      name: "AAA - L3 - Energy"
    power:
      name: "AAA - L3 - Power"
    frequency:
      name: "AAA - L3 - Frequency"
    power_factor:
      name: "AAA - L3 - Power Factor"
    update_interval: 10s
    address: 3

  - platform: pzemac
    current:
      name: "BBB - L1 - Current"
    voltage:
      name: "BBB - L1 - Voltage"
    energy:
      name: "BBB - L1 - Energy"
    power:
      name: "BBB - L1 - Power"
    frequency:
      name: "BBB - L1 - Frequency"
    power_factor:
      name: "BBB - L1 - Power Factor"
    update_interval: 10s
    address: 4
      
  - platform: pzemac
    current:
      name: "BBB - L2 - Current"
    voltage:
      name: "BBB - L2 - Voltage"
    energy:
      name: "BBB - L2 - Energy"
    power:
      name: "BBB - L2 - Power"
    frequency:
      name: "BBB - L2 - Frequency"
    power_factor:
      name: "BBB - L2 - Power Factor"
    update_interval: 10s
    address: 5

#HALL SENSOR

  - platform: esp32_hall #GPIO 39 and 36
    name: "ESP32 Hall Sensor"
    update_interval: 10s
.
.
.

2 Likes

Hi,
Yes if you connect multiples PZEM, you only need one with R4 and R9.
So you can simply removed R4 and R9 from all other PZEM.
(First schematic is correct)

Hi,
As I mentioned “The +5V pin of the 4 PZEM04 connected to the ESP8266 3V3.”

You really need to power the +5V pin of PZEM04 to a 3V3 source, as the input of the ESP32 is only compliant to 3.3V logic.
=> by connecting a +5V source you may have damage the D35 pin or/and the ESP32.

Another thing to check is the current capacity of the ESP
You have 5 PZEMs, and each consume near 2mA, then the ESP have to drive near 10mA
The ESP has a typical current capability of 28mA

(search IOL Electrical Characteristics)
=> It’s seams to be enough

1 Like

is this not compatible with the new energy update? when trying to set up my pze does not show, does the yaml need tweaking?

Can ESPHOME + PZEM show full energy, not only active?

Just use this with the pzem’s power sensor

I needed to add device_class: energy to the sensor to make it work with HA energy

Hi, me for make the detection of PZEM in HA new energy feature,
i have just add in ESPhome the state_class: "measurement" for
my energy sensor like this :

sensor:
  - platform: pzemac
    address: 1
    current:
      name: "General Current"
    voltage:
      name: "General Voltage"
    energy:
      name: "General Energy"
      state_class: "measurement"

This make it visible, but i need to wait for see analysed data in dashboard

As mentioned, I also use the utility_meter like this (in /config/configuration.yaml):

utility_meter:
  general_daily_energy:
    source: sensor.general_energy
    cycle: daily
  general_monthly_energy:
    source: sensor.general_energy
    cycle: monthly

I was checking the connections on my board to convert it from 5V to 3.3V. I soldered a 1K resistor in parallel with R8 but I think the schematic above has a mistake. I think LED D3 is not connected on pin 1 of 817 but it’s connected on Rx pin (pin 2 of 817). Could anyone verify that?
Screenshot 2021-09-20 at 13.29.49

I’ve the same problem. I receive the total amount of consumed energy and NOT the “instant” energy i consume every moment.
Are there any solution for this?
With the total, HA increases cost constantly and is not real cost…

This works for me in the HA Energy Dashboard:

  - platform: pzemac
    current:
      name: Home Current
      unit_of_measurement: A
      accuracy_decimals: 1
      icon: mdi:flash-circle
    voltage:
      name: Home Voltage
      unit_of_measurement: V
      icon: mdi:flash-circle
    power:
      name: Home Power
      unit_of_measurement: kW
      accuracy_decimals: 3
      filters:
        - multiply: 0.001
      icon: mdi:flash-circle
      id: home_power
    update_interval: 5s

  - platform: total_daily_energy
    name: Home Total Daily Energy
    power_id: home_power
    id: totaldailyenergy
    unit_of_measurement: kWh
    accuracy_decimals: 3
    icon: mdi:clock-alert
    device_class: energy

Copied you config and still seeing the “acummulated” energy…
2021-09-30 11_06_31-Clipboard
Any other hint?

Assume you are using the Home Total Daily Energy Sensor in the energy config, grid consumption ?

Right.

    power:
      name: "General Power"
      unit_of_measurement: kW
      accuracy_decimals: 3
      filters:
        - multiply: 0.001
      icon: mdi:flash-circle
      id: home_power
    frequency:
      name: "General Frequency"
    power_factor:
      name: "General Power Factor"
    update_interval: 15s

  - platform: total_daily_energy
    name: General Total Daily Energy
    power_id: home_power
    id: totaldailyenergy
    unit_of_measurement: kWh
    accuracy_decimals: 3
    icon: mdi:clock-alert
    device_class: energy