OVERVIEW

This is a hardware and software project, where:

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:

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: 

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:

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):

SOFTWARE FOR ADVANCED USAGE

In a few cases, but especially when the sensors are not standard (home made sensors, hacked sensors), you need to write some code. 

Here it comes the funny part, because the procedure I adopted to write this code can be followed not only for this but also for any other similar ESPHome project. 

The code I wrote, how to build and install it and many other details are in my Github repository