ESP32 + CT clamp - Calculations for measuring energy consumption

Hi, I’m planning to build an energy meter to calculate the power consumption of my home (16A maximum at 230V) using an ESP32 connected to Home Assistant with ESPhome. For measuring current, I wanted to use a CT clamp, like the SCT-013, connected to my ESP32 following this schematic (or something similar):

When it comes to calculating the power consumption in Watts, reading online I found out that there are two different approaches to this:

  1. Configure the the CT clamp in ESPhome following the example (CT Clamp Current Sensor — ESPHome) and using another power meter and a load calculate the linear calibration values for getting an amps reading from the CT clamp; then multiply the amps by the voltage (230V) to get Watts
  2. Other than the CT clamp, connect to the ESP32 a small transformer to measure the grid voltage as explained in the guides by Open Energy Meter (Measuring AC Voltage with an AC to AC power adapter — OpenEnergyMonitor 0.0.1 documentation); then, using Emonlib integrated in ESPhome, calculate the real power taking into account the power factor, that this library is able to calculate

The first method seems to be way simpler to make than the second one, both for the software side and for the electronics, because the circuit is not connected to the mains voltage; due to this, the first option would also be a lot safer, which is not bad for something that runs 24/7.

My question is: as I don’t need a super precise measurement, but only a rough estimate of the home power consumption, is the first method “good enough” in terms of accuracy? Or do I need to use the second method to get some usable data?

If you have any other suggestion from your experience regarding this kind of project, let me know.

Many thanks in advance, have a nice day.

If you don’t have the electronics knowledge and don’t want to build a test bed with dummy loads (resistive, capacitive, inductive), just buy something like a Shelly EM.

Seriously - it’s not worth the risk, nor the hassle. I say that with an advanced degree in microelectronics and software engineering - and a Shelly EM in the distribution board. :slight_smile:

And yes, I know a CT clamp should be galvanicaly isolated, but then there’s powering the ESP, and clamping transients in kit that could be mounted inside switchgear.

If you must buid you own, use a dedicated power measurement chip. These are cheap as they are made in thousands for your energy supplier’s meters and include many clever calibration and linearisation tricks. Look at firmware like Tasmota and the devices they support for suggestions.

Another vote to shelly Em. Reliable and precise. No hassle, no calibration…
Nominal 230 voltage might be anything between 200 and 250, without measuring it together with current, you have very rough estimate of consumption.

Many thanks for the advice!

I think I will abandon the idea of making the whole circuit on my own, as it seems to be quite difficult. So I have found online the quite common PZEM-016 module, that includes a chip that measures both voltage and current (with a CT clamp) and calculates real power on its own. It seems like it can be interfaced with the ESP32 and with ESPhome using a RS485 to TTL converter. All of this would cost around 1/3 compared to the Shelly EM, as I have a single phase circuit (and so I need only one PZEM module). Do you think this would work better? More importantly, in your experience are these modules safe? Consider that I would add both a fuse and a thermal fuse to the mains voltage input of the PZEM module.

Many thanks again

Watch BigClive on YouTube and his adventures in reverse engineering to see the very mixed bag of cheap modular PCBs. Some of the USB chargers scare the hell out of me!

The quality of pre-made PCB modules varies dramatically from “can be made to work” to “likely to explode”.

Some modules are reference designs from a datasheet, some are copies of copies of copies - the latter can be missing rather important parts as the final designer had no idea of the original circuit.

My most hated example was a 12V 4x relay board - ESP12F looked good, but some moron copied the design with an I/O expander chip, and didn’t bother to program the I/O expander creating £10 eWaste that never ever could work (no, not the ESP firmware - the unobtainable ST uP used as an expander to save $0.01).

I’ve bought many cheap PCBs as they can be easier than making something yourself (240V mains example - made safer with battery isolation), but consider the time needed to get them working - the only available datasheet might be from a design three copies ago, so doesn’t line up and you waste half a day.

So, for a quick test rig, with additional safety precautions - proceed with caution.
For a device which is hard-wired and running 24x7 - save yourself the heartache and buy a Shelly EM!

It’s not just the risk, it’s the time you’ll waste.

(And I say that just after replacing a Tuya CB3S with an ESP8266MOD on an IR Blaster and spending half a day messing about with strapping pin 10k resistors to get the new micro to boot reliably. Sometimes it’s fun; sometimes it isn’t!)

If this helps, :heart: this post!

2 Likes

Thanks!

I will consider buying the Shelly EM. After searching a bit online, the PZEM module seems to be not perfectly safe to use, especially as it would work 24/7.

Thanks again for the help!

Ah, yes - anti-tracking PCB slots and MANDATORY seperation distances.

“We’ve heard of them!”

Y1 and Y2 capacitors are another regular “value engineering” short-cut that works for a while, until it doesn’t (and the output ground floats up to 240V with the case of the charging phone attached to it…)

As BigClive would say “Spicy”

1 Like

There are plenty of threads in the pzem devices on this forum, although I haven’t seen any for a while. Possibly because devices like the Shelly EM have come on the market.

There may be other (cheaper) Shelly devices for single phase.

Eg this is rated 16A https://www.shelly.com/en-au/products/shop/shelly-1pm-gen3-1#node-4qvxsk701djiq