After seeing the introduction of the Energy section in Home Assistant, I wanted to get onboard with monitoring the homes electricity consumption.
The CT clamp from an old wireless Efergy elite energy monitor can be used.
There are no codes wrote on this, so it wasn’t clear at the time if there was a burden resistor already fitted.
With a customised clampable extension lead, an accurate plug in power monitor and an oscilloscope, I was able to measure the AC voltage coming out of the clamp.
After some trial and error, I used a 22 Ohm burden resistor and a 2KW fan heater.
The peek to peek voltage on the clamp was just under 0.5 volts AC
This means its possible to read up to 12KW (52amps @ 230v)
At this current, the clamp will read about 3v AC (upper limit of the ESP32 ADC)
4KW is generally the maximum load that we use at home, so should be ok, although I might lower the burden resistor value in the future.
The circuit was built based on the one that’s everywhere online. The image is using my own resistor values.
I will be re-building this circuit and put it all in an enclosure.
This was just a (very) rough quick build !
There is also another 10uF cap across the 3.3v supply. Its not included in the circuit diagram. In all honesty, its probably not even needed.
After hooking it all up, figuring out the code and the calibration values, everything works great:
esphome:
name: electricity-monitor
platform: ESP32
board: esp32dev
wifi:
networks:
- ssid: !secret wifi_ssid1
password: !secret wifi_password1
- ssid: !secret wifi_ssid2
password: !secret wifi_password2
manual_ip:
static_ip: 192.168.0.223
gateway: 192.168.0.1
subnet: 255.255.255.0
captive_portal:
api:
ota:
sensor:
- platform: ct_clamp
sensor: adc_sensor
name: "raw"
update_interval: 10s
accuracy_decimals: 5
- platform: ct_clamp
sensor: adc_sensor
sample_duration: 300ms
name: "Electricity usage (amps)"
update_interval: 10s
accuracy_decimals: 3
filters:
- calibrate_linear:
- 0.003 -> 0
- 0.147 -> 8.63 # value as per power plug
- platform: ct_clamp
sensor: adc_sensor
sample_duration: 300ms
name: "Electricity usage"
id: esp_watts
update_interval: 10s
accuracy_decimals: 3
filters:
- calibrate_linear:
- 0.003 -> 0
- 0.147 -> 8.63 # value as per power plug
- lambda: return x * 230.0 / 1000;
unit_of_measurement: "Kw"
- platform: adc
pin: A0
id: adc_sensor
attenuation: 11db
# name: "Volts"
update_interval: 10s
#========================
- platform: total_daily_energy # This sensor will give you a Daily kW reading
name: "Total Daily Energy"
unit_of_measurement: 'kWh'
power_id: esp_watts
accuracy_decimals: 3
filters:
device_class: energy
time:
- platform: sntp
id: my_time
I’m surprised and impressed just how accurate this is.
As of writing this, its been running for almost 24 hours now and has been spot on.
I originally attempted to get this to work with an ESP8266 - nodemcu version.
It worked - sort of, but was not accurate and picking up noise which sent the numbers all over the place.
This was before I realised what the burden resistor was for.
If it wasn’t for the low resolution of the 8266s analogue connection, I would pursue this - just for the hell of it !!
Please let me know if you have any comments/suggestions/questions.
I’m aware the code could be more efficient. Feel free to suggest improvements.
Some of the code was just to see visually what’s going on during the calibration process (easier to look at on a dashboard compared to the log file).
Enjoy,
Ian.