evcc icon indicating copy to clipboard operation
evcc copied to clipboard

Feature: "Solar first" optimizer strategy for self-consumption

Open 1va13n7in opened this issue 4 months ago • 3 comments

Is your feature request related to a problem? Please describe.

For home battery systems with flat feed-in rates (no dynamic tariff spread), the MILP optimizer has no economic incentive to prefer battery charging over grid export. Solar surplus gets exported at peak power while the battery charges only as a side effect of the cost tiebreaker (attenuate_grid_peaks). This is the wrong answer for installations where self-consumption matters more than cost arbitrage. It also does not help with feed-in power caps at the grid connection point (e.g. the German 70% rule), where the goal is to keep export below a fixed ceiling by diverting surplus into the battery.

Describe the solution you'd like

Two complementary features:

  1. charge_profile: SoC-dependent charge power limits (CC-CV taper). The optimizer currently treats c_max as constant. In reality, the BMS reduces charge current at high SoC. A chargeProfile: lifepo4_conservative config option per battery models the taper curve, making schedules feasible above 80% SoC.

  2. Solar first strategy: Alternative to the MILP. Instead of minimizing cost, it finds the flat export ceiling that charges the battery to target SoC while reducing grid export peaks. All active charging slots reduce the forecasted feed-in power by the same amount. Activated via OPTIMIZER_STRATEGY=solar-first env var. The UI adapts accordingly.

Both are fully backwards compatible (opt-in only). I have implemented, tested, and deployed both features in production on a 34 kWp / 42.58 kWh LiFePO4 system. Built with AI assistance (Claude). Changes span evcc-io/optimizer (4 files) and evcc-io/evcc (7 files). PRs are ready.

Describe alternatives you've considered

The existing attenuate_grid_peaks charging strategy helps but only acts as a tiebreaker when multiple schedules have the same cost. It does not actively optimize for self-consumption or flat export. For flat-rate systems, every schedule has the same cost, so the tiebreaker is the only thing steering the battery, which produces suboptimal results.

Additional context

Image

Solar first charging plan

Charging plan with Solar first active. The grid power line (grey) is flat during active charging. CC-CV taper visible as charging power decreases toward the end of the charge window.

The changes span two repositories. I would appreciate guidance on how to structure the PRs given the dependency (evcc needs the new optimizer version).

We briefly met at MCH2022 and WHY2025. Happy to discuss on a call, in German if easier.

1va13n7in avatar Jul 20 '26 07:07 1va13n7in

Thanks for the detailed writeup and for sharing the production numbers on the 34 kWp / 42.58 kWh system.

This confirms both features build on the separate evcc-io/optimizer module (currently pinned in go.mod at github.com/evcc-io/optimizer v0.0.0-20260613102250-473d3906e657, consumed via core/site_optimizer.go), so this is a two-repo change rather than something containable in a single PR here.

Suggested path forward:

  1. Open the charge_profile and solar-first strategy PR against evcc-io/optimizer first, since evcc-io/evcc only consumes tagged versions of that module.
  2. Once merged/tagged there, open the follow-up PR here (go.mod bump + the 7 files you mention: presumably UI/config wiring in core/site_optimizer.go, assets/js/components/Optimize/*, core/optimizer.md, etc.).
  3. Please split "charge_profile" (BMS taper modeling) and "solar-first strategy" (new optimization objective) into separate PRs on the optimizer side if feasible — they're logically independent and easier to review/merge separately.

This is a feature proposal, not a bug, so I'm labeling it enhancement. A maintainer will need to weigh in on the two-repo PR sequencing and whether OPTIMIZER_STRATEGY=solar-first is the right activation mechanism (vs. per-site config).

🤖 Generated with Claude Code

github-actions[bot] avatar Jul 20 '26 07:07 github-actions[bot]

Thank you for the detailed guidance. I will submit the pull requests accordingly.

Please find attached screenshots from various tools taken later today, which confirm that the code functions as expected.

I hope these are helpful for your review. Should you have any questions or require further adjustments, please do not hesitate to let me know.

Thank you very much for your time and support.

Image Image Image

In this setup V balance is set to 3.4V. Image

1va13n7in avatar Jul 20 '26 12:07 1va13n7in

I'm not sure why we need this given we have https://github.com/evcc-io/optimizer/pull/96?

andig avatar Jul 22 '26 06:07 andig