Add solar_hold_pct battery parameter with charging gate#70
Closed
larsxschneider wants to merge 2 commits intoevcc-io:mainfrom
Closed
Add solar_hold_pct battery parameter with charging gate#70larsxschneider wants to merge 2 commits intoevcc-io:mainfrom
larsxschneider wants to merge 2 commits intoevcc-io:mainfrom
Conversation
Document all dataclasses (BatteryConfig, GridConfig, TimeSeriesData, OptimizationStrategy) with field descriptions, units, and usage notes. Add comprehensive Optimizer class docstring with variable naming conventions, penalty variable reference, and penalty weight naming. Document constructor parameters. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a solar_hold_pct parameter (0..1) that limits battery charging during solar hours to preserve headroom for later solar production. A backward ramp raises the cap before each solar window ends so the battery reaches s_max by sunset. Enforcement uses a binary charging gate instead of a penalty to avoid incentivizing unnecessary discharge: when SoC >= cap, charging is blocked but discharge remains unrestricted. When SoC < cap, charging is allowed up to the cap value. The parameter can be set per-battery in the API request or globally via the OPTIMIZER_SOLAR_HOLD_PCT environment variable (applied only to home batteries with s_capacity and d_max > 0). Includes three test cases: basic solar hold, high initial SoC (s_initial > s_max), and two-battery setup with car + home battery. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
|
Imho this approach fundamentally violates how the optimizer should operate. Instead of giving an "keep the time while max soc applies as short as possible" it is a hardcoded "if value x then y". Unless I completely misunderstand this is nothing we want to implement. |
Member
|
The param descriptions are really great- but would deserve their own PR. |
Author
|
I'll raise a separate PR for the docs. I tried it with a soft limit first, but this approach did run into a few edge cases. The proposed solution generated better results. |
Member
|
I still take stance that the approach is flawed. The whole purpose of the optimizer ist to not have fixed, pre-defined limits. If those are needed we can put them into evcc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a
solar_hold_pctparameter that limits battery charging during solar hours but still ensures a fully charged battery by sunset.Motivation
Battery health: In summer, my battery is fully charged early in the morning and sits at 100% until the evening at high temperature. Keeping the battery at e.g. 70% during the day and only charging to 100% before sunset should improve longevity.
Grid feed-in limits (future work): The German Solarspitzengesetz (Solar Peak Act) will restrict grid feed-in during peak solar hours. By holding the battery low in the morning, peak midday solar can charge the battery instead of being curtailed. This aspect is not implemented in this PR but would be the logical next step if the maintainers agree with the general approach.
How it works
A per-timestep SoC cap curve is computed from the solar forecast:
solar_hold_pct * s_capacity(e.g. 50%)s_maxusing the remaining solar surpluss_max(no restriction)Enforcement uses a binary charging gate (Big-M formulation): when SoC is at or above the cap, charging is blocked; when SoC is below the cap, charging is allowed up to the cap. Discharge is never restricted, so the battery is not forced to dump energy.
Usage
solar_hold_pct(0..1) can be set per-battery in the API request or globally via theOPTIMIZER_SOLAR_HOLD_PCTenvironment variable. The env var default is only applied to home batteries (s_capacityset andd_max > 0), which should exclude EVs.Commits