How to use PZEM004T Energy Monitor with esphome

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

Hello, how do you manage to address numbers to PZEM 004T v3 you are with the software.
Pyy project is 2 pzem on wimos mini for monitoring the solar panel and energy consumed.
thx

Hello, I am trying to connect PZEM-004T V1.0 with NodeMCU.

However i can’t get any serial communication going, followed advices and i have this code:

esphome:
  name: vanvex2
  platform: ESP8266
  board: esp01_1m

# Enable logging
logger:
  level: VERY_VERBOSE
  baud_rate: 0
# Enable Home Assistant API
api:

ota:
  password: "xx"

wifi:
  ssid: "xx"
  password: "xx"

captive_portal:

switch:
  - platform: gpio
    name: "Vanvex_button_temp"
    pin: 12
    id: button1_d6

  - platform: gpio
    name: "Vanvex_button_down"
    pin: 14
    id: button2_d5

  - platform: gpio
    name: "Vanvex_button_up"
    pin: 13
    id: button2_d7

uart:
  id: uart_pz
  tx_pin: 1
  rx_pin: 3
  baud_rate: 9600
  stop_bits: 1

sensor:
  - platform: pzem004t
    uart_id: uart_pz
    current:
      name: "Vanvex Current"
    voltage:
      name: "Vanvex Voltage"
    power:
      name: "Vanvex Power"
    energy:
      name: "Vanvex Energy"
    update_interval: 20s`

any ideas what i am doing wrong? RX of PZEM is connected to ESP8266 GPIO1 TX, and TX of PZEM to ESP8266 GPIO3 RX. Powered by 5V VU pin.

Here is my log:

INFO Reading configuration /config/esphome/vanvex2.yaml...
INFO Starting log output from vanvex2.local using esphome API
INFO Successfully connected to vanvex2.local
[23:56:47][I][app:102]: ESPHome version 2021.9.2 compiled on Oct  9 2021, 23:45:59
[23:56:47][C][wifi:501]: WiFi:
[23:56:47][C][wifi:361]:   SSID: [redacted]
[23:56:47][C][wifi:362]:   IP Address: 192.168.1.205
[23:56:47][C][wifi:364]:   BSSID: [redacted]
[23:56:47][C][wifi:365]:   Hostname: 'vanvex2'
[23:56:47][C][wifi:369]:   Signal strength: -82 dB ▂▄▆█
[23:56:47][V][wifi:371]:   Priority: 0.0
[23:56:47][C][wifi:373]:   Channel: 1
[23:56:47][C][wifi:374]:   Subnet: 255.255.255.0
[23:56:47][C][wifi:375]:   Gateway: 192.168.1.1
[23:56:47][C][wifi:376]:   DNS1: 192.168.1.1
[23:56:47][C][wifi:377]:   DNS2: (IP unset)
[23:56:47][C][uart_esp8266:097]: UART Bus:
[23:56:47][C][uart_esp8266:099]:   TX Pin: GPIO1
[23:56:47][C][uart_esp8266:102]:   RX Pin: GPIO3
[23:56:47][C][uart_esp8266:103]:   RX Buffer Size: 256
[23:56:47][C][uart_esp8266:105]:   Baud Rate: 9600 baud
[23:56:47][C][uart_esp8266:106]:   Data Bits: 8
[23:56:47][C][uart_esp8266:107]:   Parity: NONE
[23:56:47][C][uart_esp8266:108]:   Stop bits: 1
[23:56:47][C][uart_esp8266:110]:   Using hardware serial interface.
[23:56:47][C][switch.gpio:048]: GPIO Switch 'Vanvex_button_temp'
[23:56:47][C][switch.gpio:049]:   Pin: GPIO12 (Mode: OUTPUT)
[23:56:47][C][switch.gpio:071]:   Restore Mode: Restore (Defaults to OFF)
[23:56:47][C][switch.gpio:048]: GPIO Switch 'Vanvex_button_down'
[23:56:47][C][switch.gpio:049]:   Pin: GPIO14 (Mode: OUTPUT)
[23:56:47][C][switch.gpio:071]:   Restore Mode: Restore (Defaults to OFF)
[23:56:47][C][switch.gpio:048]: GPIO Switch 'Vanvex_button_up'
[23:56:47][C][switch.gpio:049]:   Pin: GPIO13 (Mode: OUTPUT)
[23:56:47][C][switch.gpio:071]:   Restore Mode: Restore (Defaults to OFF)
[23:56:47][C][logger:193]: Logger:
[23:56:47][C][logger:194]:   Level: VERY_VERBOSE
[23:56:47][C][logger:195]:   Log Baud Rate: 0
[23:56:47][C][logger:196]:   Hardware UART: UART0
[23:56:47][C][pzem004t:110]: PZEM004T:
[23:56:47][C][pzem004t:111]: Voltage 'Vanvex Voltage'
[23:56:47][C][pzem004t:111]:   Device Class: 'voltage'
[23:56:47][C][pzem004t:111]:   State Class: 'measurement'
[23:56:47][C][pzem004t:111]:   Unit of Measurement: 'V'
[23:56:47][C][pzem004t:111]:   Accuracy Decimals: 1
[23:56:47][C][pzem004t:112]: Current 'Vanvex Current'
[23:56:47][C][pzem004t:112]:   Device Class: 'current'
[23:56:47][C][pzem004t:112]:   State Class: 'measurement'
[23:56:47][C][pzem004t:112]:   Unit of Measurement: 'A'
[23:56:47][C][pzem004t:112]:   Accuracy Decimals: 2
[23:56:47][C][pzem004t:113]: Power 'Vanvex Power'
[23:56:47][C][pzem004t:113]:   Device Class: 'power'
[23:56:47][C][pzem004t:113]:   State Class: 'measurement'
[23:56:47][C][pzem004t:113]:   Unit of Measurement: 'W'
[23:56:47][C][pzem004t:113]:   Accuracy Decimals: 0
[23:56:47][C][captive_portal:148]: Captive Portal:
[23:56:47][C][ota:029]: Over-The-Air Updates:
[23:56:47][C][ota:030]:   Address: vanvex2.local:8266
[23:56:47][C][ota:032]:   Using Password.
[23:56:47][C][api:135]: API Server:
[23:56:47][C][api:136]:   Address: vanvex2.local:6053
[23:56:54][VV][scheduler:151]: Running interval 'update' with interval=20000 last_execution=602645 (now=622646)
[23:56:54][VV][uart_esp8266:133]:     Wrote 0b10110000 (0xB0)
[23:56:54][VV][uart_esp8266:133]:     Wrote 0b11000000 (0xC0)
[23:56:54][VV][uart_esp8266:133]:     Wrote 0b10101000 (0xA8)
[23:56:54][VV][uart_esp8266:133]:     Wrote 0b00000001 (0x01)
[23:56:54][VV][uart_esp8266:133]:     Wrote 0b00000001 (0x01)
[23:56:54][VV][uart_esp8266:133]:     Wrote 0b00000000 (0x00)
[23:56:54][VV][uart_esp8266:133]:     Wrote 0b00011010 (0x1A)
[23:57:02][VV][api.service:327]: on_ping_request: PingRequest {}
[23:57:02][VV][api.service:043]: send_ping_response: PingResponse {}
[23:57:02][VV][api.service:327]: on_ping_request: PingRequest {}
[23:57:02][VV][api.service:043]: send_ping_response: PingResponse {}

Try reversing tx rx one time

Tried that in software but didn’t work

Is it a v3 nodemcu ? If not you’ll need an external 5v

Also, try not using D3, it’s GPIO0 I think

It is NodeMCU V3. GPIO1 should be TX and GPIO3 should be RX on this board. I literally tried every combination of step bits and RX/RX, tried software serial on D1/D2… Even tried to flash tasmota, but then flash size is only 1MB and in tasmota lite there is no PZEM configuration module.

I made sure that PZEM receives 5.146V, and RX/TX are inversed as they should be.

I tried another PZEM-004T board, did not help. Tried inversing RX/TX in hardware, did not help

In my working config I use:

uart:
  id: uart_pz
  tx_pin: TX
  rx_pin: RX
  baud_rate: 9600
  stop_bits: 1

Maybe try that or:

uart:
  id: uart_pz
  tx_pin: GPIO1
  rx_pin: GPIO3
  baud_rate: 9600
  stop_bits: 1