Skip to content

feat(chargers): current-limit control for alfen, abb_terra and mennekes (1.1.0) - #242

Merged
frahlg merged 2 commits into
mainfrom
charger-control-modbus-a
Nov 21, 2026
Merged

frahlg merged 2 commits into
mainfrom
charger-control-modbus-a

Conversation

@frahlg

@frahlg frahlg commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

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_terra and mennekes were community sketches: no DRIVER table, no driver_command, and a v2x_charger emit. Core treats a driver as a charger only when DRIVER.capabilities contains "ev", so none of them could be a loadpoint.

Their registers were also wrong:

  • abb_terra read 1000-1037. ABB's map starts at 0x4000.
  • mennekes read 100-300. Those registers are in neither Mennekes map.
  • alfen read 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, declares capabilities = { "ev" }, sets verification_status = "experimental" and control: true. The tested_devices notes say "not yet confirmed on hardware".

Driver Setpoint Vendor document Device stand-down
alfen 1210 Modbus server max current, FLOAT32 Alfen Modbus for ACE, Configuration Guide v1.0 After the validity time (default 60 s), falls back to the installer's safe current
abb_terra 0x4100 charging current limit, mA ABB TAC Modbus Communication v1.7 No read within the comm timeout (default 60 s): error state, session stops
mennekes ECU (AMTRON Professional, Charge Control, AMEDIO) 1000 HEMS_CURRENT_LIMIT, A Mennekes ECU Modbus TCP Server Specification rev 1.07 After COMM_TIMEOUT, falls back to SAFE_CURRENT
mennekes HCC3 (AMTRON Xtra, Premium) 0x0400 customer current limitation, A Mennekes AMTRON Modbus description v1.031 None: keeps the last value

mennekes works 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|hcc3 in 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 in upstream_docs.

Rules in all three drivers

  • Amps: power_w / (voltage × phases), rounded down to the device step: 0.1 A for Alfen and ABB, 1 A for Mennekes.
  • Phases: these drivers do not switch phases, and a 1p order alone proves nothing: a three-phase car would draw the 1p current on every phase. A driver divides 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 drawing on exactly one phase. Otherwise it divides by three. Alfen 1215 and HCC3 0x0308 are a floor.
  • Caps: never above max_amps_per_phase, cap_amps_per_phase, the device maximum (32 A, ABB 0x4006, HCC3 rated or installed current) or an optional max_a in config. Below 6 A the driver writes 0 A and never rounds up.
  • Writes: only on change, plus the refreshes a device needs:
    • Alfen: every 15 s while Core orders, or sooner when register 1208 shows 20 s or less left.
    • ECU: every 15 s, or a third of COMM_TIMEOUT.
    • A limit the device lost or someone changed is rewritten every 30 s at most.
    • Decreases go out at once.
    • Nothing is written from poll.
  • Pause and resume: ev_pause writes 0 A and holds it for 10 s through Core's 3 s contactor cycle. ev_resume and ev_start restore Core's last order, and return false when there is none yet.
  • Default mode: writes 0 A once, and only after FTW wrote a setpoint in this process. This follows the heishamon 0.8.1 rule: Core runs default mode at every start, so a telemetry-only site must not be paused. Default mode stops after three refused writes.
  • Honest results: a refused write returns false.
  • Reads: each map's main block is read every poll, so Core never reloads the driver and forgets what FTW wrote, and ABB's comm timeout stays fed. Other blocks, and Mennekes detection, are retried once a minute after three misses, so a charger offline at boot comes back.
  • Read back: max_a is the device's setpoint register. current_limit_a is what the device actually offers (Alfen 1206, ECU 706, ABB 0x400E). A failed read stays nil, and no ev is emitted without power.
  • Fields emitted: request_active (false in B2), command_stalled (the charger sent no PWM for 30 s under an offer of at least 6 A), and reason_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:

make test-driver ID=alfen        # 41 passed, 14 skipped
make test-driver ID=abb_terra    # 41 passed, 14 skipped
make test-driver ID=mennekes     # 41 passed, 14 skipped
make refused-write-report ID=<each>   # DEFAULT_MODE SETTLED 1 WRITES 0,0,0,0,0,0,0,0
make check                       # 4997 passed, 929 skipped

New harness tests: drivers/tests/lua_harness/test_{alfen,abb_terra,mennekes}_control.lua, with .py wrappers. They cover:

  • power-to-amps mapping, the minimum, rounding down and every cap
  • the phase rule: a 1p order on an idle three-phase charger, one phase measured, config phases: 1, Alfen 1215 and HCC3 0x0308 = 3 as a floor, and the first order after a re-plug
  • pause, resume, the pause hold, and resume or start before any order (false)
  • default mode that does nothing unasked and then writes once
  • refused writes that return false and stop default mode after 3 tries (1,1,1,0,0,0)
  • the refreshes: Alfen validity time and ECU COMM_TIMEOUT
  • a lost limit being rewritten
  • Alfen: a command before the word order is known writes nothing and returns false, while 0 A still goes through; a charger that sends low word first
  • retries: a block or a Mennekes detection that fails at boot is asked again after a minute, and the main block every poll
  • readings, NaN and 0xFFFFFFFF, and ECU firmware older than 5.22

refused-write-report shows 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 (NewLuaDriver with a fake Modbus, from a scratch Core worktree that is not committed). The run covered:

  • readings
  • a 7000 W order: Alfen wrote the FLOAT32 words for 10.1 A, ABB 10100 mA, Mennekes 10 A
  • a 7360 W 1p order on an idle charger: Alfen 10.6 A, ABB 10600 mA, and HCC3 with 0x0308 = 3 10 A
  • one phase measured: ABB 16000 mA, ECU 16 A
  • an Alfen that sends low word first, which was written low word first
  • an Alfen with no known word order: no reading, a positive order refused, 0 A written
  • pause, default mode, and a refused write coming back as an error

All three drivers come off invented-number-baseline.json. test_all_drivers.lua now expects ev.

Open risks

  • No hardware yet. Everything here comes from vendor documents.
  • Alfen setup: the charger takes a setpoint only with Active Load Balancing (a paid licence) set to "Energy Management System" and "Allow writing maximum currents" on. Register 1214 shows when it ignores the setpoint, which surfaces as a reason label. The command still returns true.
  • Alfen fallback: after a stand-down the charger returns to the installer's safe current, which may be higher than FTW's last order.
  • Alfen with no plausible value in any register the driver learns the word order from stays silent and uncontrolled.
  • HCC3 has no device timeout.
    • When Core stops or updates, default mode leaves it at 0 A and the car waits for Core's next order, as with easee_cloud.
    • If Core crashes, the charger keeps FTW's last limit.
    • A new process does not know an earlier one wrote, so its default mode writes nothing until FTW writes again. The driver does not guess from the limit register, because a limit the owner set in the app looks the same.
  • Single-phase sites need phases: 1 in 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.
  • ECU COMM_TIMEOUT: the spec does not say whether reads count as contact, so the driver refreshes by writing.
  • No identity yet for Alfen or the ECU: their serials are not in the socket map or the ECU map.

Generated files

index.yaml, devices.yaml, support-status.json and SUPPORT_STATUS.md were regenerated after the rebase onto main. Other charger PRs running in parallel may still conflict on them.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T17:02:43.376708Z ba0f059 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: 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".

Comment thread manifests/mennekes.yaml
control: false
setup: [device_ui]
ders: [ev]
control: true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment thread drivers/lua/mennekes.lua Outdated
Comment on lines +360 to +362
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

frahlg and others added 2 commits November 21, 2026 18:15
…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]>
@frahlg
frahlg force-pushed the charger-control-modbus-a branch from ba0f059 to ff73e62 Compare November 21, 2026 17:16
@frahlg
frahlg merged commit 49caac3 into main Nov 21, 2026
5 checks passed
@frahlg
frahlg deleted the charger-control-modbus-a branch November 21, 2026 17:21
frahlg added a commit that referenced this pull request Nov 21, 2026
Brings in #242. The generated files regenerate unchanged.

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