How to use PZEM004T Energy Monitor with esphome

Thank you. Will try it out :slight_smile:

Hey pod

Do you have a wiring digram for this?

regards

:point_down:

Thanks for that?

Can i use any Schottky Diode?

:point_down:

Thanks for that kinda obvious and i didnt see it sorry

Everyone mentions NodeMCU

am i able to get away with a wemos with 3 PZEM?

Yes, virtually every esp (8266 or 32) should do the trick.

cool thanks for the help

Can you see any issues with this?

1 Like

Hello, is it possible to use PZEM-004T with Shelly EM 50A Current Transformer Clamp?

Probably not. The pzem004t comes with a coil or clamp included and that is probably factory calibrated to deliver a good accuracy. Also pzem004t versions only exist ether with 10A or 100A coils/clamps so a 50A clamp will most likely deliver wrong values.

If I am not mistaken you schematic is not quite correct.
From my understanding the point of the diodes is to protect Wemos Rx pin from overvoltage(5V from PZEM004T). Wemos pins are 3.3V tolearant. So you need to create 5V to 3.3V logic level shifter using those diodes and pull up resistor. The way you connected pull-up resistor (on 5V rail) defeats the purpose of the diodes. Should be connected to 3.3V.

ESP Pins logic is indeed 3.3V but they are 5V tolerant.

I typically use all sensors/actors that support 5V directly with esp’s since years without any problems. I also use pzem004t’s without any level shifter and they work a treat.

Search for JST-XH 2.54

3 Likes

Would there be any issue with extending the wires on the split core ct clamp?

Hello there, do i need to do for each PZEM at start-up and then do the normal configuration?

I don’t think so.

Here is how I made my devices.

So far I made 10 of these. I’m using a generic bar soap case as an enclosure. Soap cases are less than 1 USD.

I’m using a cheap bidirectional 5V-3V digital converter module to power the ESP01 with 5V and also to allow bidirectional communication with 5V serial TTL with PZEM. Also I’m using a simple USB TTL converter for ESP01 for programming. I’ve added a switch to put it into programming mode and a button to reset.

Power supplies are 5V USB chargers. I bought 25 of them from Amazon at 1 USD each when they were on sale. They are about 5 USD each now which is still a bit cheaper than they can go for.

I’m using computer power cables with IEC connectors. I cut the IEC connector and add a female mains connector. I using cable ties to keep the power cables from moving.

The way I wired the PZEM module allows me to measure its own consumption as well as the 5V power supply in addition to the load.

Here is the ESPHome code.

substitutions:
  device_description: "Fridge"

esphome:
  name: powermeter-10
  comment: '${device_description}'

esp8266:
  board: esp01_1m

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:

ota:
  password: "*****"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Powermeter-10 Fallback Hotspot"
    password: "*****"

captive_portal:

uart:
  tx_pin: GPIO1
  rx_pin: GPIO3
  baud_rate: 9600

modbus:

sensor:
  - platform: pzemac
    current:
      name: "PM-${device_description} Current"
    voltage:
      name: "PM-${device_description} Voltage"
    power:
      name: "PM-${device_description} Power"
    energy:
      name: "PM-${device_description} Energy"
    frequency:
      name: "PM-${device_description} Frequency"
    power_factor:
      name: "PM-${device_description} Power Factor"
    update_interval: 2s   

Here are the pictures:

5 Likes

Hi, I assembled the circuit as shown in the previous messages and once mounted in the electrical panel it ran smoothly for 2 days. This morning I realized that the data was no longer available and even restarting it did not solve the problem. I disassembled the meter and I did not notice any hardware problems, so I reconnected it but after some time the led of the nodemcu started flashing very quickly and then it went out. It hasn’t given any signs of life since and I can’t even flash the firmware again. What may have happened? My configuration is this:

esphome:
  name: "pmeter"

esp8266:
  board: nodemcuv2

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "*********"

ota:
  password: "*****"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Power-Meter Fallback Hotspot"
    password: "*****"

captive_portal:


uart:
  - id: ubus1
    tx_pin: GPIO1
    rx_pin: GPIO3
    baud_rate: 9600
    stop_bits: 1   
    

time:
  platform: sntp
  id: my_time
  
  on_time:
      - seconds: 57
        minutes: 59
        hours: 23
        then:  
          - sensor.template.publish:
              id: template_pMeter_veille
              state: !lambda return id(pMeter_power_of_day).state;
  
sensor:
   
     #### PZEM-004T V3 ####
    
  - platform: pzemac
    address: 1
    current:
      name: "Power Meter - Corrente"
      accuracy_decimals: 2
    voltage:
      name: "Power Meter - Tensione"
      accuracy_decimals: 2
    power:
      name: "Power Meter - Potenza Attiva"
      unit_of_measurement: W
      accuracy_decimals: 2
      id: pMeter_power
    frequency:
      name: "Power Meter - Frequenza"
      unit_of_measurement: Hz
      accuracy_decimals: 2
    power_factor:
      name: "Power Meter - Fattore di potenza"
      accuracy_decimals: 2
      id: pMeter_power_factor
    energy:
      name: "Power Meter - Energia"
      unit_of_measurement: Wh
      accuracy_decimals: 1
      id: pMeter_energy
    update_interval: 5s


  - platform: template
    name: "Power Meter - Potenza cumulativa"
    unit_of_measurement: "kWh"
    accuracy_decimals: 1
    update_interval: 5s
    icon: mdi:power
    lambda: return (( (id(pMeter_energy).state)/1000.0));
    
  - platform: total_daily_energy
    name: "Power Meter - Energia giornaliera"
    power_id: pMeter_power 
    unit_of_measurement: "kWh"
    accuracy_decimals: 2
    id: pMeter_power_of_day
    filters:
        # Multiplication factor from W to kW is 0.001
        - multiply: 0.001
    icon: mdi:counter
    
  - platform: template
    name: "pMeter_veille"
    id: template_pMeter_veille
    unit_of_measurement: "kwh"
    accuracy_decimals: 2
    icon: mdi:power
    update_interval: 10s
    
  - platform: template
    name: "Power Meter - Potenza Apparente"
    id: pMeter_power_apparente
    unit_of_measurement: "VA"
    accuracy_decimals: 2
    update_interval: 5s
    icon: mdi:power
    lambda: return ((id(pMeter_power).state/id(pMeter_power_factor).state));
  
  - platform: template
    name: "Power Meter - Potenza Reattiva"
    id: pMeter_power_reactive
    unit_of_measurement: "VAr"
    accuracy_decimals: 2
    update_interval: 5s
    icon: mdi:power
    lambda: return (( sqrt( (id(pMeter_power_apparente).state)*(id(pMeter_power_apparente).state)   -  (id(pMeter_power).state)*(id(pMeter_power).state) ) ));
    
  - platform: wifi_signal
    name: "WiFi Power Meter - Potenza segnale wifi"
    update_interval: 10s
    
  - platform: uptime
    name: "up"
    id: uptime_sec    
 
switch:
  - platform: restart
    name: "Power Meter - Riavvio"
    
    
binary_sensor:
  - platform: status
    name: "Power Meter - Stato"    
    
    
text_sensor:
  - platform: template
    name: Power Meter - Uptime
    lambda: |-
      int seconds = (id(uptime_sec).state);
      int days = seconds / (24 * 3600);
      seconds = seconds % (24 * 3600); 
      int hours = seconds / 3600;
      seconds = seconds % 3600;
      int minutes = seconds /  60;
      seconds = seconds % 60;
      return { (String(days) +"d " + String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
    icon: mdi:clock-start
    update_interval: 113s

How are you converting 3.3V - 5V serial communication?

I would like to replicate your project, however, I didn’t find the diagram. Is there any? What module has been used? thanks