EmonCMS Grid Daily kWh decrease with export

I know many of you are using EmonCMS with your IoTaWatt units. I have been running it along side this great product for nearly 8-months and love the combination and flexibility. I did have one item that might be a quick fix that I’m simply missing which I could not find details here or on the EmonCMS site. It seems that the Import and Export are relative to the home’s usage and not based on totals. For example, if the home has used 6.69kwh at a given time and we have consumed 6.26 (grid consumption) the remainder (0.43) is from solar generation. As the day progresses the consumption goes negative instead of actual consumption usage.

Bob did have some details on the initial grid/solar setup here: Setting up solar in Emoncms

Desire: I would like to have totals simular to what is found with PVOutput (love the simple implementation Bob, thank you), one can see a total of both import (grid) and export (solar) in kWh each day. Neither of the two import/export correlate to one another as with my EmonCMS setup.

26%20AM

In the above sample, I can clearly see that I imported from the grid for the day ~16kWhs and my solar generation was about 31 kWhs.

Current State: With my EmonCMS setup, the import (grid) daily kWh value begins to decreases as I export to the grid (neg. watts) from my solar. For example, my home uses about 4-6 (winter) kWh from midnight to the start of solar generation. When exporting starts as the sun rises, my total daily kWh importing begins to go down and on good days goes negative; exporting more than importing.

Desired State: Have a total of both import (grid) and export (solar) allowing me to calculate total home consumption, etc.

From my EmonCMS dashboard:
06%20AM

I can watch the Grid kWh and decrease as I export more power to the grid. On a good day, this may be around -20 or -30 along with a negative grid cost.

My current setup looks like this:
Mains 1:

Mains 2:

Sorry for the long explanation for what my be a simple fix, but it is often hard to explain without pictures and use case info. Always willing to learn from those who have gone before and found a solution.

Let me see if I have this right:

  • The generation and consumption reported in PVoutput appear to be good.
  • Your total imported kWh in Emoncms appears to go down with generation.

Looking at what you posted, and recalling somewhat that you have a different approach using signed quantities for solar output, I think I need a refresher.

When you say “Grid kWh” I assume that is the Grid_Total_kWh developed in the Mains_1 process list. My recollection is that your solar inverter is connected to a breaker at the bottom of your load center, and so generated power is used first by your house loads and any excess is exported back through your mains. Based on that assumption, what you are reporting is consistent with what you have setup in Emoncms. Your Grid kWh is the net kWh that pass through your mains, so when solar generation exceeds consumption, it feeds the grid and reduces your net Grid kWh.

So if I have all the prior assumption correct, and taking the liberty of referring to the sum of your mains as “Mains” and the sum of your solar (why do you have two?) as Solar:

Import = Mains max 0 (The sum of positive kWh flowing into your load center)
Export = Mains min 0 (The sum of the negative kWh flowing out of your load center)
Generation = Solar max 0 (The sum of the kWh flowing into your load center from the inverter)
Consumption = Mains + Solar (The net kWh flowing in/out your load center)

These values are probably easier to produce with the IoTaWatt “calculator” and then export to Emoncms. That’s what I do, and then just “log to power” and “power to kWh” to convert the inputs to feeds. I even do my miscellaneous category there. It’s just well… a whole lot easier than messing around with those input process lists.

@overeasy,

You amaze me with your memory and ability to recall very obscure bits of information even with all the other type of installs out there. All your assumptions are correct which you listed. Main Total (Main 1 + Main 2) is where I import energy from the grid and export excess power from my solar to the grid. I have two CTs on the Solar (have from the start and if not correct happy to make corrections.). Solar Total (Solar 1 + Solar 2). The connection is at the bottom of the panel as you stated. Quick question, with a battery (Powerwall) in the near future, this would be treated like the mains with both storage (to battery) and usage (from battery) so there will be both positive and negative numbers like export/import.

Thanks for the idea on leveraging the MIN/MAX option for strip away and treat that as separate data elements. I like it. This would allow me to get actuals instead of relative based on home usage. Both are useful based on need, but I like the actuals more for calculations.

You sir are a rock star and a genius.

Quick questions looking at your formulas:

Would not Import be “Min 0” to prevent negative numbers and Export be “Max 0” to only allow negative numbers? Just wondering if my logic is backwards.

Import = Mains max 0 (The sum of positive kWh flowing into your load center)
Export = Mains min 0 (The sum of the negative kWh flowing out of your load center)
Generation = Solar max 0 (The sum of the kWh flowing into your load center from the inverter)
Consumption = Mains + Solar (The net kWh flowing in/out your load center)

This stuff makes my head hurt. Here’s how I see it.

When your mains are positive, say 2000W, you are importing power. 2000 max 0 will give you 2000.
When your mains are negative, say -1500W, you are exporting power. -1500 max 0 will give you zero.

So import will always be zero or positive. Opposite for Export with the min function.

Now at the risk of ruining my newly acquired reputation for total recall (what was your name again?) you had made some attempt to organize your panel so that all of the CTs would add up to zero if everything were measured. Not positive about that, or if that’s what you settled on, but your Emoncms process lists seem to conform to the standard conventions of supplies (mains, solar) being positive flowing into the panel, and loads being positive flowing out of the panel.

It’s a subtle difference but in the former: supply + load = 0
and in the latter: supply - load = 0

and more to the point, I think the min/max would be as you suggest if your mains are unconventional.

Does that make any sense?

I think it was more my understanding of the terms MIN and MAX sir.

I had assumed logically that something set to “MIN 0” would only allow positive numbers to pass though as logically such numbers are greater than 0 and must be positive. Where as any negative numbers would be considered false and dropped from the rule as they are below the threshold of “MIN 0”. I then would assumed the opposite with MAX 0 which via logic should accept negative numbers and drop positive one as a positive number would exceed the MAX 0 argument.

I will go and play and see what I can come up with, but I agree you direction is the right one for me to follow! I would like to get actuals for all four and allow me to do more data pivots. Thanks for allowing me to bounce it off you and the rest of the community here.

I can see your point. From the perspective of the calculator, min and max are dyadic functions that compare the two operands and select the lesser (minimum) or greater(maximum) value as appropriate.

I think Emoncms does use it in a rules context where the input process insures the minimum value would be 0. I think they call it “allow positive”.

Love having a new word of the day. :slight_smile: That makes complete sense. I also see that EmonCMS has the ability to skip over a rule based on a given (<= or =>) and a few others. I could have it jump over an Import log based on value and the opposite if the other is true.

I have some digging to do in the docs on how to send Outputs to Emoncms from IoTaWatt as today I have only been sending over the Inputs (from the CTs) no Outputs. Off to the docs for some light reading.

Using the calculator to create outputs (Emoncms inputs) is easy. The trick is to do it seamlessly without messing up what you have. I would recommend stopping the Emoncms service, making the changes to a new node on Emoncms and see if it’s posting what you want. When you have it right, you can change the input processes in your original Emoncms node to just log to power and power to kwh then switch the node name back in IoTaWatt and it should backfill the history.

write it down and plan it out. You only get one shot at it.

I’m all about planning! Don’t want to lose anything and happy to build the inputs first within the IoTaWatt and once I have things correct, tie them over to EmonCMS as you suggest. I like a good plan, and even better when they are successful. :slight_smile:

Just set these IoTaWatt Outputs to watch and see what I get. Looking forward to a sunny day as I’m sure you are having a bad one as well as me.

07%20PM

If you want export to be a positive number, add the unary function ABS to the end of the expression:

(Mains_1 + Mains_2) min 0 abs

Will do. Quick question. I could simply monitor the new Outputs and if they are doing what I assume they will by giving me absolute values for the 4 items, I can add new IDs to the EmonCMS webserver configuration and start to ingest that new data. Starting with IDs in the 20+ and keep the relative values from the older feed; correct? I have an on-prem solution, so adding feeds and such are not an issue. Just making sure I’m thinking rightly.

And when I get the storage Battery, I can treat it like my mains based on import and export; correct? Via new feeds that is.

Sure. Maximum is arbitrarily set to 29 in IoTaWatt I think.

That’s new territory for me. I think you are on the right track though. In concept, with net metering, the grid is just a big battery.

You Da Man; as always. Once in I will let you know what I find with the Battery. Could be a few more months. Oh well.

@overeasy Just want to bounce off you one last thing. I have tried many ways to add the ABS after the MIN 0 for Exporting, but it does not allow me too. I can add it after the addition (screenshot below), but that would impact the MIN function after it. I’m I doing something wrong and the ABS after MIN 0 just clicks but does not add it to the formula.

The screenshot below shows I can add it before the MIN, but the same does not work when I try to add it after.

01%20AM

I think you found a bug in the script editor. Don’t have time to flesh it out right now, but if you enclose the preceding arguments in parenthesis, it should work.

((Mains_1 + Mains_2) min 0) abs

With the “abs” before the MIN, it will be applied to the sum of the mains making it always positive, so the expression would always evaluate to the lesser of that and zero, which is zero.

I will give that one a try. Awesome solution. Thank you sir.

No rush, just giving you a heads up. That seems to work by encasing the formula in () based on what I see in the outputs on the IoTaWatt STATUS page, but the data sent over to EmonCMS appears to remain as a negative value.

A few shots below for your review.

IoTaWatt Status Info:
56%20AM

EmonCMS Value:

OUTPUT CONFIG:
29%20AM

Did you put that formula into the output script for Emoncms? The Emoncms (and other server configurations) do not have access to the outputs defined in the setup outputs section. Those are for local use only. The problem is that when you start referencing these things from other places, it opens the door to problems if the outputs are renamed or deleted. So I require that you specify them in each place that you use them for export.