Skip to content

feat(easee): driver-side improvements from 1Φ↔3Φ hardware test - #207

Merged
erikarenhill merged 5 commits into
masterfrom
feat-easee-driver-improvements
Apr 27, 2026
Merged

erikarenhill merged 5 commits into
masterfrom
feat-easee-driver-improvements

Conversation

@erikarenhill

Copy link
Copy Markdown
Collaborator

Summary

Five driver-only improvements to drivers/easee_cloud.lua derived from the live ramp test we ran in PR #206's session. No Go-side changes; the Lua file is hot-reloadable on a running Pi.

What we observed

The hardware test (1Φ × 6/7/8/9 A, then 3Φ × 6/7/8/9/10 A, 60 s observation each) revealed:

Phenomenon Latency
phaseMode POST → cloud accepts ~50–200 ms
phaseMode POST → observation API reflects ~5–30 s
dynamicChargerCurrent reset to maxChargerCurrent after phaseMode change window of ~5–10 s before our next write lands
Full phase transition + EV ramp to steady state ~60–90 s
Silently-rejected phaseMode writes when firmware is locked ∞ (the API just returns 200 OK with no effect)

Five fixes

  1. Default MinPhaseHoldS 60 → 90 s. A 60 s hold could let a flap-prone wantW trigger another transition mid-ramp.
  2. Optional max_charger_current config field. Clamps the charger's static maxChargerCurrent at init via the settings API, bounding the post-phaseMode-reset window.
  3. Firmware-settings probe at init. Logs phaseMode and maxChargerCurrent as the charger itself has them committed. Saves 30 minutes of "why is my phaseMode write being ignored?" debugging next time.
  4. Forced dynamicChargerCurrent re-assert on next driver_poll. After a successful phaseMode change, schedules a re-write ~5 s later to overcome Easee's post-transition reset without waiting for the controller's 5 s tick.
  5. Emit actual_amps_per_phase in the ev telemetry. Derived from totalPower / per-phase voltage / phases. Operators can now compare "what we asked for" (max_a, which echoes our last write with ~5-10 s lag) against "what the EV is actually drawing" (actual_amps_per_phase, live).

What is NOT in this PR

  • No Go side changes — controller, MPC, telemetry types all unchanged.
  • No "ramp-in-progress" telemetry flag for MPC consumption — that needs a Go consumer too, deferred.
  • No phase-transition-cost metric for the planner DP — same reason.

Test plan

  • gopher-lua syntax check (the full driver chunks cleanly).
  • go test ./... green (no Go changes, no regressions).
  • Re-run the 9-step ramp on hardware and verify:
    • Easee: firmware settings — phaseMode=…, maxChargerCurrent=… appears at init.
    • On the 1Φ→3Φ flip step, Easee: re-asserted dynamicChargerCurrent=N A after phaseMode reset appears within ~5 s of the phaseMode → 3 log line.
    • actual_amps_per_phase in /api/status drivers easee-cloud matches the requested amps within charger losses.

🤖 Generated with Claude Code

erikarenhill and others added 3 commits April 26, 2026 22:24
Five field-tested improvements to the Easee driver, all driver-only —
no Go side changes. Derived from the 1Φ↔3Φ ramp test we ran on a
real charger:

  * **Default MinPhaseHoldS 60 → 90 s.** Field-measured: a phaseMode
    flip + EV ramp to steady state takes 60–90 s. A 60 s hold could
    let a flap-prone wantW trigger another transition mid-ramp; 90 s
    gives one full ramp cycle before another flip.

  * **Optional `max_charger_current` config.** When set, driver
    writes it to the charger's static maxChargerCurrent at init.
    After every phaseMode change Easee resets dynamicChargerCurrent
    to maxChargerCurrent — clamping that ceiling bounds the
    post-transition window. Defaults unset (no-op) for backward
    compat; sites with maxChargerCurrent oversized vs the per-phase
    fuse should set this.

  * **Firmware-settings probe at init.** Driver fetches the charger's
    own settings (phaseMode, maxChargerCurrent) and logs them. We
    spent 30 minutes debugging silently-rejected phaseMode=1 writes
    in the field because the box was firmware-locked to phaseMode=3
    and Easee's API just returns 200 OK with no effect. Logging the
    firmware-side phaseMode at init makes that case immediately
    obvious.

  * **Forced `dynamicChargerCurrent` re-assert on next poll.** After a
    successful phaseMode change, schedules one re-write of
    last_amps_set ~5 s later (next driver_poll). Defends against
    Easee's post-transition reset of dynamicChargerCurrent → 16 A
    without waiting for the controller's 5 s tick. Idempotent if the
    controller's tick beats us to it.

  * **Emit `actual_amps_per_phase`.** Derived from totalPower and
    per-phase voltage in the ev telemetry. Operators wanting "is the
    EV actually drawing what we asked for?" can now compare
    actual_amps_per_phase against max_a (which only echoes our last
    write and lags ~5–10 s on the Easee cloud).

No tests added — the project has no Lua test harness yet, and these
are observability + post-transition timing tweaks best verified
against real hardware. Validated via gopher-lua syntax check + the
ramp test described in PR #206's session log.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…(POST-only)

Easee's API isn't symmetric — /settings only accepts POST writes,
GET there returns 405 Method Not Allowed. The static config (phaseMode,
maxChargerCurrent, …) is exposed at /config for reads.

Caught at init the first time the driver-improvements PR ran on
hardware: 'Easee: could not read firmware settings: HTTP 405'.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Easee Cloud Lua driver (drivers/easee_cloud.lua) with operational improvements discovered during live 1Φ↔3Φ ramp testing, focused on stabilizing phase switching behavior and improving operator diagnostics.

Changes:

  • Increase the default minimum phase-hold hysteresis from 60s to 90s to reduce mid-ramp flapping.
  • Add firmware settings probing at init plus an optional max_charger_current clamp (via settings API) to bound the post-phase-change reset window.
  • Add a one-shot “re-assert dynamicChargerCurrent” behavior after phase changes and emit a new diagnostic telemetry field (actual_amps_per_phase).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread drivers/easee_cloud.lua Outdated
Comment on lines +312 to +315
-- maxChargerCurrent, etc.) so the driver can detect a firmware lock
-- that would silently ignore our phaseMode writes. Easee's API uses
-- `/config` for reads and `/settings` for writes — they're not
-- symmetric. Returns the decoded table or nil + err string.
Comment thread drivers/easee_cloud.lua Outdated
Comment on lines +455 to +457
local actual_amps_per_phase = 0
local v_obs = obs[OBS_VOLTAGE]
if power_w > 0 and phases > 0 then
Comment thread drivers/easee_cloud.lua Outdated
Comment on lines +489 to +493
else
host.log("warn", "Easee: dynamicChargerCurrent re-assert failed: " ..
redact_http_err(werr))
end
pending_amp_resend = false
Comment thread drivers/easee_cloud.lua Outdated
Comment on lines 548 to 574
@@ -445,6 +553,7 @@ function driver_command(action, power_w, cmd)
phases = requested_phases
last_sent_phases = requested_phases
last_phase_change_ms = now_ms
phase_changed = true
host.log("info", "Easee: phaseMode → " .. tostring(requested_phases))
else
host.log("warn", "Easee: phaseMode write failed; skipping current write to avoid overcurrent on stale phase: " ..
@@ -463,6 +572,18 @@ function driver_command(action, power_w, cmd)
local _, err = host.http_post(
BASE_URL .. "/chargers/" .. charger_serial .. "/settings",
body, auth_headers())
Comment thread drivers/easee_cloud.lua
Comment on lines 472 to +475
cable_locked = cable_locked,
max_a = dyn_current, -- current dynamic limit (A)
phases = phases, -- from config.phases; default 3
max_a = dyn_current, -- last-set dynamic limit (echoes our write, may lag)
actual_amps_per_phase = actual_amps_per_phase, -- live per-phase A derived from totalPower
phases = phases, -- our committed phase count (1 or 3)
Comment thread drivers/easee_cloud.lua Outdated
local function read_settings(serial)
local resp, err = host.http_get(BASE_URL .. "/chargers/" .. serial .. "/config", auth_headers())
if err then return nil, redact_http_err(err) end
return host.json_decode(resp), nil
erikarenhill and others added 2 commits April 27, 2026 08:32
Six findings, all valid:

  * easee_cloud.lua:315 — read_settings doc claimed "detect a
    firmware lock" but the implementation only logs settings. Active
    detection (compare requested phaseMode after a write / periodic
    re-read) is a follow-up; reword the comment to match what the
    driver actually does (diagnostic logging at init).
  * easee_cloud.lua:319 — host.json_decode failure was treated as
    "no error", silently skipping the settings log. Now returns
    `nil, "decode failed (non-JSON response)"` so init logs a clear
    warning distinct from HTTP errors.
  * easee_cloud.lua:457 — actual_amps_per_phase used the global
    `phases` which can be 2 when config.phases=2 is misconfigured,
    or before the first successful phaseMode write. Dividing by 2
    yields a non-physical "per-phase" value. Now emitted only when
    phases ∈ {1, 3}; otherwise nil so the field is omitted from the
    payload rather than misleading.
  * easee_cloud.lua:493 — pending_amp_resend was cleared
    unconditionally even on POST failure, so a transient network
    error left the charger pinned at maxChargerCurrent. Now cleared
    only on successful re-write; failures retain the flag and
    retry on the next poll.
  * easee_cloud.lua:574 — driver_command's two raw http_post calls
    to /settings now route through the existing write_setting()
    helper for consistent encoding/auth/error handling.
  * api.go:383 — actual_amps_per_phase from the ev emit is now
    surfaced through /api/status as ev_actual_amps_per_phase. PR
    description said this would appear without Go changes; that
    was wrong. Added the field to the EV-status decode struct so
    the operator can compare requested vs actual amps directly.

Build green; gopher-lua syntax check OK; full test suite green
incl. test/e2e.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@erikarenhill

Copy link
Copy Markdown
Collaborator Author
image

@erikarenhill
erikarenhill merged commit 79ddf07 into master Apr 27, 2026
1 check passed
@erikarenhill
erikarenhill deleted the feat-easee-driver-improvements branch April 27, 2026 09:31
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.

2 participants