Skip to content

fix(control): give a planned EV its fuse share on the worst phase - #1536

Merged
frahlg merged 1 commit into
masterfrom
ev-first-per-phase
Oct 8, 2026
Merged

frahlg merged 1 commit into
masterfrom
ev-first-per-phase

Conversation

@frahlg

@frahlg frahlg commented Oct 8, 2026

Copy link
Copy Markdown
Member

Problem

A tester on v0.140.0-beta.1 (Easee Cloud, Pixii, 25 A three-phase fuse) saw the EV sheet say "Not following. Asked for 11.0 kW charge, delivering 8.3 kW. The charger has not said why." The battery was charging 4.75 kW at the same time, and the charger's load balancer had cut the car to 12 A per phase.

Core already lets a planned EV charge take its share of the fuse before optional battery charge. The rule counted only the site total: 25 A × 3 × 230 V less the margin is 16.9 kW, and 11 + 4.75 + about 1.1 kW of house load fits. With most of the house load on one phase, that phase does not fit. The load balancer acts on the worst phase before the per-phase guards in Core see an overage, so the battery kept the headroom and the car lost it.

Change

  • control/fuse_phase.go: phaseImbalanceA is the worst phase current less the mean phase current from the aggregate of the same meter sample. A three-phase battery or charger adds equal current to every phase, so this gap is import the aggregate budget cannot use. phaseImportCeilingW takes it off the fuse ceiling. A tariff peak is a billing total, so the imbalance is never taken off it.
  • The joint allocator in ComputeDispatch and republishFuseEVCapAfterFuseDischarge use that ceiling. In the reported case the battery drops to about 3.1 kW, the car keeps 11 kW and L1 lands at 24.5 A. If the car itself cannot fit, it is capped with fuse_limit and shows as limited, not as an unexplained warning.
  • Planner: each replan takes the live imbalance off MaxImportW for slots that start within the next hour (limitNearImportForPhases), never below a slot's own forecast net load, and never loosening a tighter limit. Later slots keep the full fuse because house load moves between phases. The fuse-saturation edge already triggers a replan, so the plan moves battery charge out of the clipped hour. mpc: optimize params logs phase_imbalance_w.

Balanced phases change nothing. A meter without every configured phase current falls back to the aggregate ceiling.

Limits

  • Meters report phase magnitudes. When phases flow in opposite directions the gap is understated; the existing per-phase guards still act on a real overage.
  • A single-phase battery or charger is outside the model, as it already is for perPhaseReliefW.
  • If a charger's load balancer is set tighter than fuse.max_amps, Core cannot see that. Making the Easee driver report its load-balancing reason while charging is a separate follow-up.

Evidence

  • TestScheduledEVGetsWorstPhaseBeforeBatteryCharge reproduces the report and fails on master (cap 0 saturated false).
  • TestBalancedHouseKeepsBatteryCharge, TestPhaseImportCeiling, TestLimitNearImportForPhases, TestReplanLimitsNearImportForPhaseImbalance.
  • make verify passes locally. Not yet run on hardware.

🤖 Generated with Claude Code

The joint fuse allocator and the planner's import limit counted only the
site total. With house load mostly on one phase, 11 kW EV + 4.75 kW
battery + house fits under a 25 A three-phase fuse in total, but not on
the worst phase. The charger's own load balancer then cut the car to
12 A before any FTW per-phase guard saw an overage, and the UI showed
"Not following" with no cause.

The allocator now takes the worst phase's imbalance off its import
ceiling, so optional battery charge yields to the planned car on that
phase. Each replan takes the same live imbalance off the import limit of
the next hour of slots, never below a slot's own net load. Balanced
phases and tariff peaks are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T04:47:14.132685Z 86c01ee PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 86c01eeee5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if p == nil || math.IsNaN(*p) || math.IsInf(*p, 0) {
return 0, false
}
worst = math.Max(worst, math.Abs(*p))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve phase direction when deriving import headroom

When phases flow in opposite directions, taking each current's absolute value treats an exporting phase as the worst import phase. For example, signed currents of -20/+10/+10 A at zero aggregate power produce a 20 A “imbalance,” limiting a 25 A three-phase site to only 5 A of balanced additional load per phase, although 15 A per phase fits before L2/L3 reach the fuse. Pixii supplies signed currents—perPhaseOverageReadingW explicitly documents negative export—so this unnecessarily strips several kW from planned EV and battery charging on sites with phase-local PV; retain the signed values when deriving import headroom.

AGENTS.md reference: AGENTS.md:L63-L64

Useful? React with 👍 / 👎.

Comment on lines +1584 to +1585
limitNearImportForPhases(slots, now, fuseMaxW, phaseImbalanceW)
limitNearImportForPhases(fallbackSlots, now, fuseMaxW, phaseImbalanceW)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Apply the phase limit after the downside-PV transform

When forecast-risk planning is enabled, this floors fallbackSlots against the point-forecast net load, but applyPVDownsidePerSlot later reduces PV at lines 1636–1637 without updating the import limit. If that haircut raises net load above the phase-adjusted ceiling—especially with the battery at SoCMin—even the idle action becomes infeasible; coreReservePlan returns an empty plan and validation retains the previous plan, so fuse-saturation replans can repeatedly fail. Apply or refloor the phase limit after the downside/risk transforms using the final slot inputs.

Useful? React with 👍 / 👎.

@frahlg
frahlg merged commit 4000391 into master Oct 8, 2026
@frahlg
frahlg deleted the ev-first-per-phase branch October 8, 2026 04:47
frahlg added a commit that referenced this pull request Oct 17, 2026
Fredrik's rule (17 Oct): never trust slow current values from an Easee
or any other device. The EV hard limit, the split between cars, the
EV/battery split and the #1536 allocator now read only the site meter
and FTW's own recent commands, kept for the 20 s a command takes to
reach the meter.

A rise needs a fresh reading with room for two steps and waits until
the meter shows the last change (import rose with it, or 20 s passed).
Every increase leaves a step free. An idle pool restarts only after 35 s
of measured room; a meter gap starts the count again, and a silent
meter's repeated reading never acts twice. Battery commands, not
readings, set the battery's baseline and pending range.

Removes the bracketed EV and battery credit and ev_pending_battery.go.
Overlaps #1675.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
frahlg added a commit that referenced this pull request Oct 17, 2026
…mands (#1674) (#1695)

* fix(control): the EV hard limit follows the site meter (#1674)

The EV hard cap credited a car only when its own readings bracketed a
site reading. Easee Cloud reports late and on change only, so missing
proof or one 0 W sample counted the car as house load and stopped the
charge (05:49: 2,449.5 W of credit at 20.45 A on a 25 A fuse), and an
import ceiling made the charger start and stop every half minute.

EVFuseBudget now cuts by the overage the meter measures on the worst
phase or in total import, taken from the highest offer the meter may
still contain. It holds inside the limits, rises one 1 A step when the
meter shows room and the cars have taken the last step, and restarts an
idle pool only with room for its minimum plus a step. EV readings only
gate a rise. In the loadpoint split, keeping an offer on the same
phases is no longer an increase, and the phase gate no longer cuts.

The bracket credit for the EV cap, the common battery reserve and the
dead reactive phase clamp are removed. Overlaps #1675.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix(control): the EV guard trusts only the meter and our own commands

Fredrik's rule (17 Oct): never trust slow current values from an Easee
or any other device. The EV hard limit, the split between cars, the
EV/battery split and the #1536 allocator now read only the site meter
and FTW's own recent commands, kept for the 20 s a command takes to
reach the meter.

A rise needs a fresh reading with room for two steps and waits until
the meter shows the last change (import rose with it, or 20 s passed).
Every increase leaves a step free. An idle pool restarts only after 35 s
of measured room; a meter gap starts the count again, and a silent
meter's repeated reading never acts twice. Battery commands, not
readings, set the battery's baseline and pending range.

Removes the bracketed EV and battery credit and ev_pending_battery.go.
Overlaps #1675.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix(control): keep our last offer across a restart; battery holds its order

Core restarts on every update. The pool counted a charging car as idle
on the first tick and, at 05:49 currents (2,449.5 W of room), stopped it.
FTW now saves its own last order per charger, keyed by hardware
identity, and restores it as the hold base while the same plug-in
session is connected: a matching session id, or a session energy
counter that has not gone back, within 10 minutes.

A commands-only battery counted its own repeated order twice and
hunted. Keeping a battery's latest order is now never an increase;
a measured shortfall takes charge back and new charge needs room after
our unseen increases. A command log younger than the settle time
counts the time before it as 0, so a new EV offer is not taken as
already in the meter.

The EV limit reads the meter once (telemetry-read check 8 -> 5).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

---------

Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant