How to use PZEM004T Energy Monitor with esphome

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:

Below my .yaml config. Just add new device to EspHome paste this config and generate .bin

substitutions:
  # Modify variables based on your settings
  hostname: "esp32_power_monitor"
  # this is just for ingormation where this device is located
  location: "Consumer Box"
  #amend platford and board type
  platform: ESP32
  board: nodemcu-32s

esphome:
  name: $hostname
  platform: $platform
  board: $board

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: on  
# Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "AP $hostname"
    password: !secret ap_fallback_password

captive_portal:

logger:

web_server:

api:
  password: !secret ha_api_password
  reboot_timeout: 5min 
ota:
  password: !secret ota_password

text_sensor:
  - platform: version
    name: version
  - platform: wifi_info
    ip_address:
      name: ip
    ssid:
      name: ssid
    bssid:
      name: bssid

binary_sensor:   
  - platform: status
    name: "$hostname Status"


time:
  - platform: homeassistant
    id: esptime 
    

status_led:
  pin: GPIO2

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

sensor:

  - platform: wifi_signal
    name: "$hostname WiFi"
    update_interval: 60s 
    id: wifi_stat
  - platform: uptime
    name: $hostname Uptime

  
  - 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);
      
      // first number shows position in line then comma and line number. 0 is first line

2 Likes

I have 2 pzem on the same modbus network
1 pzem = IP(1)
2 pzem = IP(2)

Part of the code used:

PinoTX:“GPIO12”
PinoRX:“GPIO14”

uart:
tx_pin: ${PinoTX}
rx_pin: ${PinoRX}
baud_rate: 9600
stop_bits: 1

switch:

  • platform: uart
    name: “Phase 1 - Reset Energy”
    date = [0x01, 0x42, 0x80, 0x11]

  • platform: uart
    name: “Phase 2 - Reset Energy”
    date = [?, 0x42, ?, ?]

What HEX numbers should I put to reset the power of the second pzem(IP=2)???