Esphome ct clamp 30A/1V

How are you measuring the voltage? It should average to 1.643VDC, with a 50-60HZ AC signal on top of it. The ESP8266 will need to sample the analog input at very high frequencies to be able to ‘see’ the AC signal and convert it into a power reading.

I just measured it with a multimeter on DC between A0 and GND. After your hint with the frequency I put a small test program on the esp:

esphome:
  name: "test"
  platform: ESP8266
  board: d1

logger:
  level: DEBUG

sensor:
  - platform: ct_clamp
    sensor: adc_sensor
    name: "My Current Sensor"
    update_interval: 10s
  - platform: adc
    pin: A0
    id: adc_sensor
    update_interval: 5s

With that i get the following readings (with a 60 Watt light bulb which should be around 260mA):
With load:

[08:18:43][D][adc:056]: ‘adc_sensor’: Got voltage=0.52V
[08:18:43][D][sensor:092]: ‘adc_sensor’: Sending state 0.52051 V with 2 decimals of accuracy
[08:18:48][D][adc:056]: ‘adc_sensor’: Got voltage=0.52V
[08:18:48][D][sensor:092]: ‘adc_sensor’: Sending state 0.52148 V with 2 decimals of accuracy
[08:18:51][D][ct_clamp:051]: ‘My Current Sensor’ - Raw Value: 0.00A
[08:18:51][D][sensor:092]: ‘My Current Sensor’: Sending state 0.00330 A with 2 decimals of accuracy
[08:18:53][D][adc:056]: ‘adc_sensor’: Got voltage=0.52V
[08:18:53][D][sensor:092]: ‘adc_sensor’: Sending state 0.52148 V with 2 decimals of accuracy
[08:18:58][D][adc:056]: ‘adc_sensor’: Got voltage=0.52V
[08:18:58][D][sensor:092]: ‘adc_sensor’: Sending state 0.52246 V with 2 decimals of accuracy
[08:19:01][D][ct_clamp:051]: ‘My Current Sensor’ - Raw Value: 0.00A
[08:19:01][D][sensor:092]: ‘My Current Sensor’: Sending state 0.00329 A with 2 decimals of accuracy

Without load:

[08:18:08][D][adc:056]: ‘adc_sensor’: Got voltage=0.52V
[08:18:08][D][sensor:092]: ‘adc_sensor’: Sending state 0.52344 V with 2 decimals of accuracy
[08:18:11][D][ct_clamp:051]: ‘My Current Sensor’ - Raw Value: 0.00A
[08:18:11][D][sensor:092]: ‘My Current Sensor’: Sending state 0.00017 A with 2 decimals of accuracy
[08:18:13][D][adc:056]: ‘adc_sensor’: Got voltage=0.52V
[08:18:13][D][sensor:092]: ‘adc_sensor’: Sending state 0.52344 V with 2 decimals of accuracy
[08:18:18][D][adc:056]: ‘adc_sensor’: Got voltage=0.52V
[08:18:18][D][sensor:092]: ‘adc_sensor’: Sending state 0.52344 V with 2 decimals of accuracy
[08:18:21][D][ct_clamp:051]: ‘My Current Sensor’ - Raw Value: 0.00A
[08:18:21][D][sensor:092]: ‘My Current Sensor’: Sending state 0.00015 A with 2 decimals of accuracy
[08:18:23][D][adc:056]: ‘adc_sensor’: Got voltage=0.52V
[08:18:23][D][sensor:092]: ‘adc_sensor’: Sending state 0.52344 V with 2 decimals of accuracy
[08:18:28][D][adc:056]: ‘adc_sensor’: Got voltage=0.52V
[08:18:28][D][sensor:092]: ‘adc_sensor’: Sending state 0.52344 V with 2 decimals of accuracy
[08:18:31][D][ct_clamp:051]: ‘My Current Sensor’ - Raw Value: 0.00A
[08:18:31][D][sensor:092]: ‘My Current Sensor’: Sending state 0.00015 A with 2 decimals of accuracy

1 Like

Hey everyone,

i have now switched to an esp32 to measure three phases (the esp8266 was just for testing while I wait for my order to come in).
After wiring up the following circuit:


and uploading (basically the same as above) a test sketch:

esphome:
  name: "test"
  platform: ESP32
  board: nodemcu-32s

logger:
  level: DEBUG

sensor:
  - platform: ct_clamp
    sensor: adc_sensor
    name: "My Current Sensor"
    update_interval: 10s
  - platform: adc
    pin: GPIO34
    id: adc_sensor
    update_interval: 6s

I am at the same point as with the esp8266:

The ADC sensor always reports 1.10V and the ct clamp sensor 0.00005 A. It doesn’t matter if I turn my light bulb (60W/ 0.240A on 230V) on or off.

2 Likes

You do have the clamp only around the live wire, and not both live and neutral?

Yes. It is just around the live wire. With my clamp meter I can measure the 0.240A.

TBH I didn’t think your setup completely through, but when I saw your 1.10V reading, this immediately reminded me of a similar problem I had getting correct values from that sensor:

I’m not sure why you are getting the 1.10V even when the light bulb is off, but you should keep in mind, that you may just always see the maximum voltage an ESP32 ADC sensor returns with the attenuation set to default.

@audacity363

I also had trouble getting the ESPHome CT sensor to work. I created an issue for it.

I was actually able to get good readings using an ESPHome custom component, as I mentioned in the issue description.

Anyone else using the ESPHome CT sensor and is it working for you?

EDIT: I got it working using this suggestion:

As i´m currently also reading into this - maybe of interest, even if it will not fix the issue:

The ADC in the ESP32 has a range of 0 to 1.1v.
The voltage divider sets the midpoint between 0 and 3.3V (= 1.65v) as a DC bias.
1.65V is higher than the max V of the ADC so its saturated.

The ESP32 has an attenuator, and setting it to 11db may help…

I also had a similar problem, after much investigation it turned out I had the incorrect board configured in ESPhome.

It should be;

esphome:
  name: powermonitor
  platform: ESP8266
  board: d1_mini

It had defaulted to the generic board ‘esp01’

I have been using the CT Clamp for over a year and I recently found that when my load is OFF (no current) I get nan - I think this did not happen in the past but not sure:

[D][ct_clamp:038]: 'Water Boiler Power Power [W]' - Raw AC Value: nanA after 2819 different samples (563 SPS)e
[D][sensor:113]: 'Water Boiler Power Power [W]': Sending state nan W with 1 decimals of accuracye

When It is on it seems to work fine

[D][ct_clamp:038]: 'Water Boiler Power Power [W]' - Raw AC Value: 0.106A after 6120 different samples (1224 SPS)e
[D][sensor:113]: 'Water Boiler Power Power [W]': Sending state 0.10638 W with 1 decimals of accuracye

My code is

  - platform: ct_clamp
    sensor: adc_sensor
    name: "${friendly_name} Power [W]" #" Current [A]"
    unit_of_measurement: "W"
    sample_duration: 5s
    update_interval: 10s
    accuracy_decimals: 1

Any thought?

Sorry to ask this 12 months later - but why not use the 5V? I have set up a test with both 5V and 3.3V and both work. Is it for additional voltage from the CT? (I have measured this in case and it is miniscule)

You want to bias the ADC to half its supply rail voltage(3.3V/2 = 1.65 ) so it can pick up the maximum positive and negative voltage swing, +/- 1.65V. If you use the 5V rail it will be biased to 5/2 = 2.5V, allowing a 2.5V negative swing but only 3.3 - 2.5 = 0.8V positive swing.

If your generated voltage from the CT is small enough you won’t notice any difference. Unless the component uses this 1.65v in it’s calculations. However start generating AC voltages bigger than 0.8V and the positive value will clip, giving erroneous results.

2 Likes

Thanks for the explanation. I’ll have to research some more as I have pretty tenuous grasp.

Have a look at these plots:

JSSut

The first blue plot is similar to what comes out of the CT. A sine wave centred on 0V swinging both positive and negative.

The ADC can only measure from 0 to 3.3V (middle red plot).

By shifting the CT output up a constant DC amount (1V in the third magenta graph) The ADC can now measure the full waveform as it is all above 0V.

The position of this DC bias point should be half way between 3.3V and 0 to meaure the maximum possible positive and negative parts of the CT waveform.

Supplying the voltage divider with 5V would shift this bias point too high (2.5V instead of 1.65V).

3 Likes

Thanks @tom_l . Very clear explanation. The CT sensor I am using is from the Emporia Vue2 kit and I’m pretty sure it has something built into it. Only outputs 0-0.333v for the 50A clamp.

How are you measuring the 0 a 3.333v? You should be using a voltmeter set on AC voltage measurement. A Current Transformer monitoring an AC device generates an AC current or voltage, depending on the specific type of device. A normal AC voltmeter will not show any negative values. You need an oscilloscope to show the waveforms above.

Yes just using voltmeter connected to the 2.5mm jack pin of the CT clamp. The AC voltage I am measuring is in perfectly in line with the specs of the CT clamp when I use a known current.

Great! That means the voltage is alternating from positive to negative, and thus the voltage will need to be biased by +1.65v. Otherwise you’ll lose half of the waveform.

# using A6 instead of GPIO34, and setting the attenuation should sort it out.

# add a web server , this will help with debugging, calibration etc. very usefull,
# find the webserver at either 'webserver.local' or at port80 of the esp32's IP eg. 192.468.0.22:80
# to add a webserver include the following:
web_server: 					
 port: 80
 include_internal: true				
 ota: true
 local: true
 version: 2
 id: webserver


# not sure if it makes a diffrence but your code does not specify the framework type, 
# All of my sensors are set as follows:
esphome:
  name: esp32ct
esp32:
  board: esp32dev
  framework:
    type: arduino

# then remember to add time, you need this for daily consumption sensors
# add the following:
time:						
  - platform: sntp
    id: my_time

# then try the following sensors, you will be able to see the following in the front end: 
# your measured current (Amps) 
# your current consumption for the day (AmpHour)
# your measured Power (watts)
# daily power consumption (KiloWhattHour)

# the following should work fine :

sensor:                                       
  - platform: adc                      	# First sensor gets the voltage from the ADC
    pin: A6                       		# GPIO34 is A6
    attenuation: auto			# very imporatant esp32's give whacky results without this...
    accuracy_decimals: 5
    id: adc_sensor

  - platform: ct_clamp			# this internal sensor gives a calibrated 'raw' result 
    sensor: adc_sensor
    name: "Measured Current"
    internal: true
    update_interval: 5s
#    filters:					#uncomment this after calibration
#      - calibrate_linear:
#          - 0.01407 -> 0            
#          - 0.01759 -> 1
    accuracy_decimals: 5    
    id: measured_current

  - platform: template				# this will be the final current reading visible in the front end		
    name: "Current"            
    id: current
    lambda: |-					        # ignore readings below 1 Amp 
      if (id(measured_current).state > 1){ 
        return (id(measured_current).state);
      } else {
        return 0.0;
      }
    device_class: current
    update_interval: 5s
    accuracy_decimals: 2			
    unit_of_measurement: A  
    
  - platform: total_daily_energy		#this will calculate the total current used for the day (AmpHour)
    name: "Daily Current"
    power_id: measured_current
    accuracy_decimals: 2
    unit_of_measurement: Ah
    
  - platform: template				#this sensor will measure your power consumption (Watt)
    name: "Measured Power"            
    id: power
    lambda: |-
      return id(ct1_current).state * 235; 	#change the 235 to whatever your voltage is
    accuracy_decimals: 2
    update_interval: 5s
    device_class: power
    unit_of_measurement: W
    
  - platform: total_daily_energy  		#this will keep track of power consumed daily (kwh)      
    name: "Total Daily Power Consumption"
    unit_of_measurement: kWh
    power_id: power
    accuracy_decimals: 2
    filters:
      - multiply: 0.001
    device_class: energy


#hope this helps, this works on my esp32's , cant see why it wont work on yours.
##cheers
6 Likes