# How is the P value calculated in emonESP?

Hi, in looking at emonESP for my emonTXv4 I see the voltage (Vrms) at 236.64V and the P1 at 1454W. The 100A CT is connected to my Air Conditioning compressor.

My understanding of CTs is they sense voltage and output a value of 0 to 5V, which is converted to amps on a scale of 0-100 for a 100A CT, where 0V=0A and 5V=100A. But when I look at the emonESP data it shows the CT output as Watts.

The datasheet for the 100A CT shows that it can output in either current as mA or voltage as mV - I’m not sure which is used in the emonESP application.

My goal is to get the Amperage value. So, I think I have two approaches. One is to obtain the Amp value being read before it is converted to Watts, or understand the formula used to convert to Watts. I prefer the former as I believe a Power Factor must be involved in the Watts conversion.

Any help in understanding this better is greatly appreciated.

Thank you,

Gordon

You are a bit mixed up there! Let me start with the c.t itself and work my way up the chain to the point where you have a meaningful number.

A current transformer does what it says on the label - it transforms a large current - 100 A is the number you mentioned - into a much smaller current, in the case of the one used with the emonTx V3, 50 mA. [I’m an electrical engineer so I always use rms values unless I say differently.] Inside the emonTx V3 is a “burden” resistor (‘burden’ because it’s a load the c.t. needs to work) and it’s that resistor which changes the current into a voltage. By changing the value of the burden, you can choose the voltage to suit the ADC you’re using. For the emonTx V3, that’s about 1.1 V; for the emonTx Shield, about 1.6 V.

In the case of the emonTx4, we use a c.t. which has the burden incorporated within it. We don’t know the current the c.t. outputs, and neither do we care because the values of the current and burden are chosen together by the manufacturer to give 0.333 V output for your 100 A mains current.

Inside the emonTx (every emonTx), the ADC samples the current and voltage around 20 times, usually more, per mains cycle. Those instantaneous samples are multiplied together to give the instantaneous power, these power values are added up and averaged over time to give the average power (the ‘real’ power) in watts. At the same time, individual voltage samples and current samples are squared and averaged to give the rms (root mean square) average voltage and current.

There are of course scaling and calibration constants that turn the pure numbers out of the ADC into engineering values: volts, amps, watts & watt-hours.

So the answer to your problem is, the current is already available within the sketch running inside your emonTx4. The bad news is historically, it’s never been made available to the user by default.

Your two approaches are both correct. The first involves getting the source code for the sketch and changing it to send out the current as well as or instead of the power. The second is quite tricky, because no formula is involved while it is measuring the voltage - the power is derived from current and voltage for each and every sample - it knows nothing about power factor, and in fact it calculates the power factor from those three averages: power factor is defined as the average real power divided by the apparent power (the product of rms voltage and current).

If it doesn’t have the voltage to measure, emonLibCM is capable of running without, and in this case the sketch assumes a constant voltage and multiplies current by a number to give the apparent power, stated in watts but it’s really only a best guess and it’s in VA (volt-amperes). If you’re using the emonVs with your emonTx4, it’s almost certainly not doing this but giving you true real power in watts.

Incidentally, the ESP8266 takes no part in this, all it does is transmit the output by Wi-Fi.

Have you looked in ‘Learn’, because most of the above it written up in there?

Hi Robert,
thank you for the explanation, this helps a lot. I will definitely have a look at ‘Learn’. To be honest, there is a ton of information in the community and the docs, but it is not always easy to find what I’m looking for so after a few hours of searching and reading, I then post my question. With a basic understanding of electricity (and I mean basic - I can wire up house circuits, but am short on electrical theory) I think inability to find the answer is more a case of how I am structuring my search terms.

My preference is to modify the source code to get it to send out current and power, but I have limited programming skills. Where is the best source to learn how to make this change to the sketch? I’m eager to learn, just need some help finding the best place to begin.

Thanks again.

Gordon

Look at the sketch, download the library it uses and the documentation that goes with that, and see how you get on. Then ask if what you think you need to do is right. Only then worry about how and the details of the language. Though others swear by platformio, I swear at it (because when I tried it, it screwed my machine up something awful, so I binned it), and I can’t help you if you use it. I’d recommend running with the tried and tested Arduino IDE (with all its shortcomings), again the instructions to set it up are in ‘Learn’, but I’ve yet to look at updating them to cover the emonTx4 and the extra libraries required. Not mentioned there is the need for an extension to the IDE, the instructions for this are here: Firmware — OpenEnergyMonitor 0.0.1 documentation Installing the IDE and libraries is also mentioned there, while the libraries missing from the older instructions are mentioned, some explanations and details are skipped.

Get it wrong and learn from your mistakes!

I put this reference list together some years ago, these might help:

My bible for C is of course “Kernigan & Ritchie” http://www.amazon.co.uk/C-Programming-Language-2nd/dp/0131103628/ref=sr_1_3?s=books&ie=UTF8&qid=1292502807&sr=1-3. This is the standard text book. The normal place I point people at who want to move up to C++ is C++ In Action: Industrial Strength Programming Techniques - Free Computer, Programming, Mathematics, Technical Books, Lecture Notes and Tutorials and that assumes you know C. Because the Arduino environment normally uses a very small subset of the language, neither are the best place for a beginner to start, nor are many of the other on-line tutorials. I’d still suggest you have both of those, and maybe Bruce Eckel’s “Thinking in C++”.

http://engineering.nyu.edu/gk12/amps-cbri/pdf/ArduinoBooks/Arduino%20Programming%20Notebook.pdf does look to be a good starting place for a beginner, though I’ve not checked through it in detail. It does not go as far as classes and methods that are used here, though. For that, you need “Cpp In Action…” or one of the references below.