feat: configurable loadpoint priority strategy (soc/deficit) with hysteresis
Closes #31071.
Draft, opened for maintainer feedback per the prior-consensus policy — happy to adjust the design/naming or move to a discussion before finalizing.
What
Adds a per-loadpoint priorityStrategy that sub-orders loadpoints within the same priority tier when distributing PV surplus, plus a priorityHysteresis deadband:
priorityStrategy:static(default) |soc(prefer lower vehicle soc) |deficit(prefer largerlimitSoc − soc).priorityHysteresis(soc-%, default0= off): only outrank another same-priority loadpoint when ahead by more than the band, so near-equal-soc loadpoints tie/converge instead of leapfrogging.
Fully backward compatible: static + 0 == current behavior.
How
EffectivePriorityScore()= integerEffectivePriority()(tier) + a fractional[0,1)strategy term, so sub-ordering never crosses a priority tier. The prioritizer ranks by this score; the hysteresis is applied at the comparison (> band), capped< 1.0so it never weakens cross-tier ordering. Strategy term only applies when a positive vehicle soc is known.
Scope (full parity with the existing priority option)
- Config (YAML
mapstructure) + validation. loadpoint.APIgetters/setters, settings-DB persistence + boot restore, publishedkeys.- HTTP API endpoints + MQTT setters (mirror
priority/mode); regenerated mock + OpenAPI/MCP spec. DynamicConfiground-trip → exposed in the config modal, and in the runtime settings modal.- Unit tests (score math, prioritizer ordering, hysteresis no-leapfrog, setters validation/persistence).
go test ./core/... ./server/...,vue-tsc, eslint,npm run buildall green.
Notes
- Docs PR: evcc-io/docs (linked separately).
- i18n: English source only; other locales via the translation workflow.
Is it possible you consider actual energy stored, instead of only percentage for the prioritization?
I think directionally secondary cars with smaller battery become more and more popular.
Our second car has a 25 kWh battery, which is less then half of the other.
Good call. Ranking by percentage alone over-prioritizes a smaller battery: your 25 kWh second car at 40% needs less energy than the big one at 50%, yet the lower % would win. Added it.
There's now a priorityBasis that composes with both the soc and deficit strategies:
percent(default): rank by the soc-% gap, unchanged behaviorenergy: scale the soc-% gap by the vehicle'scapacity, so loadpoints rank by absolute energy (kWh) instead of percentage
So you can keep "lower charge level first" but have it mean less energy stored / more energy needed in kWh. In your example the primary car (needs ~37.5 kWh) now outranks the 25 kWh car (needs ~15 kWh) instead of the other way around.
When a vehicle's capacity is unknown the energy basis falls back to the percentage gap for that loadpoint, so nothing breaks if capacity isn't set. The hysteresis deadband follows the basis (soc-% in percent mode, kWh in energy mode).
It's exposed in both the config and runtime loadpoint modals (a percent/energy selector next to the strategy) and wired into the API/MQTT/OpenAPI surface, with tests covering the inversion case. Pushed to this branch.
Sounds like this PR fulfills a long-standing need for bigger installations. Nice.
I‘ve wondered how hysteresis is handeled in case of >1 vehicle with closely matching socs? If they have streaming api, prioritizer decision may change at each cycle. Does it need hysteresis to guard against that happening?
@andig on the hysteresis question: priorityHysteresis covers this. The prioritizer only lets one loadpoint outrank another when its score is ahead by more than the band, so loadpoints inside the band tie rather than leapfrog (prioritizer.go, GetChargePowerFlexibility).
It converges instead of oscillating. Charging the emptier car raises its soc and lowers its own score, so a within-band pair both keep charging and stay tied. A handover happens once the gap actually exceeds the band. Default is 0, which reproduces the current behavior; set it a bit wider than the per-cycle soc movement to absorb streaming-soc jitter. Covered by TestPrioritizerHysteresis.
One caveat: it's a stateless deadband, not a latch, so there can still be one-step chatter right at the band edge. That only shifts flexible-power allocation, not charge/stop. If you'd prefer flap protection out of the box, I can ship a small non-zero default, or make it a proper latch (keep the previous winner until the other exceeds it by the band).
I have implemented dynamic prioritization via ioBroker currently and I remember it was pretty counter-intuitive and the documentation did not cover the topic to its full complexity.
When I remember right, the priority was not the only relevant component. I had to adjust the loadpoint delay (the surplus time after which the loadpoints starts charging).
I think this is not covered by this commit, right? In my local implementation, the loadpoint of the prioritized car always gets the smaller delay, so I make sure this is actually the one that starts charging first.
One has to consider the actual time until the car starts charging. When the car needs a minute to start charging (after power is supplied) the second loadpoint must have at least 1 minute plus the evcc control interval delay more than the first.
I set the delay to 3 minutes for primary LP and 6 minutes for secondary LP.
One caveat: it's a stateless deadband, not a latch, so there can still be one-step chatter right at the band edge. That only shifts flexible-power allocation, not charge/stop. If you'd prefer flap protection out of the box, I can ship a small non-zero default, or make it a proper latch (keep the previous winner until the other exceeds it by the band).
Out of curiosity: did you write that or AI?
I have implemented dynamic prioritization via ioBroker currently and I remember it was pretty counter-intuitive and the documentation did not cover the topic to its full complexity.
When I remember right, the priority was not the only relevant component. I had to adjust the loadpoint delay (the surplus time after which the loadpoints starts charging).
I think this is not covered by this commit, right? In my local implementation, the loadpoint of the prioritized car always gets the smaller delay, so I make sure this is actually the one that starts charging first.
One has to consider the actual time until the car starts charging. When the car needs a minute to start charging (after power is supplied) the second loadpoint must have at least 1 minute plus the evcc control interval delay more than the first.
I set the delay to 3 minutes for primary LP and 6 minutes for secondary LP.
@andig would you be so kind and quickly give your 5 cents? I never understood the worth of "priority". Without adjusting the lp delay it's not enough right?
When there is only enough energy to charge one car with surplus, both cars would initiate the charge and then the car with less priority would stop.
One caveat: it's a stateless deadband, not a latch, so there can still be one-step chatter right at the band edge. That only shifts flexible-power allocation, not charge/stop. If you'd prefer flap protection out of the box, I can ship a small non-zero default, or make it a proper latch (keep the previous winner until the other exceeds it by the band).
Out of curiosity: did you write that or AI?
AI did write that i'm mostly on the phone giving instructions. That was me with fingers on my keyboard :D
We appreciate human interaction. That „one caveat“ is the telltale sign, plus the general wording…
Can you publish the EffectivePriorityScore via API, so we can see the results? Then I can make the load point delay consistent to the calculated priority (via ioBroker).
hey steve, i've implemented what you wished for ;) effectivePriorityScore is now in the loadpoint API
Hi Alex, our of curiosity: how did you set the loadpoint delays?
My observation: When both are set to the same delay, both cars initiate a charge when surplus is sufficient and then the car/lp with the lower priority stops charging.
Adds a per-loadpoint priorityStrategy that sub-orders loadpoints within the same priority tier
What happens when we have 2 lps with identical priority but different strategies? Wondering if strategy doesn't have to be a global thing rather than per loadpoint?
Also- and this may get messy later on- the optimizer won't be aware of such a strategy. Not sure what this will amount to then?
you're right, mixing strategies in one tier makes no sense (soc gap vs deficit gap)
- moved strategy/basis/hysteresis to site config, per-loadpoint config removed (407b8bf)
- per-tier basis locking gone, prioritizer simpler now
optimizer:
- doesn't read priority at all today, plans each vehicle on its own against tariff/forecast
- strategy only changes how the prioritizer splits surplus each cycle, same place where int priority already acts
- so no change for the optimizer vs plain priority. if it ever needs it, the published score is there to read
@ScumbagSteve staggered by hand here too
- 60s enable on the prioritized lp, 120s the other, 180s disable both
- with #31684 not needed anymore between different priorities
- same priority: still needed, see my comment on the issue
same priority: still needed, see my comment on the issue
with #31194 merged we might as well fix that here? Do you want to compare actual score value or score classes?
@ScumbagSteve do you need a binary for testing? We can easily trigger that per PR now :)
I work in docker environment. I usually build the docker locally from a branch.
I can test this. @Alexxtheonly do you generate log entries according to what the system determined? This helps massively for testing.
score value, not classes
- with no strategy set the fractional term is 0, so the score is just the int tier again. comparing score in reservedPVPower comes out identical to what #31684 does today, nobody using plain priority sees a change
- with a strategy set the score is the only thing that gives startup order inside a tier. classes can't do it, both cars sit in the same class so reservedPVPower reserves for neither and the enable race stays as is
- so comparing score is a strict superset of the int compare, same behavior when the fraction is 0
the prioritizer already applies the hysteresis band at comparison, so reservedPVPower needs the same band. otherwise it reserves surplus for a car at startup that then loses in steady state and you get flap. equal within the band behaves like your equal-tier case today: neither reserves, both race
happy to fold it into this PR instead of a separate one. i'll wire reservedPVPower to compare the score with the band and add a test for the within-tier startup case
Pushed d2a2f68c5 to this branch — the three priority settings are now behind the experimental flag.
They moved out of ControlModal into a dedicated PriorityModal, surfaced as its own entry under config > general with v-if="experimental". Same shape as the battery grid discharge setting in #32086 (177ca558c): dedicated modal, 🧪 in the title, no server-side guard, UI gating only. ControlModal is back to its pre-PR state.
i18n keys moved from config.control.* to a config.priority.* block, with the option labels nested under strategy.* and basis.* so the general entry and the selects can both index them by enum value.
npm run lint (prettier, eslint, vue-tsc, i18n check) and npm test are green. No Go changes.
One thing left for you: the branch conflicts with master (mergeable_state: dirty) — last merge from upstream was 2026-07-12. Worth a merge before this comes out of draft.
🤖 Generated with Claude Code
Merged current master into the branch (ec7cef0e6) — mergeable is green again.
Four conflicts, all keep-both: the generalconfig entry and modal registration collided with the battery grid discharge entry from #32086, core/keys/site.go with the solarAdjusted key, and loadpoint_effective_test.go where TestEffectivePriorityScore and the new TestEffectiveMinSoc were inserted at the same spot. Took master's RemoteModal signature (it gained :site-title).
Verified after the merge: go build ./..., go vet, go test ./core/..., npm run lint, npm test all pass. Regenerated the openapi/mcp docs and the loadpoint/api mocks — no drift, the textual merge was already consistent.
🤖 Generated with Claude Code