How to use PZEM004T Energy Monitor with esphome

Hi MarkB1, sorry for such late reply. Yes it is 2004 with i2c and I use ESPHome integrated in Home assistant to read my data.



uart:
  tx_pin: GPIO17
  rx_pin: GPIO16
  baud_rate: 9600
  stop_bits: 1

sensor:

  - platform: pzemac
    current:
      name: "Home Current"
      id: cur
    voltage:
      name: "Home Voltage"
      id: vol
    power:
      name: "Home Power"
      id: power
      state_class: measurement

    frequency:
      name: "Home Frequency"
      id: freq
    power_factor:
      name: "Home Power Factor"
      id: pow_factor
    update_interval: 5s

  - platform: total_daily_energy
    name: "Total Daily Energy"
    unit_of_measurement: kWh
    filters:
      - multiply: 0.001
    power_id: power
   
    
    
i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true
display:
  - platform: lcd_pcf8574
    dimensions: 20x4
    address: 0x27
    lambda: |-
      it.printf(0, 0, "* Home Power Meter *");
      it.printf(0, 1, "Pow:%.0fW", id(power).state);
      it.printf(10, 1, "Amp:%.1fA", id(cur).state);
      it.printf(0, 2, "%.1fV", id(vol).state);
      it.printf(14, 2, "%.1fHz", id(freq).state);
      it.strftime(0, 3, "Time:%H:%M", id(esptime).now());
      it.printf(10, 3, " WiFi%.0fdb", id(wifi_stat).state);
      
1 Like

Hi Guys, wondering if you smart people could run an eye over my config and maybe see what the problem is? Ive been at it for hours and cant see the issue. All my entities are showing up however are all ‘Unkown’ in lovelace. Running a Pzem-004t V3.0

esphome:
  name: solarenergy

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: ######

wifi:
  ssid: ######
  password: ######

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: ######
    password: ######

captive_portal:

uart:
  rx_pin: D2
  tx_pin: D1
  baud_rate: 9600
  stop_bits: 1

modbus:

sensor:
  - platform: pzemac
    address: 1
    current:
      name: PZEM-004T V3 Current
    voltage:
      name: PZEM-004T V3 Voltage
    energy:
      name: PZEM-004T V3 Energy
    power:
      name: PZEM-004T V3 Power
    frequency:
      name: PZEM-004T V3 Frequency
    power_factor:
      name: PZEM-004T V3 Power Factor
    update_interval: 60s

I have also tried GPIO5 and GPIO4 instead od D1 and D2. I have tried with modbus added and without. I have also tried with no stopbits, 1 stopbit and 2 stopbit. I also tried without
address: 1

The Wemos d1 mini and the Pzem are sharing the same 5v source if thats an issue? both are wired back to the source, not the pzem being piggybacked off the wemos

Any help would be awesome! Thank you!
Kade

edit: forgot to add, I soldered on a resistor as described here:
https://tasmota.github.io/docs/PZEM-0XX/#hardware-connections

my code for a v3 is just above at post 143, I have not added the resistor, and have fed mine from the same supply as my d1

Just removed the resistor and flashed with your code, still getting unknown results.
any other ideas?

edit: just changed logger level to VERY_VERBOSE and got this:

[06:21:32][V][mdns:088]:   - _esphomelib, _tcp, 6053
[06:21:32][V][mdns:090]:     TXT: version = 2022.1.3
[06:21:32][V][mdns:090]:     TXT: mac = bcff4d818e12
[06:21:32][V][mdns:090]:     TXT: platform = ESP8266
[06:21:32][V][mdns:090]:     TXT: board = d1_mini
[06:21:37][VV][scheduler:185]: Running interval 'update' with interval=60000 last_execution=4294948841 (now=41547)
[06:21:37][VV][uart.arduino_esp8266:178]:     Flushing...
[06:21:37][V][modbus:184]: Modbus write: 01.04.00.00.00.0A.70.0D (8)
[06:21:40][VV][api.service:337]: on_ping_request: PingRequest {}
[06:21:40][VV][api.service:043]: send_ping_response: PingResponse {}
[06:21:47][VV][api.service:337]: on_ping_request: PingRequest {}
[06:21:47][VV][api.service:043]: send_ping_response: PingResponse {}
[06:21:55][VV][api.service:337]: on_ping_request: PingRequest {}
[06:21:55][VV][api.service:043]: send_ping_response: PingResponse {}
[06:22:02][VV][scheduler:185]: Running interval '' with interval=60000 last_execution=6607 (now=66607)
[06:22:02][VV][api.service:337]: on_ping_request: PingRequest {}
[06:22:02][VV][api.service:043]: send_ping_response: PingResponse {}
[06:22:10][VV][api.service:337]: on_ping_request: PingRequest {}
[06:22:10][VV][api.service:043]: send_ping_response: PingResponse {}
[06:22:17][VV][api.service:337]: on_ping_request: PingRequest {}
[06:22:17][VV][api.service:043]: send_ping_response: PingResponse {}
[06:22:25][VV][api.service:337]: on_ping_request: PingRequest {}
[06:22:25][VV][api.service:043]: send_ping_response: PingResponse {}
[06:22:32][VV][api.service:337]: on_ping_request: PingRequest {}
[06:22:32][VV][api.service:043]: send_ping_response: PingResponse {}
[06:22:37][VV][scheduler:185]: Running interval 'update' with interval=60000 last_execution=41545 (now=101551)
[06:22:37][VV][uart.arduino_esp8266:178]:     Flushing...
[06:22:37][V][modbus:184]: Modbus write: 01.04.00.00.00.0A.70.0D (8)
[06:22:40][VV][api.service:337]: on_ping_request: PingRequest {}
[06:22:40][VV][api.service:043]: send_ping_response: PingResponse {}
[06:22:47][VV][api.service:337]: on_ping_request: PingRequest {}
[06:22:47][VV][api.service:043]: send_ping_response: PingResponse {}
[06:22:55][VV][api.service:337]: on_ping_request: PingRequest {}
[06:22:55][VV][api.service:043]: send_ping_response: PingResponse {}
[06:23:02][VV][scheduler:185]: Running interval '' with interval=60000 last_execution=66607 (now=126615)```

have you tried changing the rx and tx pins around? I remember me thinking I had them correct and got nothing till I swopped them. Sorry the log info is way above my skill set.

yeah tried that too

I have a Wemos Mini D1 and a pzem-004t v3. The ESPHome is already prepared. But I was not able to find clear information related to the wiring of pzem-004 v3.
My question is related to the +5V pin. Should I connect it to the 5V pin from Wemos or to 3.3V? Do I need an external source or for one pzem it is enough the power provided by Wemos? Do I need a resistor?

I know that the question is recurrent, but I was not able to find a clear statement.

See my post here

1 Like

For PZEM use 5V from D1 mini and Tx, Rx use 5V / 3.3V level converter

Connected to 3.3V amd and it seems that it works. With the 5V the PZEM-004T was not starting.

I suspect the kwh value is under the real consumption
Can be this caused by the 3.3V that is provided to pzem-004t?

As I mentioned, I use this connection and it works well for more than a year. If it is written PZEM + 5V / GND it is necessary to observe it and not solve the problem 3.3V.
pzem schema

2 Likes

Found the problem. The coil was not well connected to the main cable.

I read the post but I couldn’t figure out my problem.
I connected 2 pzem004t v3 to a nodemcu. but i get crc error

[W][modbus:096]: Modbus CRC Check failed! C961!=01

this is my configuration:

esphome:
  name: powermeter

esp8266:
  board: nodemcuv2

# Enable logging
logger:
  level: verbose
  baud_rate: 0

# Enable Home Assistant API
api:

ota:
  password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid_casa
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Powermeter Fallback Hotspot"
    password: !secret wifi_password_fallback

captive_portal:

web_server:
  port: 80
  
uart:
  - id: ubus
    rx_pin: GPIO3 #D1
    tx_pin: GPIO1 #D2
    baud_rate: 9600
    stop_bits: 1

modbus:
  id: mbus
  uart_id: ubus

sensor:
  - platform: pzemac
    address: 1
    modbus_id: mbus
    current:
      name: "ID1 Current"
    voltage:
      name: "ID1 Voltage"
    energy:
      name: "ID1 Energy"
    power:
      name: "ID1 Power"
    frequency:
      name: "ID1 Frequency"
    power_factor:
      name: "ID1 Power Factor"
    update_interval: 10s
  - platform: pzemac
    address: 2
    modbus_id: mbus
    current:
      name: "ID2 Current"
    voltage:
      name: "ID2 Voltage"
    energy:
      name: "ID2 Energy"
    power:
      name: "ID2 Power"
    frequency:
      name: "ID2 Frequency"
    power_factor:
      name: "ID2 Power Factor"
    update_interval: 10s
    
button:
  - platform: restart
    name: Restart Sale

i need to use diodes and resistors on the circuit as indicated in this pic?

Where did you get that box from to fit all the components? Looks neat!
Also on the box the CT clamp is connected to, I can spot a Zigbee symbol. How do you use it?

Hi, box is from Ferrero Rocher chocolates :wink: . CT clamp is connected to PZEM004T which is connected to ESP32 with EspHome. There is no Zigbee involved in this project.

All of that I can tell. I have the same setup, except for the chocolate box :wink:

I meant this Zigbee logo. :wink:

This is my electricity meter in the UK. They call them Smart Meters so they probably use Zigbee to communicate with not so smart display at home to display real usage

My own…


2 Likes

Would you mind sharing your full .bin file for the esp? :slight_smile: