OVERVIEW
This is a hardware and software project, where:
- while the hardware is pretty standard (ESP32 and a few common components),
- the software is completely based on ESPHome and Home Assistant. In the unlikely case you don't know what they are, i strongly suggest to follow the links and study them a little.
PREREQUISITES
A) In addition to knowing something about ESPHome, to build this project and test it you need only to have a local instance of Home Assistant and its ESPhome integration.
See also SIMPLE USAGE below.
B) Instead, if you want to build and eventually modify the software, you need to:
- install a local instance of ESPhome Command Line (the development environment)
- install Visual Studio Code or use your code editor of choice
- install a local instance of Home Assistant in a computer of your choice (I strongly suggest a dedicated Raspberry PI)
See also SOFTWARE ADVANCED USAGE below.
HARDWARE
Simple, standard and cheap.
It is based on an ESP32. I chose a D1 mini but any version with at least 3 Analog to Digital inputs is OK.
The "AC transformer" has the only purpose to get a signal proportional to the mains. R6 and R1 reduce the sinusoidal 220V AC voltage signal to something less 1 Vpp. If you have 110V, simply change R1 to 270K.
R5 and R7 (27 Ohm) let to obtain around 800 mVpp when a current of 30App flows into the 1:1000 Current Transformer Clamp. If you have an AC transfomer with a different ratio, or you need a different current range, simply change R5 and R7 values.
ASSEMBLY
I assembled the few components on a matrix board but I'm talking with Elecrow to design a PCB.
On the top left you see the big AC transformer, as i I didn't find a smaller one. However any 220V to 5 10 12 15 18 24 or any other out voltage can be ok.
Below it there is 300mA delayed fuse
On the left bottom you see the micro 220V - 5V power supply
THE CURRENT TRANSFORMER
It's really trivial to install it.
Simply open the top of the PZCT-02, or any other Clamp Current Transformer you have, and let only one AC wire pass through its large hole.
SIMPLE USAGE
If you copy my hardware schematic you can use my "ESPHome external component" to integrate it into ESPHome and Home Assistant without any programming. To do this:
- simply get my ct_power_clamp_test.yaml file
- uncomment this:
# use this if your external component is on Github external_components: - source: type: git url: https://github.com/guido57/ESP32-power-meter components: [ct_power_clamp]
and comment this:
# use this if your external component is in a local directory e.g. components external_components: - source: components components: [ct_power_clamp]
and you're ready to go as you do with any other ESPHome integration.
FINE TUNING
As you'll probably have the "AC Voltage Transformer" and/or the "AC Current Transformer" different from mine, you have to tune the sensors multiplying the read values by a different number, as the following:
voltage_sensor: # the mains AC RMS voltage measured by an adc input through an AC transformer
sensor_id: adc_voltage_sensor
id: voltage
name: "Voltage"
filters:
- multiply: 1099
accuracy_decimals: 0
How to tune:
- A = measure the real voltage with an RMS multimeter
- B = read the voltage value measured by the ct_power_clamp using the 1099 multiplier
- Calculate the correct multiplier to substitute 1099 as: 1099 X A / B
- Do the same for power1_sensor and power2_sensor using a power meter (if you have it)
If you don't have a portable power meter you can use the one of you electricity supplier (the main power meter of your house):
- connect a 220V resistive (e.g. an electric oven without fan) appliance as the unique load
- P = read the power in your home power meter
- C = read the power value measured by the ct_power_clamp using the 41017 multiplier
- calculate the correct multiplier to substitute 41017...