Repository navigation
feat(loadpoint,easee): 1Φ/3Φ auto-switching with per-phase fuse clamp - #203
Merged
Merged
Conversation
Adds phase-mode awareness to the loadpoint controller and the Easee
cloud driver so a 16 A site can deliver low-W charge sessions on a
single phase (≥ 6 A min), then flip up to three phases when the MPC
budget pushes past the per-phase ceiling.
Config (per-loadpoint):
loadpoints:
- id: garage
driver_name: easee
phase_mode: auto # "1p" | "3p" | "auto" — empty == "3p"
phase_split_w: 0 # 0 = derive from site fuse (V × A per phase)
min_phase_hold_s: 60 # hysteresis dwell, "auto" only
The split is derived from SiteFuse.MaxAmps × SiteFuse.Voltage so a
240 V or 220 V install is handled correctly without hard-coding 230 V.
The Easee Lua driver now also accepts a `voltage` field on the
ev_set_current command so its W→A conversion uses the same site
voltage instead of a baked 230.
Safety:
* Per-phase fuse clamp applied BEFORE step filtering AND a
second-line check after snapping so a misconfigured AllowedStepsW
can't punch through the breaker.
* On 1Φ↔3Φ transitions, the Easee driver POSTs phaseMode FIRST.
If that POST fails, the W→A write is skipped entirely — the
failure mode would otherwise compute amps against the old phase
count (e.g. 7400 W ÷ 1Φ = 32 A), trip a 16 A breaker. Controller
retries next tick.
* MinPhaseHoldS hysteresis (default 60 s) prevents contactor flap
when the MPC budget oscillates around the split. Locked modes
(1p, 3p) bypass the hold.
* Empty PhaseMode ("") behaves identically to legacy locked-3Φ —
no behaviour change for existing fleets on upgrade.
Tests: 12 (controller_phase_test.go). Covers auto split direction,
locked modes, fuse clamping at multiple breaker sizes, non-230V
voltage propagation, hysteresis, payload shape, and the zero-fuse
no-clamp guard.
Carved off the larger PR #184 review surface — extracted only the
phase-switching pieces; schedule persistence, MPC policy gates,
EV-first cost bias, and the live-load fuse clamp stay on the branch
for separate evaluation.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Reframes the phase-switching design after review feedback: deciding
1Φ vs 3Φ is a charger-physics question (knows its min/max amps,
contactor switching latency, manufacturer-specific phaseMode wire
format) — it does NOT belong in the cross-driver Go controller.
Wire-format change to the ev_set_current command:
Before: power_w + phases + voltage (controller decided phases)
After: power_w + phase_mode + phase_split_w + min_phase_hold_s
+ voltage + max_amps_per_phase + site_phases
(driver decides phases from operator preferences + site
fuse params)
The Go controller now does only what's universal: convert MPC's Wh
budget for the slot to a continuous wantW, snap to the loadpoint's
configured AllowedStepsW (a planning hint), and pass the operator's
phase_* preferences and the site fuse parameters through verbatim.
SetSiteFuse stays as a setter so main.go can inject the fuse values
once at startup.
Easee Lua now owns:
* pick_phases() — locked / auto with hysteresis using host.millis()
for the dwell timer (no Go-side state map per loadpoint anymore).
* per_phase_amps() — W → A conversion using the controller-supplied
voltage; clamps to the per-phase fuse ceiling AND to Easee's
physical 0/6/32 A band (round-not-floor so 5.8 A → 6 A clears the
minimum).
* The phaseMode-fail-safe early-return: if the phaseMode POST fails
on a transition, we abort the dynamicChargerCurrent write rather
than command 32 A on a now-stale 1Φ phase count.
Tests:
* controller_phase_handoff_test.go — 7 tests on the controller side
asserting the cmd JSON carries the operator preferences and site
fuse params correctly. Empty PhaseMode is omitted (legacy shape
preserved). The Voltage 240 V case proves no 230 V hardcode.
* phase_helpers_test.go — 9 tests on PhaseFor + FilterStepsByPhase
(now exported as advisory reference implementations). The Easee
Lua driver implements the same rule locally; these tests pin the
contract for any future Go-side driver.
Driver-side phase logic is verified against real hardware in
integration testing — there's no Lua test harness in the project
yet (followup).
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
erikarenhill
force-pushed
the
easee-phase-switching
branch
from
April 26, 2026 16:53
ece83e0 to
5c3d1df
Compare
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
Adds 1Φ ↔ 3Φ auto-switching for an Easee charger, carved off the larger PR #184 review surface. None of the bundled features that were entangled with the planner DP / loadpoint state surface (schedule persistence, policy gates
only_surplus/allow_grid/allow_battery_support, EV-first cost bias, live-load clamp) come along — only the phase mechanics + the Easee driver support.How it works in reality
Phase decisions live in the driver. The Go controller does not pick phases. Each EV charger has its own physics — the minimum amperage it accepts (Easee = 6 A), the maximum (32 A), the contactor + cloud-API round-trip latency for switching, the manufacturer-specific wire format for the phaseMode setting. Pushing that logic into the cross-driver controller would force every future Go driver to inherit Easee's assumptions. So the controller passes through what's universal — operator preferences and site fuse parameters — and lets each driver decide.
ev_set_currentcommand shape{ "action": "ev_set_current", "power_w": 4000.0, // MPC slot budget for this loadpoint "phase_mode": "auto", // "1p" | "3p" | "auto" (operator pref) "phase_split_w": 0, // 0 = derive from voltage × max_amps_per_phase "min_phase_hold_s": 60, // hysteresis dwell, "auto" only "voltage": 230.0, // site voltage from cfg.Fuse.Voltage "max_amps_per_phase": 16.0, // site fuse trip current per phase "site_phases": 3 // 1 or 3 }Empty
phase_modeis omitted from the cmd entirely — legacy fleets that don't read these fields see exactly the pre-switching shape and continue running locked-3Φ.The driver's decision (in
easee_cloud.lua)Pick phases.
pick_phases(mode, want_w, voltage, max_amps_per_phase, split_w, hold_s, now_ms):1p/3p→ return that, no hysteresis applied.auto→ effective split =phase_split_wif set, otherwisevoltage × max_amps_per_phase(so a 240 V × 16 A install splits at 3840 W, not the canonical 3680 W). Pick 1Φ whenwantW < split, else 3Φ.autoreadshost.millis()to compare against the timestamp of the last commit. If less thanmin_phase_hold_s × 1000ms have passed since the last flip, hold the previous phase regardless of what the new wantW would prefer. Easee's contactor + cloud-API round-trip is ~5–10 s observed; without the hold a wantW oscillating around the split would burn the contactor and never deliver useful power.Compute amperage.
per_phase_amps(power_w, voltage, phases, max_amps_per_phase):amps = round(power_w / voltage / phases)— round, not floor, so 5.8 A clears the 6 A minimum.[0, EASEE_MAX_A=32]AND to the per-phase fuse ceiling AND0 < amps < 6 → 0(Easee silently ignores writes below its minimum, which would leave the charger in a "I requested but nothing flows" zombie state — pause cleanly instead).POST
phaseModefirst whenrequested_phases != last_sent_phases. Easee's settings endpoint acceptsphaseMode = 1(locked-1p) or3(locked-3p); we never use2(auto) because hysteresis is our concern, not the charger's.phaseModePOST fails, the driver returnsfalseimmediately WITHOUT writingdynamicChargerCurrent. The alternative — computing amps against the unchanged phase count after a failed transition (e.g. 7400 W intended for 3Φ, written as 32 A on a single phase) would trip a 16 A breaker. Controller retries on the next tick; the operator sees aphaseMode write failedwarning in the logs.POST
dynamicChargerCurrentwith the clamped amperage.What the controller still owns
wantWviaremaining_wh × 3600 / remaining_s, accounting for what's already been delivered mid-slot.SnapChargeW(wantW, MinChargeW, MaxChargeW, AllowedStepsW)— operator's discrete step list is a planning hint that maps the smooth MPC budget to a charger-friendly target. The driver may further round to its own minimum amperage.Reference helpers (not called by the controller)
PhaseForandFilterStepsByPhaselive inloadpoint/snap.goas exported pure-Go helpers. The Easee Lua driver implements the same rule locally; these helpers are reference implementations for future Go-side drivers (and the test contract). The controller does NOT call them — phase decisions are entirely a driver-level concern.What does NOT land
Everything else from PR #184. The pieces below stay parked on
teslable-ev-surplusbecause each requires either MPC DP changes orManagerstate expansion to be functionally complete:loadpoint_schedulesSQLite table + cross-restartRestoreTargetonly_surplus,allow_grid,allow_battery_support) — DP-only enforcementgridW − evWheadroom math)DerVehicletelemetry typeTest plan
go test ./...(all green incl.test/e2e)controller_phase_handoff_test.go): cmd JSON carriesphase_mode/phase_split_w/min_phase_hold_s/voltage/max_amps_per_phase/site_phasescorrectly; emptyphase_modeis omitted; non-230 V site (240 V) propagates verbatim.phase_helpers_test.go):PhaseFor+FilterStepsByPhasecovering locked modes, empty default → 3Φ, auto split direction, non-standard voltage split, custom split override, empty input.phase_modeset continues to send 3Φ commands (no behaviour change); site withphase_mode: autoflips to 1Φ when MPC budget < per-phase ceiling.Followups (not blockers for this PR)
pick_phases/per_phase_ampscan have unit tests insidedrivers/.ev_set_currentcontract.🤖 Generated with Claude Code