Repository navigation
feat(chargers): current-limit control for alfen, abb_terra and mennekes (1.1.0) - #242
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba0f0597b7
ℹ️ 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".
| control: false | ||
| setup: [device_ui] | ||
| ders: [ev] | ||
| control: true |
There was a problem hiding this comment.
Gate charger control until hardware acceptance is complete
All three charger manifests now advertise control even though their notes explicitly say it has not been confirmed on hardware, and the added tests exercise only mocked Modbus responses. This violates the control acceptance gate in AGENTS.md, which requires HIL acceptance for every target host. In particular, the newly supported HCC3 retains its last current limit indefinitely after host loss, so mocked command/default-mode tests do not establish a bounded safe outcome. Keep these new actuation paths read-only until the required hardware acceptance is recorded; marking them experimental does not satisfy that gate.
AGENTS.md reference: AGENTS.md:L34-L35
Useful? React with 👍 / 👎.
| local phases = cmd.phase_mode == "1p" and 1 or 3 | ||
| if seen_phases > phases then phases = seen_phases end | ||
| local amps = power_w / (voltage * phases) |
There was a problem hiding this comment.
Include the HCC3 phase count when converting watts to amps
For an HCC3 charging on three phases, a 1p order can deliver three times the requested power despite the driver already reporting phases = 3. poll_hcc3() returns an empty current table, so driver_poll() never increases seen_phases, and this conversion consequently uses one phase regardless of the HCC3 phase register. With the existing host mock, a three-phase HCC3 given a 3680 W order at 230 V writes 16 A per phase, allowing 11040 W. Feed the HCC3's reported phase count into the control divisor so the same phase-safety protection used by the ECU path also applies here.
Useful? React with 👍 / 👎.
…es (1.1.0)
Fredrik decided on 21 Nov 2026 that a driver which can command its device
ships with control on. These three were community sketches: no DRIVER
table, no driver_command, and a v2x_charger emit, so Core could not use
them as loadpoints. Their registers were also wrong: ABB's 1000-1037 and
Mennekes' 100-300 are in no vendor map, and Alfen read current sum as
voltage, apparent power as session energy and a state string as a number.
Each driver now reads and writes the vendor's documented registers, emits
ev with DRIVER.capabilities = { "ev" }, and is marked experimental:
- alfen: Modbus server max current (1210, FLOAT32), from Alfen's Modbus
for ACE guide. Rewritten every 15 s while Core orders, inside the
charger's validity time; after that the charger falls back to its safe
current.
- abb_terra: charging current limit (0x4100, mA), from ABB's TAC Modbus
Communication v1.7. The charger treats reads as contact.
- mennekes: ECU HEMS_CURRENT_LIMIT (1000) from the ECU Modbus TCP Server
Specification rev 1.07, and HCC3 current limitation (0x0400) from the
AMTRON Modbus description v1.031. The driver detects which map.
All three: amps per phase from power, voltage and the larger of Core's
phase mode and the phases seen; capped by the fuse, cap_amps_per_phase and
the device maximum; rounded down; 0 A below 6 A. Writes only on change,
plus the refresh a device needs. Pause holds 0 A through Core's contactor
cycle. Default mode writes 0 A once, only after FTW wrote, and stops after
three refusals. A refused write returns false. Lua tests cover each rule.
Not yet confirmed on hardware.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
Review of #242 found two fuse risks and two stuck states. - Phases. A 1p order on an idle charger wrote P/V, which a three-phase car draws on every phase; on the HCC3, which measures no currents, a 7360 W 1p order became 32 A. These drivers do not switch phases. They now divide by one phase only when config says `phases: 1` and the charger shows no more, or when Core orders 1p and the car is measured on exactly one phase. Otherwise three. Alfen 1215 and HCC3 0x0308 are a floor. - Alfen word order. In the wrong order 6.2 A reads as about 2.7e23 A. The driver now learns the order from a value plausible in only one order, and until then reports nothing and refuses every current above 0 A. - Reads that missed three times were never asked again, so a charger offline at boot never came back. Optional blocks are now retried once a minute; each map's main block is asked every poll, so Core never reloads the driver and forgets what FTW wrote. - ev_start and ev_resume with no order yet return false. - The HCC3 stand-down and the gaps after a Core crash are now stated in the driver and the manifest. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Fredrik Ahlgren <[email protected]>
ba0f059 to
ff73e62
Compare
Brings in #242. The generated files regenerate unchanged. Signed-off-by: Fredrik Ahlgren <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
On 21 Nov 2026 Fredrik decided that a driver which can command its device ships with control on, and one that cannot says so plainly.
alfen,abb_terraandmennekeswere community sketches: noDRIVERtable, nodriver_command, and av2x_chargeremit. Core treats a driver as a charger only whenDRIVER.capabilitiescontains"ev", so none of them could be a loadpoint.Their registers were also wrong:
abb_terraread 1000-1037. ABB's map starts at 0x4000.mennekesread 100-300. Those registers are in neither Mennekes map.alfenread 326 as voltage (it is current sum), 346 as session energy (apparent power L1), and 1201 as a number (a 5-register Mode 3 string). It also reported NaN as 0.Change
Each driver now reads and writes the vendor's documented registers. Each also emits
ev, declarescapabilities = { "ev" }, setsverification_status = "experimental"andcontrol: true. Thetested_devicesnotes say "not yet confirmed on hardware".alfenabb_terramennekesECU (AMTRON Professional, Charge Control, AMEDIO)mennekesHCC3 (AMTRON Xtra, Premium)mennekesworks out which map a charger speaks on its first polls: an ECU answers holding 122 with 1-5, otherwise the HCC3 input block is tried.family: ecu|hcc3in config skips this. Mennekes marks the HCC3 document confidential, so the driver names it but does not link it; evcc and others use the same addresses. The other three documents are inupstream_docs.Rules in all three drivers
power_w / (voltage × phases), rounded down to the device step: 0.1 A for Alfen and ABB, 1 A for Mennekes.phases: 1and the charger shows no more, or when Core orders 1p and the car is measured drawing on exactly one phase. Otherwise it divides by three. Alfen 1215 and HCC3 0x0308 are a floor.max_amps_per_phase,cap_amps_per_phase, the device maximum (32 A, ABB 0x4006, HCC3 rated or installed current) or an optionalmax_ain config. Below 6 A the driver writes 0 A and never rounds up.ev_pausewrites 0 A and holds it for 10 s through Core's 3 s contactor cycle.ev_resumeandev_startrestore Core's last order, and return false when there is none yet.max_ais the device's setpoint register.current_limit_ais what the device actually offers (Alfen 1206, ECU 706, ABB 0x400E). A failed read stays nil, and noevis emitted without power.request_active(false in B2),command_stalled(the charger sent no PWM for 30 s under an offer of at least 6 A), andreason_no_current_label.Alfen's 2025 guide says 32-bit words come low word first and that 1 should be subtracted from register numbers. evcc and the Home Assistant driver do neither. The driver uses the table numbers as they stand. In the wrong word order 6.2 A reads as about 2.7e23 A, so the driver does not guess. It learns the order from a value plausible in only one order: a phase voltage, the safe current, or the applied or written current. Until then it reports nothing and refuses every current above 0 A. 0 A is all zero bits, the same in both orders.
Tests
Run locally, after the rebase onto
main:New harness tests:
drivers/tests/lua_harness/test_{alfen,abb_terra,mennekes}_control.lua, with.pywrappers. They cover:phases: 1, Alfen 1215 and HCC3 0x0308 = 3 as a floor, and the first order after a re-plug1,1,1,0,0,0)refused-write-reportshows no writes because its probe never commands first, and default mode writes only after FTW has. The harness tests cover refusals after a command.The three drivers were also run under Core's own gopher-lua host (
NewLuaDriverwith a fake Modbus, from a scratch Core worktree that is not committed). The run covered:All three drivers come off
invented-number-baseline.json.test_all_drivers.luanow expectsev.Open risks
phases: 1in config, unless the car is measured on one phase under a 1p order. A one-phase car on a charger set to three phases gets a third of a 1p order. That is safe, but slow.Generated files
index.yaml,devices.yaml,support-status.jsonandSUPPORT_STATUS.mdwere regenerated after the rebase ontomain. Other charger PRs running in parallel may still conflict on them.🤖 Generated with Claude Code