Negative power factor with Shelly EM

I don’t see that in neither one of Tom’s graphs.

Additionally, this API response contains contradicting information, right?
Screenshot 2022-03-26 at 12-03-04 Screenshot
How could [real] power be positive when power factor is negative?

I’m not necessarily saying that the new code is right, I’m just pointing out that there likely is a bug in the Shelly firmware.
If you want to get the patch reverted, you should raise an issue on Github and include your explanation of why the new code is wrong. I see you have already done that :+1:

Tom’s house load is normally negative because he presumably has a lot of leading PF loads, this is not unusual and you can see that the much increased negative PF diminishes around sunset and then starts to go negative again at about 0800 as the Solar starts to export again after sunrise.
Yes I’ve reported the integration is now wrong on GitHub.

Leading PF (capacitive load) does not generate any real power.
PF should still be positive, it’ll just be less then 1.
-pi/2 < phi < 0
0 < cos(phi) = PF < 1

Incorrect, the total load is a mix of 12.88 real power and -93.52 apparent power and therefore the PF is 12.88/-93.52 giving a PF of -0.14

The real power element is just 13W and in a typical load situation at very low powers these are the results to be expected.

The total load is a mix of 12.83 W real power and -93.52 var reactive power, thus giving sqrt(12.83^2 + (-93.52)^2) = 94.396 VA apparent power.
Power factor is PF = 12.83 W / 94.396 VA = 0.136

But you don’t know the sign because you haven’t measured the phase angle and the Shelly did and reported -0.14.
You ignored the sign in your calculations so the vector maths is wrong.
The bottom line is the integration was correct, now it’s not.

So shelly is reporting abs(P) instead of P for real power?
P = -12.83 W
Q = -93.52 var
S = sqrt((-12.83 W)^2 + (-93.52 var)^2) = 94.396 VA
PF = -12.83 W / 94.396 VA = -0.136
12.83 watts of real power is generated.

So you sort of got to the correct result eventually, real power can’t be negative and Shelly does not report it as that.
If you think about the vectors the y-axis is the apparent power and the x-axis the real power.

So I knew that PF was negative for inductive loads (when voltage leads current, “CIVIL” mnemonic) but had not considered that its sign changes when exporting power.

I agree that the PR needs reverting.

The only issue is that the Shelly web interface is showing positive PF when it should be showing negative PF. The API (that home assistant uses) is correct. So it’s only a problem that Shelly needs to fix.

Shelly web Interface

a8cfa5f918f2873d06bcd0bb85a97b5533670dd7

API:

f821e684ff45d337d6602dcdf8da0c75a2d2832a

Home Assistant:

5efec1ab9502c956f838713e516f32440a5b8b61

By convention, generated power is negative. So real power can be negative.
x-axis is the real power. y-axis is the reactive power. Apparent power is the length of the vector, always positive.

I think you are talking about phase angle being positive / negative, not the power factor.

When power factor is equal to 0, the energy flow is entirely reactive and stored energy in the load returns to the source on each cycle. When the power factor is 1, referred to as unity power factor, all the energy supplied by the source is consumed by the load. Power factors are usually stated as “leading” or “lagging” to show the sign of the phase angle. Capacitive loads are leading (current leads voltage), and inductive loads are lagging (current lags voltage).

A negative power factor (0 to −1) can result from returning active power to the source, such as in the case of a building fitted with solar panels when surplus power is fed back into the supply.
Power factor - Wikipedia

It has been 30 years since I did AC theory!

So which of these is correct?

If generated power is in fact reported as a negative number:
At the time of this measurement, power was being consumed, not generated. Thus I’d say the positive power factor is correct.

However, for generated power, PF is negative. So unconditionally reporting the absolute value is wrong.

The trouble is that that sensor has nothing to do with my solar export. It is only measuring a single load (my heat pump). It does not care if the energy comes from the solar inverter or the grid.

What’s even weirder is that the Shelly web interface is now agreeing with their API (there have been firmware updates):

Screenshot 2022-10-30 at 10-20-47 ShellyEM

Screenshot 2022-10-30 at 10-19-52 Screenshot

This is my theory. It is not correct mathematically, but it might make sense from the firmware programmer’s point of view.

  • The Shelly programmer deemed the correct mathematical sign of the power factor as redundant, because power consumption / generation can be decided based on the sign of the real power P.
  • They wanted to include information about the power factor being leading / lagging. Now that abs(pf) is always positive, it might have seemed like a good idea to them to add this information as the sign of pf.

What G6EJD is seeing in their system could be a coincidence. The sign of the power factor changing with (solar?) power generation might be a result of the load type changing.

Assuming the above is right, Home Assistant should probably do something like sgn(P)*abs(pf) to get the mathematically correct power factor value. (I don’t know if that’s desirable though. After all, the sign is redundant information, and knowing if the PF is leading or lagging is much more useful.)

It’s 2:30 AM here, so you should probably take this theory with a grain of salt.

The sign of the PF is vital to calculate energy flows, either import or export.

Yes the Shelly firmware has been updated to correct their sign error. You’ll also note they now report Voltage, Current and PF so there is everything needed for the classic VAr calculation and still the PF sign is necessary!

So all that’s required is to remove the abs(PF) change that was made recently and normal integration service will resume.

BTW it is quite usual for an induction motor to exhibit a large leading PF so the basic CIVIL aide memoir does not work as it’s an inductive load and does not follow the rule. Most industrial users will run an induction motor on light load for PF correction purposes as they get charged for VAr domestic customers are charged for Watts. Any air conditioning unit is highly likely to be using an induction motor (no brushes) and so presents a negative PF to the supply evident no matter where the measurement is made in the house.

For pure sine waves, pf = cos(phi), where phi is the phase angle.
No matter what combination of inductive and capacitive load you have, if you don’t generate any real power, you cannot get a phase angle that is not in the range <-pi/2; pi/2>. Thus, pf is in the range <0; 1>.
Pf can only be negative if real power is being generated. However, in that case, P is also negative.


The vector math wouldn’t work if PF was negative for an inductive load.
S = P + jQ
P is real power being consumed. Since this is a load and not a generator, P is a positive number.
Q is the reactive power. Either positive or negative, based on load type.
S is complex power.
|S| is apparent power.

P = pf * |S|
|S| is always positive. Thus, PF can only be negative if P is negative (i.e. if real power is being produced, which an inductive load cannot do).

I recommend that you read the wikipedia article. It clearly show the equations, as well as the graphical representation (power triangle).

What I was trying to explain in one of my previous comments was that you used the incorrect equation in your example.
P = 12.88 W
Q = -93.52 var (you thought this to be |S| = -93.52 VA, which cannot be true).
You are calculating PF = P / Q, which is not right. For example, Q = 0 for a purely resistive load. If your equation was correct, PF wouldn’t be defined for a purely resistive load (division by zero), yet it’s a well-known fact that it’s 1 (see the Wikipedia article).


I didn't want to start a flame war. I agree that Home Assistant shouldn't be returning the abs() of PF as this is removing a piece of information the device is sending.

What I don’t agree with is your explanation of why PF would be negative.
I also don’t think the device is returning the true power factor (which would have the same sign as P), but rather a value that also contains information about the PF being leading / lagging, which cannot normally be decided just based on the value of PF (again, see Wikipedia).

In a property when there is no load on the incoming grid the PF will be 1, I think we agree on that.

Then if resistive loads are applied the PF will remain at 1 and the load current increases.

However, loads are never perfectly resistive so R +jX or R-jX will start to apply as X is no longer 0 and in most cases the load is inductive and the current will lag the voltage applied due to back EMF and the PF will move to a positive value but less than 1 typically +0.8 so now the Apparent current flow has increased being the vector sum of the real and imaginary current components.

The equation Real Power/Apparent Power always works because Apparent Power can never be 0 and the result is always the PF.

Don’t forget Wiki articles are created by the general public and can be amended by the general public they are not always the definitive answer to topics!

If the house has many leading PF loads like TV power supplies and LED lighting or induction motors, all tend to have a PF of about -0.5 because they use capacitor droppers or by their nature they present a leading load, then the predominant house load will be leading and the -ve sign denotes that, I’m not sure why this is causing so much confusion.

High leading PF loads have a -ve sign
High lagging PF loads have a +ve sign

Both by convention.

When energy flows out of a property usually from solar generation the PF will be negative, and when there is no solar and when the house loads are predominantly negative the measured PF will be negative or when the house loads are predominantly positive the PF will be positive.

When a solar system is generating the PF will continuously change from + to - as the house load changes usually when the house consumes all of the excess solar energy.

Had the integration changes been challenged by more knowledgeable commentators this thread would never have been started! But of course it’s occurred after the event when it went wrong.

We just need the integration changes to be undone so it no-longer returns abs(PF) and just PF

If this is how you define the power factor, then the equations presented on Wikipedia don’t work. And PF != cos(phi). (This might not be entirely relevant, but in Czech, we don’t use an extra symbol (PF) for power factor. We just write cos(phi).)

This also isn’t true with your definition of PF.

However, this isn’t even what you did in your example:

You have divided real power by reactive power Q (negative number in this case), not apparent power |S|.
What if this was a mostly resistive load? Say P = 100 W; Q = -1 var. You would get PF = 100 / (-1 var) = -100 from your formula. I think we’ll agree that this cannot be right.

Wiki articles should cite trustworthy sources. If you don’t trust the information written there, you can check with the cited materials.

Power Factor sign is subject to standard used, that is either the IEEE or IEC standards.
A comparison of the 2 standards is presented:
https://www.se.com/ww/en/faqs/FA212521/

PF sign convention: IEC

PF sign correlates with the direction of real power (kW) flow.

  • Quadrant 1 and 4: Positive real power (+kW), the PF sign is positive (+).
  • Quadrant 2 and 3: Negative real power (-kW), the PF sign is negative (-).

PF sign convention: IEEE

PF sign is correlates with the PF lead/lag convention, in other words, the effective load type (inductive or capacitive):

  • For a capacitive load (PF leading, quadrant 2 and 4), the PF sign is positive (+).
  • For an inductive load (PF lagging, quadrant 1 and 3), the PF sign is negative (-).

PF sign test on Shelly EM:

I test the sign of PF given by the Shelly EM on the 4 quadrant by looking the “power”, “reactive power” and “pf” (publish with mqtt) and obtain:

  • For a capacitive load (PF leading, quadrant 2 and 4), the PF sign is negative (-).
  • For an inductive load (PF lagging, quadrant 1 and 3), the PF sign is positive (+).

It seems that Shelly EM use (IEEE PF sign convention) multiply by (-1)

2 Likes