# Extended data rules net consumption calculation

im trying to do a dodgy workaround for getting net power as im unsure how else i can get it works
my rule is

if(v10 + v4 - v2 < 1) v10 = (v4 - v2)*-1 else v10 = v4

v10 is sent as 0 to “activate the rule”

so basically
if 0 + Consumption - Generation less than 1 v10 = Consumption - Generation * -1 to turn it into a positive

that allows me to save it but looking at the test it shows anything negative as 0

i try and add else v10 = consumption but it wont work as a rule.

is there an easier way to create this rule to try and show a rough net consumption?

Could you try

if ( v4 > v2 ) v10 = ( v4 - v2 ) else v10 = ( v2 - v4 )

I hope that I have the syntax correct!

Thanks will look at that.

I think my other issue is generation is uploaded before consumption so its as if there is no comsumption data when using the rule
Will have to look at delaying generation upload for 1 minute and see what happens

I had to remove some spaces but it errors on else if i remove else and whats after it, it accepts the rule but if i have else it wont let me save it
if(v4 > v2) v10 = (v4 - v2) else v10 = (v2 - v4)

I was relying on one of the examples.

if(v7 > v8) v9 = 1 else v9 = 0

Depending on how the rules are parsed I imagine that a space is required before and after the else clause.

If the system tries to apply a rule before the dependant terms of the rules are defined it might cause an issue.

i tried spaces and no spaces its like it doesnt like else even though as you said the examples have them

i think im going to have issues with it anyway as it would need to be uploaded at the same time. or how does the rule know when to work?

looking at other rules they have a ; before else so done that and it accepted it. don’t know if it will work as expected or not though
if(v4 > v2) v10 = (v4 - v2);else v10 = (v2 - v4)

The semicolon ‘;’ is used to separate individual rules if you have more than one. In the case above it is a single rule - unless you have other rules.

As a test I tried to insert the rule shown in the HELP but changing v9 to v12 as I am already using v9. I too received an error message.

Interesting. After clicking on the HELP button adjacent to the ‘Extended Data Rule’ dialogue box one of the example rules shown is:

*if(power > 1000) power += 10; else if(power > 1500) power -= 10; else power = 0.95;

I tried creating a rule if ( v4 > v2 ) v10 = ( v4 - v2 ); else v10 = ( v2 - v4 )

With a semicolon inserted before the else; the ‘Rule Tester’ appears ‘happy’. It looks like there may be an error in the example shown in

https://www.pvoutput.org/help.html#extendeddata-rule

Thanks @grannos the documentation will be corrected soon.

The syntax indented should be -

``````if(v7 > v8)
v9 = 1;
else
v9 = 0;
``````

Still not working. So guessing i need to upload the data at the same time.
Unless the rule can be delayed with some sort of sleep command?

So you don’t push / upload v2 and v4 at the same time? Or you derive v2 and / or v4 from the Energy but not at the same time?

I push generation from the inverter and consumption from a pi
I know its not ideal but a rough graph is better than it calculating wrong

Is it possible for you to PUSH both values from the Pi? Obviously you’d have to be able to extract the generation figure from the inverter - using the Pi - first. Then you’d be able to push both values using a single PVO API call.

yeah need to look into it.
i can use a script on the pi to get the data from inverter but then some how need to combine that with the pvoutput integration service on the pi to do consumption.

my scripting skills are copy and paste so will need to look into it a bit more

ok so after a bit of googling i have 3 options.
x. Hope I can get the pvoutput integration service to grab the data from the inverter. (PVOutput Intergration service cant do net)
2. Use my inverter script to grab the data from pvoutput integration service (probably log file) and use that but i would also have to somehow cancel the upload from pvoutput integration service.
3.write code to get the data from my CC ENVIR and inverter…

none sound that appealing for my knowledge

to calculate net would it be this or
if ( v4 > v2 ) v10 = ( v4 + v2 ); else v10 = ( v2 - v4 )

Question. Do you have more than one clamp connected to your CC ENVIR setup? If not then it won’t be possible to tell if you are importing OR exporting electricity to / from the grid at any particular time.

only one clamp. but including the information from the inverter it should tell me.
If CC ENVIR is > Solar im importing
If solar is > CC ENVIR im exporting

I assume then that the CT clamp is around the ACTIVE conductor which represents the LOAD in your home rather than around the ACTIVE conductor which passes through the main switch & meter?

I’m sure there’s a diagram elsewhere on this forum showing places to place CT clamps.

this is the setup

This diagram is not clear if it is a flow diagram or a wiring diagram. Whichever it is the clamp will measure NET power. It is true that you can combine this with the output of the inverter from its monitoring app but this introduces an error due to timing of the measurements by two different devices which are not synchronized. Summed over 288 intervals can be a considerable difference. Still, the cumulative errors will be a small percentage of the total production…most people might be willing to live with that.