Proposal: add Power and Energy distribution channels to `_sum`

I would like to hear your feedback on the following PR:

This PR adds a feature to closely analyze in real-time and for historic values, how the power and energy distributed between Grid, Production, Energy-Storage-System and Consumption, i.e. how much grid-buy energy was charged to the battery; how much grid-sell energy was discharged from a battery, etc.

This PR adds new Channels to the _sum component, that represent power and energy distribution:

  • PRODUCTION_TO_CONSUMPTION_POWER / PRODUCTION_TO_CONSUMPTION_ENERGY
  • PRODUCTION_TO_GRID_POWER / PRODUCTION_TO_GRID_ENERGY
  • PRODUCTION_TO_ESS_POWER / PRODUCTION_TO_ESS_ENERGY
  • GRID_TO_CONSUMPTION_POWER / GRID_TO_CONSUMPTION_ENERGY
  • ESS_TO_CONSUMPTION_POWER / ESS_TO_CONSUMPTION_ENERGY
  • GRID_TO_ESS_POWER / GRID_TO_ESS_ENERGY / ESS_TO_GRID_ENERGY

The unit test in PowerDistributionTest.java shows some example distributions:

  • Grid Sell -1000 W, Production 2000 W, ESS Discharge 500 W (Consumption is 1500 W in this case)
    • 1000 W Production-to-Consumption
    • 1000 W Production-to-Grid
    • 500 W ESS-to-Consumption

These values will be useful in a UI visualization in future. The feature has been > successfully tested locally on my private system.

One downside of the approach with CalculateEnergyFromPower is, that the resulting energy values might be slightly different to e.g. CONSUMPTION_ACTIVE_ENERGY. Itā€™s difficult to overcome this - but in reality a few Wh difference might not make a difference.

@Sn0w3y: Whatā€™s you opinion?

Hi @sfeilmeier,

Great job on adding the power and energy distribution channels! :tada: The implementation is clear.
In my Opinion it is a great Contribution and Improvement !

If it is merged i would be able to test it locally aswell on my System :slight_smile:
What would be a UI Widget which is suitable maybe on History Tab to show some new Values? Do you have something in your mind?

Best,
Sn0w3y

Ok, thanks! Iā€™ll let it run a few more days locally and see if I can identify any flaws.

I did not think about visualizations in detail. A suitable visualization could be in the form of a Sankey-Diagram

1 Like

I will let it run on my Edge aswell :slight_smile: Just pulled the PR :stuck_out_tongue:

Will also report if everything works ! :slight_smile:

What do you think should we do with invalid data? For example negative Production and Consumption. Using them the way they are (so that the sum-equation fulfills) or setting them to zero (breaking the equation).

As weā€™re working on a new version of the channels and focusing on improving the user experience, I believe it would be better, especially for installers who may not be familiar with grid connections, to keep the values at 0 if any values are incorrect. What is your opinion on this approach?

Additionally, it might be helpful to display an error in the UI if the values are invalid, so that users can easily identify and correct any issues.

What are your thoughts on this? :slight_smile:

I havenā€™t had a detailed look at it, but how do you choose the six channel values for the powers? In the example you give,

1500W Production-to-Consumption,
500W Production-to-Grid and
500W ESS-to-Grid

would also be valid, wouldnā€™t it? And anything in between, like

1250W Production-to-Consumption,
750W Production-to-Grid,
250W ESS-to-Consumption and
250W ESS-to-Grid.

Mathematically speaking, you have a linear equation system with 6 variables (Production-to-Consumption etc.) and only 3 equations (Production = Production-to-Consumption + Production-to-ESS + Production-to-Grid etc.), leaving a 3-dimensional solution space, if Iā€™m not mistaken. Okay, you additionally say that most powers are non-negative, which solves it in some cases, but still, how do you determine which of the many solutions you take?

Best regards,
Thomas

@Sn0w3y: The problem is, that this would break the most fundamental formula in OpenEMS:

Consumption = Grid + Production + ESS

Showing a Warning is a good idea, but we need to consider corner cases as well. E.g. in my system the grid meter measures electric vehicle charging power before I get the value from the charging station. This leads to a short period of negative consumption as well.


Thank you Thomas (@tsicking),

this kind of the discussion is the reason why I opened a ā€œProposalā€ thread here to discuss this. :+1:

Yes indeed, if we want to visualize the distribution, we need to settle on a ā€œpriorityā€ on how the energy should flow.

Example (based on JUnit test #3):

Distribute following power:

  • Grid Buy: 1000 W
  • Production: 2000 W
  • ESS Charge: 500 W

Solution #1 (as in the test)

  • Production-to-Consumption: 1000 W
  • Production-to-ESS: 500 W
  • Grid-to-Consumption: 1000 W

Solution #2 (equally possible within the linear equation system)

  • Grid-to-ESS: 500 W (might be illegal depending on the legislation)
  • Production-to-Consumption: 1500 W
  • Grid-to-Consumption: 500 W

In the implementation I chose to distribute ESS first, to avoid these legislation pitfalls, that also exist in the ESS-To-Grid direction.

But I am very open to discussion. Maybe it helps if we add more examples in the PowerDistributionTest.java - including some that break other constraints (like Consumption and Production being negative)

I think the better approach would be to show a warning when invalid data is detected without altering the core calculations. This would allow users to identify and correct any discrepancies without affecting the equation.

Maybe this could be handled with a delay easily ? :slight_smile: As if the Meter is incorrect it is negative most of the Times and not only a short Period :slight_smile:

Unfortunately this is not only a corner case. The idm heatpump measures its own consumption only approx. every 30s. Same for the dachs CHP and there are other components. Therefore we often have short periods of negative consumption.

ā€¦

I donā€™t like the idea of setting invalid data to zero. Having negative data has helped us identify other system problems in a lot of systems. If really needed, I prefer to catch this kind of problem within the component that causes it.

Unfortunately we still do not have a way to handle this appropriately. E.g. the idm heatpump always breaks the consumption within the UI. That is something we simply live with at the moment:

I thought of a sum component configuration option to set negavtive values to zero in only a few systems. But I also do not like this idea too.

I donā€™t think displaying an error will help much here, as we have this components, which provide meter values heavily delayed.

First of, I like the idea of breaking down the power and energy values within PR #2923.

Regarding

People buy a battery to store the energy from the PV!
Therefore I think the ESS first assumption is pragmatic and comes closest to reality of most people.