Esphome ct calmp sct-013-000 and nodemcu

Thank you! The template was the part I was missing to get the second value to report to HA!

To be honest I have kind of migrated away from my original scheme and now use the PZEM-004 t
https://www.aliexpress.com/item/4000558302474.html?spm=a2g0o.productlist.0.0.795aea91zbaLDd&algo_pvid=f52d6305-6444-48ca-9848-c744910591af&algo_expid=f52d6305-6444-48ca-9848-c744910591af-3&btsid=0bb0624516214117394447424ef192&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_
Far more accurate and very easy to communicate with.

I don’t modify my PZEM like some do, I just use a level shifter.

my code

# WeMos D1 Mini PZEM 004T V3 #

# Substitutions
substitutions:
  # Device Names
  device_name: "pzem_004t_v3_d1_mini"
  friendly_name: "PZEM 004T V3 D1 Mini"
      
esphome:
  name: pzem_d1_mini
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "XXXX"
  password: "xxxxxx"
  power_save_mode: none

  manual_ip:  
   static_ip: 192.168.0.104
   gateway: 192.168.0.2
   subnet: 255.255.255.0  


  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "PZEM004T V3 D1 Fallback Hotspot"
    password: "A1i5751c9OoJ"

captive_portal:

# Enable logging
logger:
  level: DEBUG
  baud_rate: 0

# Enable Home Assistant API
api:

ota:

# Enable Web server.
web_server:
  port: 80
  
text_sensor:
  - platform: version
    name: "ESPHome Version ${friendly_name}"
    
# Example configuration entry

  - platform: wifi_info
    ip_address:
      name: ESP IP Address ${friendly_name}
    ssid:
      name: ESP Connected ${friendly_name}
    bssid:
      name: ESP Connected ${friendly_name}
      
      
time:
  - platform: homeassistant
    id: homeassistant_time

    


# LCD Display
i2c:
  sda: D2
  scl: D1
  scan: True
  
display:
  - platform: lcd_pcf8574
    id: mydisplay
    dimensions: 20x4
    address: 0x27
    lambda: |-
      it.printf(0, 0, "DAILY ENERGY:%.1f kWh", id(${device_name}_daily_energy_total).state);
      it.printf(0, 1, "POW:%.1f W", id(${device_name}_power).state);
      it.printf(10, 1, "AMPS:%.1f A", id(${device_name}_current).state);
      it.printf(0, 2, "%.1fV", id(${device_name}_voltage).state);
      it.printf(8, 2, "%.1fPF", id(${device_name}_power_factor).state);
      it.printf(14, 2, "%.1fHz", id(${device_name}_frequency).state);
      it.strftime(0, 3,"%H:%M %d.%m", id(homeassistant_time).now());
      it.printf(12, 3, "%.1f db", id(${device_name}_wifi_signal).state);

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

sensor:
  - platform: pzemac
    current:
      name: "${friendly_name} V3 Current"
      id: "${device_name}_current"
    voltage:
      name: "${friendly_name} V3 Voltage"
      id: "${device_name}_voltage"
    energy:
      name: "${friendly_name} V3 Energy"
      id: "${device_name}_energy"
    power:
      name: "${friendly_name} V3 Power"
      id: "${device_name}_power"
    frequency:
      name: "${friendly_name} Frequency"
      id: "${device_name}_frequency"
    power_factor:
      name: "${friendly_name} V3 Power Factor"
      id: "${device_name}_power_factor"
      unit_of_measurement: pf
    update_interval: 2s

  - platform: total_daily_energy
    name: "${friendly_name} Total Daily Energy"
    id: ${device_name}_daily_energy_total
    power_id: ${device_name}_power
    filters:
        # Multiplication factor from W to kW is 0.001
        - multiply: 0.001
    unit_of_measurement: kWh
    icon: mdi:counter

  - platform: integration
    name: "${friendly_name} Energy Meter" 
    sensor: ${device_name}_power
    time_unit: h
    filters:
     # Multiplication factor from W to kW is 0.001
      - multiply: 0.001
    unit_of_measurement: kWh
    icon: mdi:counter
    
    
  # Sensors with general information.

  # Uptime sensor.
  - platform: uptime
    name: ${friendly_name} V3 Uptime
    id: "${device_name}_uptime"

  # WiFi Signal sensor.
  - platform: wifi_signal
    name: ${friendly_name} V3 WiFi Signal
    id: "${device_name}_wifi_signal"
    update_interval: 60s

binary_sensor:
  - platform: status
    name: "${friendly_name} V3 Status" 
   

status_led:
  pin:
     number: D4
     inverted: false   

Regards,

Do you wire the board as the schematic on aliexpress shows and put mains power to the board?

Yes mains and the CT to the PZEM.

I also added

to power the LCD and with a diode in series on the 5VCC on the D1 mini.

Interface between the PZEM and D1 with a level shifter.

Works a charm and very accurate.

Gives you
Power (W)
Volts
amps
PF
Frequency
KWh totals

Where can I get one of this to buy in the USA?

Hi, I am trying to do the same as you but I am not sure that I understand how
Is this schematic correct?


Edit
I’ve just read this:

And according to the formula on that site I need a 23.335 Ohm resistor so I am using 2 47Ohm resistors in parallel

The SCT-013-xxx CT Clamp does not need the burden resistor (shown in your diagram as “66”), The CT Clamp has this in it already. Other than that your diagram is correct. But one thing, there is an issue with these cheap clamps. The shielding may be connected to the ring, causing interference. Suggested to cut the plug off and hard wire.

1 Like

Wonder if anyone can help with calibrating my readings. Using a SCT-013 clamp and this SCT013 board (ESP8266 Mains Current Sensor - Wemos - Current transformer - SCT013 - 100A/50mA | eBay) with a D1 mini board. Using the below values for calibration results in negative values for current and watts. These values at @240v

    filters:
      - calibrate_linear:
          - 0 -> 0
          - 0.01780 -> 4.72  # 1134w microwave (700w)
          - 0.03571 -> 11.26 # 2702w kettle (2520-3000w)

Sorry, I’m new to this and I get this error

1 Like

I believe you are missing a time component.

Either use

time:
  - platform: sntp
    id: my_time

or

time:
  - platform: homeassistant
    id: homeassistant_time
1 Like

It was perfect. I would like to add it in the Energy integration. How would I convert it to kWh? Sorry for the bother

Change "unit_of_measurement: ‘kW’ " for KWh, I don’t know if it’s right, but it appeared to me to integrate it in Energy

I’m not sure what you mean, there is an example of how to change W the kW in the post you referenced, kWh is a measurement of power used over a period of time.

I think in order for this integration to be added to the Energy Dashboard, you have to add it to the Recorder. Again, I’m not sure, but I think I’m right.

I don’t know if I did the right thing when converting from kw to kwh, but I wanted to do it to put it here

Looking at my ESP energy meter, I have the following.

    total:
      name: 'Full House Energy Meter Total'
      id: sensor_total_energy
      unit_of_measurement: 'kWh'
      icon: mdi:circle-slice-3
      state_class: total_increasing
      device_class: energy
      accuracy_decimals: 3
      filters:
        - lambda: return x * (1.0 / 1000);

If this is incorrect, I’m leaving the conversation for now, it’s late and I’m a little drunk :slight_smile:

I have connected a SCT-013-xxx (20A) CT Clamp exactly as described above, but I am not getting any readings via esphome. As soon as the sensor is connected: NaN. Without the sensor, the values fluctuate.
I have already cut off the connector and soldered it, no improvement. The contacts are correct, I have checked them several times. Even with a load of almost 9A: no measurement. I have already replaced the sensor and don’t know what to do. The capacitor points with negative to GND, doesn’t it?
It should not be due to the calibration, I have already tested the most different variants. The same with the ‘internal’ option.
Does anyone have any ideas? 🤷

with SCT013, it´s possbile to measure bidirecional current ?