How to use PZEM004T Energy Monitor with esphome

Hi! I am connecting the PZEM-004T to the D1 mini. And nothing:

XML:

substitutions:
  devicename: ac_pzem
  upper_devicename: AC PZEM

esphome:
  name: $devicename
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "xxx"
  password: "xxx"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "AC PZEM Fallback Hotspot"
    password: "xxx"

captive_portal:

web_server:
  port: 80

# Enable Home Assistant API
api:
 
# Enable OTA Access
ota:
 
# Enable verbose logging over serial
logger:

uart:
  tx_pin: TX #GPIO1
  rx_pin: RX #GPIO3
  baud_rate: 9600
  stop_bits: 1

sensor:
  - platform: pzem004t
    current:
      name: "PZEM-004T Current"
    voltage:
      name: "PZEM-004T Voltage"
    power:
      name: "PZEM-004T Power"
    update_interval: 60s

Log:

INFO Successfully connected to ac_pzem.local
[17:14:46][I][app:100]: ESPHome version 1.14.3 compiled on Nov 23 2019, 17:13:57
[17:14:47][C][wifi:415]: WiFi:
[17:14:47][C][wifi:283]:   SSID: 

[redacted]
[17:14:47][C][wifi:284]:   IP Address: 192.168.15.80
[17:14:47][C][wifi:286]:   BSSID: [redacted]
[17:14:48][C][wifi:287]:   Hostname: 'ac_pzem'
[17:14:48][C][wifi:291]:   Signal strength: -54 dB ▂▄▆█
[17:14:48][C][wifi:295]:   Channel: 1
[17:14:48][C][wifi:296]:   Subnet: 255.255.255.0
[17:14:48][C][wifi:297]:   Gateway: 192.168.15.1
[17:14:48][C][wifi:298]:   DNS1: 192.168.15.1
[17:14:48][C][wifi:299]:   DNS2: 212.33.225.212
[17:14:48][C][uart:140]: UART Bus:
[17:14:48][C][uart:142]:   TX Pin: GPIO1
[17:14:48][C][uart:145]:   RX Pin: GPIO3
[17:14:48][C][uart:147]:   Baud Rate: 9600 baud
[17:14:48][C][uart:148]:   Stop bits: 1
[17:14:48][C][uart:150]:   Using hardware serial interface.
[17:14:48](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[17:14:48][C][logger:175]: Logger:
[17:14:48][C][api:095]: API Server:
[17:14:48](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[17:16:25][I][ota:046]: Boot seems successful, resetting boot loop counter.

What’s wrong?

I would try software serial. Do you know your version of the pzem004t?

What is your is pzem version? For v3 you should use pzemac integration

I used the logger settings: VERY_VERBOSE. But I can’t understand whether pzem004t works or not.

[16:17:54][I][app:100]: ESPHome version 1.14.3 compiled on Nov 26 2019, 16:12:47
[16:17:55][C][wifi:415]: WiFi:
[16:17:55][C][wifi:283]:   SSID: [redacted]
[16:17:55][C][wifi:284]:   IP Address: 192.168.15.80
[16:17:55][C][wifi:286]:   BSSID: [redacted]
[16:17:55][C][wifi:287]:   Hostname: 'ac_pzem'
[16:17:55][C][wifi:291]:   Signal strength: -64 dB ▂▄▆█
[16:17:55][V][wifi:293]:   Priority: -1.0
[16:17:55][C][wifi:295]:   Channel: 1
[16:17:55][C][wifi:296]:   Subnet: 255.255.255.0
[16:17:55][C][wifi:297]:   Gateway: 192.168.15.1
[16:17:55][C][wifi:298]:   DNS1: 192.168.15.1
[16:17:55][C][wifi:299]:   DNS2: 212.33.225.212
[16:17:55][C][uart:140]: UART Bus:
[16:17:55][C][uart:142]:   TX Pin: GPIO1
[16:17:55][C][uart:145]:   RX Pin: GPIO3
[16:17:55][C][uart:147]:   Baud Rate: 9600 baud
[16:17:55][C][uart:148]:   Stop bits: 1
[16:17:55](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[16:17:55](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[16:17:55][C][logger:175]: Logger:
[16:17:55](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[16:17:55](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[16:17:55][C][api:096]:   Address: ac_pzem.local:6053
[16:17:55](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[16:17:56][VV][api.service:250]: on_ping_request: PingRequest {}
[16:17:56][VV][api.service:035]: send_ping_response: PingResponse {}
[16:18:01][VV][api.service:250]: on_ping_request: PingRequest {}
[16:18:01][VV][api.service:035]: send_ping_response: PingResponse {}
[16:18:04][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=45434 (now=55434)
[16:18:06][VV][api.service:250]: on_ping_request: PingRequest {}
[16:18:06][VV][api.service:035]: send_ping_response: PingResponse {}
[16:18:11][VV][api.service:250]: on_ping_request: PingRequest {}
[16:18:11][VV][api.service:035]: send_ping_response: PingResponse {}
[16:18:14][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=55434 (now=65435)
[16:18:18][VV][api.service:250]: on_ping_request: PingRequest {}
[16:18:18][VV][api.service:035]: send_ping_response: PingResponse {}
[16:18:23][VV][api.service:250]: on_ping_request: PingRequest {}
[16:18:23][VV][api.service:035]: send_ping_response: PingResponse {}
[16:18:26][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=65434 (now=75441)
[16:18:28][VV][api.service:250]: on_ping_request: PingRequest {}
[16:18:28][VV][api.service:035]: send_ping_response: PingResponse {}
[16:18:33][VV][api.service:250]: on_ping_request: PingRequest {}
[16:18:33][VV][api.service:035]: send_ping_response: PingResponse {}
[16:18:34][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=75434 (now=85434)
[16:18:38][VV][api.service:250]: on_ping_request: PingRequest {}
[16:18:38][VV][api.service:035]: send_ping_response: PingResponse {}
[16:18:43][VV][scheduler:131]: Running interval 'update' with interval=60000 last_execution=33078 (now=93078)
[16:18:43][VV][uart:173]:     Wrote 0b10110000 (0xB0)
[16:18:43][VV][uart:173]:     Wrote 0b11000000 (0xC0)
[16:18:43][VV][uart:173]:     Wrote 0b10101000 (0xA8)
[16:18:43][VV][uart:173]:     Wrote 0b00000001 (0x01)
[16:18:43][VV][uart:173]:     Wrote 0b00000001 (0x01)
[16:18:43][VV][uart:173]:     Wrote 0b00000000 (0x00)
[16:18:43][VV][uart:173]:     Wrote 0b00011010 (0x1A)
[16:18:43][V][app:076]: A component took a long time in a loop() cycle (0.41 s).
[16:18:43][V][app:077]: Components should block for at most 20-30ms in loop().
[16:18:43][VV][api.service:250]: on_ping_request: PingRequest {}
[16:18:43][VV][api.service:035]: send_ping_response: PingResponse {}
[16:18:44][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=85434 (now=95434)
[16:18:49][VV][api.service:250]: on_ping_request: PingRequest {}
[16:18:49][VV][api.service:035]: send_ping_response: PingResponse {}
[16:18:54][VV][api.service:250]: on_ping_request: PingRequest {}
[16:18:54][VV][api.service:035]: send_ping_response: PingResponse {}
[16:18:54][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=95434 (now=105441)
[16:18:59][VV][api.service:250]: on_ping_request: PingRequest {}
[16:18:59][VV][api.service:035]: send_ping_response: PingResponse {}
[16:19:04][VV][api.service:250]: on_ping_request: PingRequest {}
[16:19:04][VV][api.service:035]: send_ping_response: PingResponse {}
[16:19:05][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=105434 (now=115435)
[16:19:09][VV][api.service:250]: on_ping_request: PingRequest {}
[16:19:09][VV][api.service:035]: send_ping_response: PingResponse {}
[16:19:09][I][ota:046]: Boot seems successful, resetting boot loop counter.
[16:19:09][VV][preferences:051]: SAVE 32: 0=0x00000000 1=0x0DEFE4E3 (Type=233825507, CRC=0x0DEFE4E3)
[16:19:14][VV][api.service:250]: on_ping_request: PingRequest {}
[16:19:14][VV][api.service:035]: send_ping_response: PingResponse {}
[16:19:14][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=115434 (now=125437)
[16:19:19][VV][api.service:250]: on_ping_request: PingRequest {}
[16:19:19][VV][api.service:035]: send_ping_response: PingResponse {}
[16:19:24][VV][api.service:250]: on_ping_request: PingRequest {}
[16:19:25][VV][api.service:035]: send_ping_response: PingResponse {}
[16:19:25][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=125434 (now=135434)
[16:19:30][VV][api.service:250]: on_ping_request: PingRequest {}
[16:19:30][VV][api.service:035]: send_ping_response: PingResponse {}
[16:19:34][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=135434 (now=145434)
[16:19:35][VV][api.service:250]: on_ping_request: PingRequest {}
[16:19:36][VV][api.service:035]: send_ping_response: PingResponse {}
[16:19:41][VV][api.service:250]: on_ping_request: PingRequest {}
[16:19:41][VV][api.service:035]: send_ping_response: PingResponse {}
[16:19:43][VV][scheduler:131]: Running interval 'update' with interval=60000 last_execution=93078 (now=153079)
[16:19:43][VV][uart:173]:     Wrote 0b10110000 (0xB0)
[16:19:43][VV][uart:173]:     Wrote 0b11000000 (0xC0)
[16:19:43][VV][uart:173]:     Wrote 0b10101000 (0xA8)
[16:19:43][VV][uart:173]:     Wrote 0b00000001 (0x01)
[16:19:43][VV][uart:173]:     Wrote 0b00000001 (0x01)
[16:19:43][VV][uart:173]:     Wrote 0b00000000 (0x00)
[16:19:43][VV][uart:173]:     Wrote 0b00011010 (0x1A)
[16:19:43][V][app:076]: A component took a long time in a loop() cycle (0.41 s).
[16:19:43][V][app:077]: Components should block for at most 20-30ms in loop().
[16:19:44][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=145434 (now=155434)
[16:19:48][VV][api.service:250]: on_ping_request: PingRequest {}
[16:19:48][VV][api.service:035]: send_ping_response: PingResponse {}
[16:19:53][VV][api.service:250]: on_ping_request: PingRequest {}
[16:19:53][VV][api.service:035]: send_ping_response: PingResponse {}
[16:19:56][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=155434 (now=165438)
[16:19:58][VV][api.service:250]: on_ping_request: PingRequest {}
[16:19:58][VV][api.service:035]: send_ping_response: PingResponse {}
[16:20:03][VV][api.service:250]: on_ping_request: PingRequest {}
[16:20:03][VV][api.service:035]: send_ping_response: PingResponse {}
[16:20:05][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=165434 (now=175434)
[16:20:08][VV][api.service:250]: on_ping_request: PingRequest {}
[16:20:08][VV][api.service:035]: send_ping_response: PingResponse {}
[16:20:13][VV][api.service:250]: on_ping_request: PingRequest {}
[16:20:13][VV][api.service:035]: send_ping_response: PingResponse {}
[16:20:14][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=175434 (now=185440)
[16:20:18][VV][api.service:250]: on_ping_request: PingRequest {}
[16:20:18][VV][api.service:035]: send_ping_response: PingResponse {}
[16:20:23][VV][api.service:250]: on_ping_request: PingRequest {}
[16:20:23][VV][api.service:035]: send_ping_response: PingResponse {}
[16:20:24][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=185434 (now=195436)
[16:20:28][VV][api.service:250]: on_ping_request: PingRequest {}
[16:20:28][VV][api.service:035]: send_ping_response: PingResponse {}
[16:20:33][VV][api.service:250]: on_ping_request: PingRequest {}
[16:20:33][VV][api.service:035]: send_ping_response: PingResponse {}
[16:20:34][VV][scheduler:131]: Running interval '' with interval=10000 last_execution=195434 (now=205434)
[16:20:38][VV][api.service:250]: on_ping_request: PingRequest {}
[16:20:38][VV][api.service:035]: send_ping_response: PingResponse {}
[16:20:43][VV][scheduler:131]: Running interval 'update' with interval=60000 last_execution=153078 (now=213080)
[16:20:43][VV][uart:173]:     Wrote 0b10110000 (0xB0)
[16:20:43][VV][uart:173]:     Wrote 0b11000000 (0xC0)
[16:20:44][VV][uart:173]:     Wrote 0b10101000 (0xA8)
[16:20:44][VV][uart:173]:     Wrote 0b00000001 (0x01)
[16:20:44][VV][uart:173]:     Wrote 0b00000001 (0x01)
[16:20:44][VV][uart:173]:     Wrote 0b00000000 (0x00)
[16:20:44][VV][uart:173]:     Wrote 0b00011010 (0x1A)
[16:20:44][V][app:076]: A component took a long time in a loop() cycle (0.41 s).
[16:20:44][V][app:077]: Components should block for at most 20-30ms in loop().
[16:20:44][VV][api.service:250]: on_ping_request: PingRequest {}
[16:20:44][VV][api.service:035]: send_ping_response: PingResponse {}

Could you please post the complete yaml?

Thanlks

2 Likes

I have a three phase system and all of them are monitored. Addresses of each pzem should be changed manually. Tasmota has a command to do so.


esphome:
  name: power_ac
  platform: ESP8266
  board: nodemcuv2  

wifi:
  ssid: "xxxxxxx"
  password: "xxxxxxxxx"
  manual_ip:
    static_ip: 192.168.1.xxx
    gateway: 192.168.1.xxx
    subnet: 255.255.255.0


# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:

ota:

uart:
  - id: ubus1
    tx_pin: GPIO1
    rx_pin: GPIO3
    baud_rate: 9600
    stop_bits: 1
    
sensor:
  - platform: pzemac
    voltage:
      name: "Black Volt"
    power:
      name: "Black Power"
    update_interval: 10s
    address: 1
    
  - platform: pzemac
    voltage:
      name: "Brown Volt"
    power:
      name: "Brown Power"
    update_interval: 10s
    address: 2   
    
  - platform: pzemac
    voltage:
      name: "Red Volt"
    power:
      name: "Red Power"
    update_interval: 10s
    address: 3       
    
  - platform: adc
    pin: VCC
    name: "Power_AC Voltage"
4 Likes

Your are more than welcome to make a pull request and add the mentioned feature to esphome :star_struck:

1 Like

I have no idea how to do that sorry :slight_smile:
But it is a serial command from the console:
ModuleAddress 1 changes the currently connected single pzem004’s address to 192.168.1.1. And this can work for up to 3 pzems. You use the addresses 1,2 and 3.

1 Like

I have a manual in spanish for integrate the pzem, in ESPhome but I’m not sure if can put here a external link.

Sorry bit of an off topic question but I’m stuck for answers…

I’ve a question on how you connect the reference wires to live and neutral on the pzem-016… I was thinking I’d just take the live and neutral from a power socket next to my utility board… or do I specifically have to take the live from before all the loads and the neutral from after all the loads?

I’ve done this and it works fine, reads very close to the kWh per day as my supplier says I’ve used

yes I watched a youtube video and the chap pointed out that wiring the reference wires after the detection coil is no big deal… just means it records its own drain which is only a few milliamps so no worries there

I am using esphome +pzem-004t v3. My log:

INFO Reading configuration /config/esphome/pzem_004t.yaml...
INFO Starting log output from 192.168.5.239 using esphome API
INFO Connecting to 192.168.5.239:6053 (192.168.5.239)
INFO Successfully connected to 192.168.5.239
[16:54:21][I][app:100]: ESPHome version 1.14.3 compiled on Mar 17 2020, 15:26:41
[16:54:21][C][wifi:415]: WiFi:
[16:54:21][C][wifi:283]:   SSID: [redacted]
[16:54:21][C][wifi:284]:   IP Address: 192.168.5.239
[16:54:21][C][wifi:286]:   BSSID: [redacted]
[16:54:21][C][wifi:287]:   Hostname: 'pzem_004t'
[16:54:21][C][wifi:291]:   Signal strength: -71 dB ▂▄▆█
[16:54:21][C][wifi:295]:   Channel: 11
[16:54:21][C][wifi:296]:   Subnet: 255.255.255.0
[16:54:21][C][wifi:297]:   Gateway: 192.168.5.1
[16:54:22][C][wifi:298]:   DNS1: 192.168.5.1
[16:54:22][C][wifi:299]:   DNS2: (IP unset)
[16:54:22][C][uart:140]: UART Bus:
[16:54:22][C][uart:142]:   TX Pin: GPIO4
[16:54:22][C][uart:145]:   RX Pin: GPIO5
[16:54:22][C][uart:147]:   Baud Rate: 9600 baud
[16:54:22][C][uart:148]:   Stop bits: 1
[16:54:22][C][uart:152]:   Using software serial
[16:54:22][C][modbus:096]: Modbus:
[16:54:22][E][uart:390]:   Invalid stop bits: Integration requested stop_bits 2 but you have 1!
[16:54:22][C][logger:175]: Logger:
[16:54:22][C][logger:176]:   Level: DEBUG
[16:54:22][C][logger:177]:   Log Baud Rate: 115200
[16:54:22][C][logger:178]:   Hardware UART: UART0
[16:54:22][C][pzemac:061]: PZEMAC:
[16:54:22][C][pzemac:062]:   Address: 0x01
[16:54:22][C][pzemac:063]: Voltage 'PZEM-004T V3 Voltage'
[16:54:22][C][pzemac:063]:   Unit of Measurement: 'V'
[16:54:22][C][pzemac:063]:   Accuracy Decimals: 1
[16:54:22][C][pzemac:063]:   Icon: 'mdi:flash'
[16:54:22][C][pzemac:065]:   Accuracy Decimals: 1
[16:54:22][C][pzemac:065]:   Icon: 'mdi:power'
[16:54:22][C][pzemac:066]: Frequency 'PZEM-004T V3 Frequency'
[16:54:22][C][pzemac:066]:   Unit of Measurement: 'hz'
[16:54:22][C][pzemac:066]:   Accuracy Decimals: 1
[16:54:22][C][pzemac:066]:   Icon: 'mdi:current-ac'
[16:54:22](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[16:54:22](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[16:54:22](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[16:54:22](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[16:54:22][C][captive_portal:169]: Captive Portal:
[16:54:22][C][ota:029]: Over-The-Air Updates:
[16:54:22][C][ota:030]:   Address: 192.168.5.239:8266
[16:54:22][C][ota:032]:   Using Password.
[16:54:22][C][api:095]: API Server:
[16:54:22][C][api:096]:   Address: 192.168.5.239:6053
[16:54:42][D][pzemac:046]: PZEM AC: V=130.0 V, I=0.000 A, P=0.0 W, F=60.0 Hz, PF=0.00
[16:54:42][D][sensor:092]: 'PZEM-004T V3 Voltage': Sending state 130.00000 V with 1 decimals of accuracy
[16:54:42][D][sensor:092]: 'PZEM-004T V3 Current': Sending state 0.00000 A with 3 decimals of accuracy
[16:54:42][D][sensor:092]: 'PZEM-004T V3 Power': Sending state 0.00000 W with 1 decimals of accuracy
[16:54:42][D][sensor:092]: 'PZEM-004T V3 Frequency': Sending state 60.00000 hz with 1 decimals of accuracy
[16:54:43][D][sensor:092]: 'PZEM-004T V3 Power Factor': Sending state 0.00000  with 2 decimals of accuracy

But Esphome shows my pzem as OFFLINE, any clues?

Is it though? Can you ping it? Does HA see it?

Sorry! My bad… After going to the integrations tab and Add pzem, I can see the sensors!
But the Esphome its still showing as OFFLINE

Glitch in the matrix.

Probably yeap! :smiley:
But I still need to fix it… :wink:

Why? Its working isn’t it?

This is usually caused by mDNS not working. see https://esphome.io/guides/faq.html?highlight=mdns

Thanks @nickrout, worked perfectly!

Someone knows a complete and clear guide on how to do this