Skip to content

feat(etrel, keba, schrack_ev): control the charging current; wallbox says it cannot - #244

Merged
frahlg merged 8 commits into
mainfrom
charger-control-modbus-b
Nov 21, 2026
Merged

frahlg merged 8 commits into
mainfrom
charger-control-modbus-b

Conversation

@frahlg

@frahlg frahlg commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Fredrik decided on 21 November 2026 that a driver that can command its device ships with control on, and one that cannot says so plainly (#239). Etrel, KEBA, Schrack and Wallbox were community sketches: no DRIVER block, no driver_command, v2x_charger output and register maps from no vendor document. Core uses a charger as a loadpoint only when DRIVER.capabilities holds "ev", so FTW could not use any of them.

Driver Result Route
etrel 1.1.0 controls Modbus TCP, Float32 current setpoint at holding 8 (function code 16)
keba 1.1.0 controls Modbus TCP, 5004 current in mA, 5014 enable (function code 6)
schrack_ev 1.1.0 controls Modbus RTU through a Modbus TCP gateway, 101 current, 100 authorisation
wallbox 1.1.0 cannot control, read_only = true We found no documented local interface. Use FTW's OCPP central system.

Every controlling driver:

  • turns power_w into amps per phase: power_w / (voltage × phases). Phases is one only when config says phases: 1 and the car has not drawn on more than one phase since it was plugged in, or when Core orders 1p and the car draws on exactly one. Otherwise it is three, idle or just started too, so a three-phase car never gets the L1 sum Core budgeted for a 1p order. Schrack measures no phases, so it uses only phases from config (default 3).
  • never exceeds max_amps_per_phase, cap_amps_per_phase or the charger's own limit (Etrel 1028, KEBA 1110, Schrack 127 and cable 128), and rounds down to 0.1 A (Schrack: 1 A). Below 6 A it writes 0 A or disables. It never rounds up.
  • writes only on change and applies decreases at once. A charger that offers more than the order 30 s after it was written (10 s for Schrack) gets it again. One that holds a charge paused against the order for 30 s (Etrel status 6, KEBA state 5) gets the setpoint or enable again on the next order, at most every 30 s.
  • on ev_resume and ev_start, which carry no budget, writes an order back only when it is under 30 s old. Otherwise it writes 6 A (KEBA and Schrack write the current before the enable or authorisation), and only when the limit named with the last positive order allows 6 A; a 0 W order carries no cap and does not replace it. With a limit below 6 A it writes nothing and returns false. With no limit known, after a reload for example, it writes nothing, returns true and logs once that the charger waits for Core's next order.
  • KEBA refreshes the failsafe timeout at half its length while FTW steers, paused or not, and while FTW holds the charger disabled after a stand-down. After three refusals it tries once a minute. Whether a failsafe current overrides a disable once FTW stops is not verified. KEBA counts phases only when all three phase currents answered in that poll, and tries a lost phase current again once a minute.
  • stands down in default mode (Etrel 0 A, KEBA 5014 = 0, Schrack 100 = 0) only after a command wrote in this run. Core runs default mode at every start, so a charger FTW never steered keeps its own state and a charge already running goes on (the heishamon 0.8.1 and zaptec_cloud 0.2.1 rule). After that it stands down once, then writes nothing. It returns true only when the stand-down is confirmed, or when FTW wrote nothing in this run. A refused stand-down returns false and is tried again at most once a minute, with no write in between.
  • returns false when a write fails or the device refuses it.
  • leaves a failed read out. It reports the charger's own offer as max_a, its ceiling as device_limit_a with age, and current_limit_a, reason_no_current_label and command_stalled from device state.

Old maps that were wrong:

  • Etrel read holding 300-312, which no Etrel list has.
  • KEBA read the error code as L1 current, voltages from the current, serial and product registers, lifetime energy as session energy, and register 5004, which is write-only.
  • Schrack read the charging authorisation as a state and power from registers Schrack does not list.
  • Wallbox reads registers 4-9, which no Wallbox document lists. The driver keeps them, says in its description that its power and energy are unverified, and no longer reports 0 for one that did not answer.

Driver evidence

  • Driver ids: etrel, keba, schrack_ev, wallbox
  • Device make/model: Etrel INCH Home/Pro/Duo (connector 1); KEBA KeContact P30 c-series and x-series; Schrack i-CHARGE CION Home and Semipublic
  • Firmware tested: none
  • Protocol/register source:
    • Etrel "INCH SmartHome Modbus TCP Registers" (2023 sheet, mirrored in RustyDust/sonnen-charger). Etrel's Knowledge Centre now lists V6.0 (August 2025, needs firmware 7.1.1), which I could not read.
    • KEBA "KeContact P30 Modbus TCP Programmers Guide" V1.07 (12.2025), and the P30 UDP Programmers Guide V2.05 for why UDP is not used.
    • Schrack "Modbus Register Tabelle CION Home und Semipublic" (2021, 2022, 2023) and the i-CHARGE CION operating manual V2.2, table 15.
    • Wallbox "OCPP activation and setup guide". evcc controls these Wallbox models over OCPP only.
    • evcc's etrel.go and keba-modbus.go were read for behaviour only. No code was copied.
  • Hardware test performed: none
  • Known limits:
    • Etrel: INCH Duo connector 2 is not covered. Session energy of 0 is left out, since some firmware never moves it (Etrel: Geladene Energie 0,0 kWh evcc-io/evcc#5346).
    • KEBA: P30 only. A c-series below firmware 3.10.16 speaks only UDP, which FTW's host lacks; update the firmware. The owner must set unit ID 255 (the UI default is 1) and DIP switch DSW1.3 ON.
    • Schrack: no power or energy register, so FTW cannot see what the car draws. CION Pro speaks OCPP and is not covered.

Safety

  • A driver that can command its device has control on, or says in its description why it cannot.
  • Vendor signs are converted at the driver boundary. An EVSE is a one-way load, so w is positive while charging.
  • Cached telemetry becomes stale instead of being re-emitted as fresh.
  • No credentials, serial numbers, private addresses or site data are included.

Control evidence

  • Hardware evidence: not yet. All three control paths stay experimental.
  • Control changes include default-mode, refused-write and harness test evidence.

New Lua harness tests (drivers/tests/lua_harness/test_{etrel,keba,schrack_ev}_control.lua, run by pytest) cover three default-mode calls on a fresh driver writing nothing, a refused stand-down returning false and retried at most once a minute, resume of an old order (6 A only, or nothing without room), the KEBA failsafe refresh during a pause and its back-off, the KEBA phase count with L2 and L3 unreadable, re-writing a stalled order, the Schrack void reset at most every 30 s (including a fault that clears while void still reads 1, and a refused reset), a 1p order on an idle three-phase installation giving P/(3·V), P/V only for a car drawing on exactly one phase or a configured one-phase installation, power-to-amps mapping with caps, rounding down, the 6 A minimum, write only on change, pause and resume, default mode settling, a refused write returning false, refusal settling, and re-asserting a lost order. KEBA also covers a non-P30 product code and the failsafe refresh. Schrack also covers a void authorisation and a car that is not plugged in.

make refused-write-report: etrel, keba and schrack_ev SETTLED 1 WRITES 0,0,0,0,0,0,0,0, since the probe never commands and default mode now leaves an unsteered charger alone. The control tests cover a refused stand-down after a command wrote (1,0,0,0, then one retry a minute). Wallbox has no default mode.

Checks

The four drivers leave drivers/tests/invented-number-baseline.json. Generated files (index.yaml, devices.yaml, support-status.json, SUPPORT_STATUS.md) will conflict with the other charger-control PRs and need regenerating at merge.

🤖 Generated with Claude Code

…says it cannot

Etrel INCH, KEBA KeContact P30 and Schrack i-CHARGE CION Home/Semipublic now
declare capabilities = { "ev" }, emit ev and take ev_set_current, ev_pause,
ev_resume and ev_start, so FTW can use them as loadpoints. Each register map
now comes from the vendor's own document; the old maps were in none.

Orders become a current per phase within Core's max and cap per phase and the
charger's own limit, rounded down, and 0 below 6 A. Default mode stands the
charger down once and settles. A refused write returns false.

Wallbox publishes no local Modbus interface for its chargers. The driver
declares read_only = true and points to FTW's OCPP central system.

All four are experimental: not yet confirmed on hardware.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@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:07:31.137746Z 7383808 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: 7383808588

ℹ️ 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 drivers/lua/etrel.lua
Comment on lines +233 to +235
for _, key in ipairs({ "max_amps_per_phase", "cap_amps_per_phase" }) do
local v = cmd[key]
if finite_positive(v) and v < ceiling then ceiling = v end

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 Honor zero-valued current caps

When Core supplies a positive power order with cap_amps_per_phase = 0, finite_positive(v) discards the cap instead of stopping charging. In the Lua harness, an 11,040 W order with a zero cap writes 16 A and enables charging. The same predicate appears in KEBA's and Schrack's amps_for implementations, so all three drivers can exceed Core's explicit current ceiling. Treat a finite zero cap as binding and route it through the existing below-minimum stop behavior.

AGENTS.md reference: AGENTS.md:L39-L42

Useful? React with 👍 / 👎.

Comment on lines +309 to +311
if written_auth and auth and auth ~= written_auth and
written_auth_ms and now - written_auth_ms >= ORDER_SETTLE_MS then
written_auth = nil

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 authorization intent when detecting stalled commands

If the charger clears register 100 to zero after accepting an authorization, this branch clears written_auth after 10 seconds. However, the stalled-command check below requires written_auth == 1 continuously for 30 seconds, so it resets its timer before it can report the dropped authorization. Reproducing a connected car with authorization held at zero leaves command_stalled false beyond 40 seconds. Track the requested authorization independently of the write-deduplication cache so invalidating that cache does not erase the intent needed for stall detection.

Useful? React with 👍 / 👎.

frahlg and others added 3 commits November 21, 2026 18:12
Brings in #241 and #243. The invented-number baseline keeps main's list
without etrel, keba, schrack_ev and wallbox; CHANGELOG.md keeps every entry.

Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ase only when certain

Core runs driver_default_mode at every start. The stand-down now acts only
after a command wrote in this run, so a charger FTW never steered keeps its
own state and a charge already running goes on. The heishamon 0.8.1 rule.
Once FTW wrote, the stand-down is unchanged and still settles.

An order is divided by one phase only when config says the installation is
one-phase and the car has not drawn on more than one, or when Core orders 1p
and the car draws on exactly one. Otherwise, idle or just started too, it is
three, so a three-phase car never gets a one-phase sum on each phase. Schrack
measures no phases and uses only config phases.

Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #242. The generated files regenerate unchanged.

Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
frahlg and others added 4 commits November 21, 2026 18:31
…-down, failsafe and phases

- Resume and start come without a budget. Write an order back only when it
  is under 30 s old; otherwise 6 A, and only when the last limit Core named
  allows it. With no such limit, write nothing and return false. KEBA and
  Schrack write the 6 A current before the enable or authorisation.
- Default mode returns true only when the stand-down is confirmed, or when
  FTW wrote nothing in this run. A refused stand-down returns false and is
  tried again at most once a minute, with no write in between.
- KEBA refreshes the failsafe timeout while FTW steers, paused or not, and
  after three refusals tries once a minute instead of stopping.
- KEBA counts phases only when all three phase currents answered in that
  poll, and tries a lost phase current again once a minute.
- A charger that holds a charge paused against the order for 30 s
  (Etrel status 6, KEBA state 5) gets the setpoint or enable again on the
  next order, at most every 30 s.
- Schrack clears a void authorisation once per void episode.
- Wallbox: say we found no documented local Modbus interface, and that its
  power and energy readings are unverified.

Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #247. The generated files regenerate unchanged.

Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er stand-down

- Schrack: a void authorisation is reset at most every 30 s while the
  charger calls it void, not once per episode. A fault made the reset void
  again at once, and void then stayed set after the fault cleared, so the
  driver never reset again. The reset counts only once its write lands.
- Resume uses the limit named with the last positive order. Core names
  cap_amps_per_phase only with a positive order, so a 0 W order no longer
  replaces it with the site maximum.
- Resume or start with no known limit, after a reload for example, writes
  nothing and returns true, logging once that the charger waits for Core's
  next order. Nothing was refused and nothing written above the budget.
- KEBA keeps refreshing the failsafe timeout while FTW holds the charger
  disabled after a stand-down. Whether the failsafe current overrides a
  disable once FTW stops is not verified; the header says so.

Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@frahlg
frahlg merged commit 51a9719 into main Nov 21, 2026
5 checks passed
@frahlg
frahlg deleted the charger-control-modbus-b branch November 21, 2026 17:44
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