Skip to content

Controller Timeslot Peakshaving: Avoid endless while loop#3464

Merged
sfeilmeier merged 2 commits intoOpenEMS:developfrom
opernikus-common:bugfix/timeslot-peakshaving
Dec 6, 2025
Merged

Controller Timeslot Peakshaving: Avoid endless while loop#3464
sfeilmeier merged 2 commits intoOpenEMS:developfrom
opernikus-common:bugfix/timeslot-peakshaving

Conversation

@tsicking
Copy link
Copy Markdown
Contributor

@tsicking tsicking commented Dec 2, 2025

In the previous implementation, if the min power of the ess is 0 (e.g. if the battery has an error), and the SOC is below the hysteresis SOC while being in state slowcharge, the while loop would toggle between the states SLOWCHARGE and HYSTERESIS endlessly. This is critical, as the method runs inside the core cycle, therefore the whole system would stop.
One can reproduce the bug with a simulated ess, a controller fix active power setting the ess to 0, and a controller timeslot peakshaving running afterwards in state SLOWCHARGE.
The new implementation leaves out the while loop altogether and does not check the min power.

When going through the code, I saw that there is more room for improvement, namely:

  1. The ess and the meter could be referenced via OSGi (breaking configurations, as ess() would need to be renamed to ess_id())
  2. When restarting the system in state SLOWCHARGE, the controller will not get back into the state, but remain in state NORMAL.
    This will be done in separate PRs.

@tsicking tsicking requested a review from clehne December 2, 2025 07:42
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 2, 2025

Codecov Report

❌ Patch coverage is 68.18182% with 7 lines in your changes missing coverage. Please review.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #3464      +/-   ##
=============================================
+ Coverage      59.54%   59.54%   +0.01%     
  Complexity       112      112              
=============================================
  Files           2901     2901              
  Lines         124935   124926       -9     
  Branches        9357     9356       -1     
=============================================
- Hits           74381    74379       -2     
+ Misses         47737    47725      -12     
- Partials        2817     2822       +5     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fabian94533
Copy link
Copy Markdown
Contributor

@tsicking thank you for this pull request. We've currently faced this issue on one of our customer systems. We are testing this on the system at the moment. I will give you response if it works out.

You are saving me a lot of debug time by your pr 👏🏽

Copy link
Copy Markdown
Contributor

@sfeilmeier sfeilmeier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@sfeilmeier sfeilmeier merged commit 77f15dc into OpenEMS:develop Dec 6, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants