Esphome ct calmp sct-013-000 and nodemcu

There is no need for the 3.3v connection. The sense current will be produced by the current flowing in the wire you are measuring. So 66R in parallel with CT. One end of CT to GND other end to A0 (polarity is important!). If you want to protect the ADC input you can connect a Schottky diode from A0 (anode) to 3.3V (cathode). That way the voltage produced will flow to the supply rail if it exceeds 3.3V+Vf of the diode.

No need for the external divider. Use the 10uF (and possibly a 0.1uF as well) between A0 and ground if noise is a problem. Keep the capacitor leads as short as possible and as close to A0 and GND as possible.

Hi,
Not having much luck, not getting any output / input and just wondering if it has anything to do with the CT type, I have put the link below to the CT and my model is SCT013 100A:50mA.

Data sheet states ※ Output type: voltage output type built-in sampling resistor, current output type built-in protective diode.

Data Sheet

You mentioned before polarity is important and according to the data sheet the plug is labelled as L output and K output? is the output not AC as I have been able to measure AC mV between A0 and GND.

so to summarise what I have tried…

CT L Output to GND
CT K Output to A0
Burden resistor 60 ohm parallel accross L Output and K Output
10 uF Cap between GND and A0.

I have tried swapping the leads of the CT, no change.

Multi meter connected between GND and A0.

Regards,

Ah crap. I was stupidly assuming it was DC output. Forget everything I said. Your original circuit is correct.

See:

https://openenergymonitor.org/forum-archive/node/156.html

So all up and running wired as per my original config with 22 ohm burden resistor but my issue is with the erratic reading at zero amps.

image

This can affect the calibrated reading anywhere between 0 and 0.5 Amps, not ideal.

Is there anyway to factor this out in the calibration, something like

    filters:
      - calibrate_linear:
          - 0.00040 -> 0.0
          - 0.01393 -> 3.54
          - 0.02442 -> 6.56
          - 0.02455 -> 6.59

< 0.00100 -> 0.0 ?

I did see some example of

lambda Filter
filters:
  - lambda: return x * (9.0/5.0) + 32.0;

or am i off track?

Is there anything else other than the 10uF cap I can add to the circuit?

Regards,

I just saw your thread now, I have the same issue… My setup:
image

I get just crap. 0.46V all the time from the adc_sensor until I remove it from the A0 .
I use a Amica Nodemcu

Hi, my setup is working Okay and is repeatable, just trying to find a way to offset the zero.

So In my configuration I added another sensor to monitor the raw reading when I have the calibrate linear filter applied to the main Measured Current…

  • platform: ct_clamp
    sensor: adc_sensor
    name: “raw values”

If you look at your logs you will see for example 0.01801 represents 6.42298 A, this is implemented in the filters, - calibrate_linear:

forget using the adc_sensor for your reading.

[14:15:52][D][sensor:092]: 'adc_sensor': Sending state 0.41895 V with 2 decimals of accuracy

[13:49:04][D][sensor:092]: ‘raw values’: Sending state 0.01801 mA with 5 decimals of accuracy
[13:49:07][D][ct_clamp:051]: ‘Measured Current’ - Raw Value: 0.02A
[13:49:07][D][sensor:092]: ‘Measured Current’: Sending state 6.42298 A with 2 decimals of accuracy
[13:49:14][D][ct_clamp:051]: ‘raw values’ - Raw Value: 0.02A
[13:49:14][D][sensor:092]: ‘raw values’: Sending state 0.01807 mA with 5 decimals of accuracy

My config, I added the "raw values so I could log the values easier.

sensor:
  - platform: ct_clamp
    sensor: adc_sensor
    name: "Measured Current"
    update_interval: 10s
    filters:
      - calibrate_linear:
          - 0.0 -> 0
          - 0.01826 -> 5.15
          - 0.01952 -> 6.754
          - 0.01925 -> 7.09
          - 0.04057 -> 16.02
          - 0.07834 -> 31.37
            
          
  - platform: adc
    pin: 17
    id: adc_sensor


  - platform: ct_clamp
    sensor: adc_sensor
    name: "raw values"
    update_interval: 10s
    unit_of_measurement: mA
    accuracy_decimals: 5   

My setup for the initial calibration.

Portable electric heater with low (3.5 A) and high (6.9 A) low/high selector, CT and Multi meter in series measuring amps.

so taking the reading from the logs and then writing the linear values in the configuration gives a good repeatable reading.

My issue is when the load is zero i get an erratic reading. drifting between 0.2 a 0.5 A.
For the higher calibration values i transferred my setup to measure the main incoming supply to the house.
I then was able to put increased loading on the the CT as my Fluke can measure 10 Amps max,

With this I was able to calibrate the higher loads,16 A and 31 A by comparing readings from my smart meter and the readings from the log and modified the calibration linear table accordingly.

Thank you, I will try this and see if I can get it to work

did you get this working? Im stuck at the same level you were.

Hi,
I´m trying to connect a SCT013-20A-1V to ESPhome.
I cannot find any schematics for this CT (1V). Do you know where i can find one?!"

Best regards
Petter

Hi,

Use this

remove R1 burden resistor as your CT has it inbuilt.

Also have a look at

Regards,

1 Like

Sweet!
Works fine now!
Thanks a lot!

@MarkB1,
I’m trying to do the same thing with the SCT013 100A/50mA.
Can you share your final wiring diagram and ESP code? I want to do this with a D1 mini, I assume I can just map the pins from the nodemcu to the D1 mini?

Thanks!

Get one of these

ESP8266 Mains Current Sensor - Wemos - Current transformer - SCT013 - 100A/50mA

code

esphome:
  name: wemos_d1_mini_1
  platform: ESP8266
  board: d1_mini
  
  
wifi:
  ssid: 
  password: 
  power_save_mode: none
  
  manual_ip:  
   static_ip: 192.168.0.107
   gateway: 192.168.0.2
   subnet: 255.255.255.0
   
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Wemos D1 Mini 1 Fallback Hotspot"
    password: "VGaeoNIRWbVa"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:


# Enable Web server.
web_server:
  port: 80


text_sensor:
  - platform: version
    name: "ESPHome Version Wemos D1 Mini 1"

    
# Example configuration entry

  - platform: wifi_info
    ip_address:
      name: ESP IP Address Wemos D1 Mini 1
    ssid:
      name: ESP Connected SSID Wemos D1 Mini 1
    bssid:
      name: ESP Connected BSSID Wemos D1 Mini 1
      
      
# Sync time with Home Assistant.
time:
  - platform: homeassistant
    id: homeassistant_time

binary_sensor:

  - platform: status
    name: "wemos_d1_mini_1 Status"  
    
sensor:
  - platform: ct_clamp
    sensor: adc_sensor
    name: "Measured Current"
    update_interval: 10s
    filters:
      - calibrate_linear:
          - 0.00009 -> 0.0
          - 0.01300 -> 1.6
          - 0.01438 -> 1.94
          - 0.02088 -> 3.25
          - 0.02184 -> 3.51
          - 0.02312 -> 3.72
          - 0.02600 -> 4.34
#          - 0.02740 -> 5.0
#          - 0.04340 -> 6.75
#          - 0.08990 -> 17.1
            
          
  - platform: adc
    pin: A0
    id: adc_sensor   
    
    
# Sensors with general information.


  # Uptime sensor.
  - platform: uptime
    name: Wemos D1 Mini 1 Uptime


  # WiFi Signal sensor.
  - platform: wifi_signal
    name: Wemos D1 Mini 1 WiFi Signal
    update_interval: 60s


status_led:
  pin:
     number: D4
     inverted: FALSE
5 Likes

That’s a super neat and clean little board!

I have a question, how do you get voltage reported to HA?

I can get the Amperage with the ct_clamp platform no problem, but I cannot wrap my head around implementing lamda to do the math and send both amps and voltage to HA.

Instead of relying on the terrible ESP8266 ADC, and you will get a lot more information:

I don’t believe you can get Voltage from the sensor (assuming you are talking about the mains voltage.
If you mean the Voltage reading from the clamp then change the internal: to false as I have done below:

  - platform: ct_clamp
    sensor: adc_sensor
    name: "raw values"
    internal: false
    update_interval: 10s
    unit_of_measurement: mA
    accuracy_decimals: 5

I just thought I’d put my config in here if anyone likes the look of it, it deesn’t report any fluctuations below 0.1A, can be changed.

sensor:
  - platform: ct_clamp
    sensor: adc_sensor
    name: "True Current"                # This first sensor gets the Amps, note that is set to internal only.
    id: the_clamp
    internal: true
    update_interval: 10s
    filters:
      - calibrate_linear:               # Calibrate your own stuff here, mine is only used for the car charger, therefore I'm pulling approx 28A
          - 0.00026 -> 0.0
          - 0.02856 -> 8.37
          - 0.09489 -> 27.9

  - platform: template
    name: "ESP8266 Current"             # This sensor is the one that gets seen by HA, if the reading is below 0.1A then it reports 0, keeps your 0 at 0
    id: templated_sensor
    lambda: |-
      if (id(the_clamp).state > 0.1){
        return (id(the_clamp).state);
      } else {
        return 0.0;
      }
    device_class: current
    update_interval: 10s
    accuracy_decimals: 2
    unit_of_measurement: A

  - platform: template
    name: "ESP8266 Watts"               # This sensor converts the Amps to Watts (this is assuming that your voltage is 230, if not change the 230 accordingly)
    id: esp_watts
    lambda: |-
      return id(templated_sensor).state * 230;
    accuracy_decimals: 2
    update_interval: 10s
    device_class: power
    unit_of_measurement: W
                   
  - platform: total_daily_energy        # This sensor will give you a Daily kW reading
    name: "ESP8266 Daily Energy"
    unit_of_measurement: 'kW'
    power_id: esp_watts
    filters:
      - multiply: 0.001
    device_class: energy

  - platform: adc
    pin: A0
    id: adc_sensor   

  - platform: ct_clamp
    sensor: adc_sensor
    name: "raw values"
    internal: true
    update_interval: 10s
    unit_of_measurement: mA
    accuracy_decimals: 5
4 Likes

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?