Calculating kWh usage with CT Clamp (Amp meter)

Hi folks,

Any tips on how to create a virtual sensor to track kWh usage using the output of a CT clamp sensor?

My CT sensors are reporting the kW usage every 2 seconds for 4 different areas of the house, which is great for a live view of whats happening in the house, however I also want to get the daily (and perhaps total) kWh usage for each area.

I think what I need is some sort of ‘accumulator’ sensor so every 2 seconds it adds the kWh amount of energy used onto the total?

Any tips where to start?

:point_right: :one: Search

A CT clamp typically outputs current and without knowing the voltage and power factor and the same time it’s not possible to get accurate power readings for non resistive loads :bulb:

Appreciate the links, this a precisely what I need.

I think you’ve answered your own point about the search given the title of the thread you quoted is: " Theengs Plug - BLE Gateway 70 devices supported + Smart plug + Energy consumption" which contains none of the words I searched for which were “kWh usage sensor”. Sometimes the info needed is not easy to locate even with a search.

WRT to the power factor, is there a default value that domestic Electricity meters typically use? Or do they measure in a way that doesn’t require this?

The search is not limited to the title of a topics but by default it’s a full text search in all posts :bulb:
Also when doing a (re)search it’s best to not limit your keywords but do actually the opposite and try with synonyms, abbreviations etc. Also less (words) often outputs more results :mag:

image

No. They need to continuously measure the power factor as domestic customers typically don’t get billed for any reactive power usage :zap:

Our Last week power factors as an example :point_down:

So I’m fairly certain my CT Clamps are accurately calibrated now. Despite this my measured power draw with the CT clamp at the imcoming supply is approx 20% higher than the same measurement from my electricity meter (via MQTT). Is this likley due to the ‘Power Factor’?

Where do you get that power factor data from?

Your ct clamps are only able to measure electrical current and not power :warning:

Feel free to open the links and read about active and reactive power :muscle:

Install a energy monitor? :zap:

Yes, this makes your ct clamp obsolete :put_litter_in_its_place:

There are other CT-based systems that measure current and voltage and report power. I happen to be using a Sense Home Energy monitor, but there are others such as the Shelly EM.

Accuracy will of course require that the sensor measures phase relationships accurately. Such systems are often loosely called “CT clamps” since they measure current that way.

Cheers.

Your energy monitor pictured is just a CT clamp in disguise, the ring magnet on the left is the equivalent of the split magnet in a CT clamp. It may be doing some fancy filtering and sampling inside the circuitboard hardware but ultimately it is just measuring current & voltage and approximating power - which is exactly what my CT clamp is doing (using the ESPHome ‘ct_clamp’ module, which samples the current approx 1500 times a second to analyse the phase/amplitude).

As I am also sampling current and voltage it should be possible to do the same calculations inside ESPHome or even Home Assistant (hence the title of this thread). That’s where I’m seeking a bit more information. I’m using a very basic Amps * Volts = Power at the moment, but as noted, this is missing some more complex mathematics to understand the active and reactive power components.

Afaik it’s the other way around. Power meter exist which output voltage, current, power factor, frequency, etc. and they also include ct-based technologies for measuring the current. :bulb:

Again, to only measure current (with a ct-clamp/coil) on a AC system which not exclusively has a resistive power load will simply not be sufficient to know the real power (@take @supersebbo as an example) :point_up:

And still didn’t bother to open one of the many links which provides you with knowledge your are obviously lacking at the moment. :man_facepalming:

Not complex, simple math. But you should just really take some 20 minutes and just read the basics really :+1:

Other then your ct clamp which is a current meter only the pzem004t v3 is a energy meter which measures current, energy, power, voltage, frequency and the power factor. But yes, it includes a ct coil for the current measurements :zap:

I think we’re talking cross purposes here.

Your energy monitor is only taking two INPUTS current and volts, and is OUTPUTTING current, energy, power, voltage, frequency and the power factor. To do this it will be doing some level of waveform analysis on the AC and some internal calculations and transfer functions to derive those outputs from the inputs. This is documented with this sensor:

This ‘measure module’ is the logic/math I’m interested in replicating inside ESPHome/HomeAssistant, perhaps this is simple in your eyes but I was hoping for a bit more guidance as the Wiki articles are not at a level I can understand. I don’t think it truly is that ‘simple’ as you’re making out, but if it is, could you perhaps write it as pseudo code that I can turn into Python?

1 Like

It’s simple math. As you have already your active power (kW) from your domestic electricity meter via mqtt in HA and you also have the apparent power (kVA) from your ct-clamp/coil together with a voltage meter (:warning:*) you can actually simply calculate the reactive power (kVAR) to get to know the power factor :raised_hands:

Active power = apparent power - reactive power

image

*In case you don’t measure the voltage continuously don’t try a fixed (imaginary) value as this will simply not work out…

Our Last week AC voltage as an example :point_down:

You want your ct (CURRENT transformer) to tell you voltage, power, frequency and power factor with the help of software? You should throw a patent on this :joy:

You for sure will find sources that explain it in an easier way for you. But really take the time to get this knowledge! You will have no chances in achieve what you want without knowing the basics. And don’t blame yourself - many people think that a current transformer (ct) will tell them the real power usage in an AC system (with PF not 1) but that’s just not the case (and something I write here like every 3 months :wink:)

OK, perhaps I didn’t mention I also measure the input voltage of my supply (and see as much variation as you do):

The CT sensor I’m using outputs a single RMS value for the current, but behind the scenes it’s actually sampling the supply at over 1000 times a second, so there is a lot more data here that can be dug in to.

So this gives me all the inputs that the PZEM-004T sensor has, so it must be possible to calculate all the other values from those values.

To calculate the frequency I believe is a case of applying a ‘Fourrier Transform’ to the input data, as the CT sensor is sampling at over 1000hz it can easily sample a 50hz AC waveform. There is some starting material here:

I can probably work this part out.

Then it’s a case of working out the formulas/transforms active power - as noted above by @dwebb2025 this is a case of sampling the phase, amplitude and voltage. Assuming the existing RMS transform is sufficient for the apparent power then there is all the data needed to calculate the rest of the outputs.

As noted here, all the inputs needed to do this, I have.

Digital

A modern digital wattmeter samples the voltage and current thousands of times a second. For each sample, the voltage is multiplied by the current at the same instant; the average over at least one cycle is the real power. The real power divided by the apparent volt-amperes (VA) is the power factor. A computer circuit uses the sampled values to calculate RMS voltage, RMS current, VA, power (watts), power factor, and kilowatt-hours. The readings may be displayed on the device, retained to provide a log and calculate averages, or transmitted to other equipment for further use. Wattmeters vary considerably in correctly calculating energy consumption, especially when real power is much lower than VA (highly reactive loads, e.g. electric motors). Simple meters may be calibrated to meet specified accuracy only for sinusoidal waveforms. Waveforms for switched-mode power supplies as used for much electronic equipment may be very far from sinusoidal, leading to unknown and possibly large errors at any power. This may not be specified in the meter’s manual.

2 Likes