Skip to content

feat(zaptec_cloud): control the charger's current, pause and resume (0.2.0) - #240

Merged
frahlg merged 4 commits into
mainfrom
zaptec-cloud-control
Nov 21, 2026
Merged

frahlg merged 4 commits into
mainfrom
zaptec-cloud-control

Conversation

@frahlg

@frahlg frahlg commented Nov 21, 2026

Copy link
Copy Markdown
Member

What

FTW now controls a Zaptec Go, Go 2 or Pro through Zaptec Cloud. Before this, the driver read the charger but declared read_only = true. FTW accepted the charger and never steered it. One owner with a 20 A main fuse saw L1 overload whenever the car charged next to the battery.

  • Current goes to the charger's maxChargeCurrent (POST /api/chargers/{id}/update). Zaptec documents that setting for "an external party [that] must override the Zaptec load balancer". The installation's AvailableCurrent is not used, because Zaptec asks for at most one change per 15 minutes, which is too slow for a fuse guard. The installation's own circuit-breaker limit still applies.
  • Amps never exceed Core's per-phase budget. The driver assumes three phases unless Core and the charger both say one, so a single-phase car can only draw less than budgeted. Values round down. Below 6 A the driver writes 0 A. Nothing goes above max_amps_per_phase or 32 A.
  • Pause writes 0 A and sends command 506. Resume offers the last asked current (or 6 A) and always sends 507. Codes 520 and 528 ("would not change the state") count as done. Any other refusal returns false.
  • Stand-alone mode (observation 712) makes the charger ignore API current. The driver then refuses current orders and resumes, logs why, and shows the reason through reason_no_current_label.
  • Stand-down (driver_default_mode) writes 0 A and pauses once, then does nothing until a new order. A refused stand-down retries after five minutes.
  • Readings. Missing readings stay nil instead of 0. Phase currents and voltages are now reported. Every request carries User-Agent: FTW-zaptec_cloud/<version>.

The driver does not switch phases.

Evidence

  • Lua harness test drivers/tests/lua_harness/test_zaptec_cloud_control.lua: watts to amps, the caps, the 1p rule, rounding, deduplication, pause and resume, the codes, stand-alone mode, stand-down settling and retry, nil readings and the User-Agent.
  • Mutation checks. Each of these breaks the test: rounding up, dropping the cap, dropping the minimum, trusting a 1p order, no dedupe, no settle, no retry wait, current in stand-alone mode, no 528 handling, a false success on a failed write, and no User-Agent.
  • FTW's real Lua host. A local Core test loaded this driver into FTW's gopher-lua host against a fake Zaptec API (httptest). It confirmed the exact POST sequence and bodies, the bearer token, the User-Agent, code 528 on resume and a settling stand-down. That run found a real bug: a resume right after a pause read a stale "charging" poll and skipped 507. The fix is in the second commit, and the harness now covers the case.
  • make test-driver ID=zaptec_cloud and make check both pass (5 092 passed).

Hardware

Not yet confirmed on hardware. The control path stays verification_status = "experimental". A Zaptec Go owner on a 20 A fuse can test it on the beta channel.

Sources

The source is Zaptec's API documentation: https://api.zaptec.com/help/index.html and its OpenAPI file, now listed in upstream_docs. evcc's Zaptec charger was read to understand how the API behaves in the field, including the 520/528 codes and stand-alone mode. That evcc module is not MIT-licensed, so no code was taken from it.

Refs #239 (the rule change: a driver that can command its device ships with control on).

🤖 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-21T16:45:38.127937Z fe2fe8d 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: fe2fe8d9ba

ℹ️ 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/zaptec_cloud.lua Outdated
local mode = type(cmd.phase_mode) == "string" and cmd.phase_mode or ""
local one_phase = (mode == "1p") or (mode ~= "3p" and phases_cfg == 1)
local phases = 3
if one_phase and live_phase_count() <= 1 then phases = 1 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 Require positive phase evidence before using single-phase math

When a three-phase charger is idle or paused, all phase currents are zero, so live_phase_count() <= 1 incorrectly treats it as confirmed single-phase. With phase_mode = "1p", a 6,900 W order and a 32 A cap, the harness writes 30 A instead of 10 A. Since this driver never switches phases, a three-phase vehicle can then draw 20,700 W rather than the allocated 6,900 W. Missing current observations trigger the same behavior. Keep the conservative three-phase calculation unless single-phase operation is positively established; zero or missing current is not that evidence.

Useful? React with 👍 / 👎.

Comment on lines +566 to +569
local wrote = write_current(0)
send_command(CMD_PAUSE)
if wrote then
stood_down = 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 Require a successful pause before settling in stand-alone mode

When stand-alone mode is active, the driver explicitly recognizes that API current settings are ignored. Nevertheless, an accepted zero-current write sets stood_down even if the pause command fails. This leaves the charger running without an effective clamp and suppresses all subsequent stand-down attempts until another order arrives. The harness reproduces this with observation 712 set to 1 and a 503 response to command 506: no retry occurs after five minutes. In stand-alone mode, only a successful pause should establish that stand-down completed. This also violates the required safe default mode.

AGENTS.md reference: AGENTS.md:L34-L35

Useful? React with 👍 / 👎.

setup: [vendor_portal]
ders: [ev]
control: false
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 Keep control disabled until hardware acceptance is recorded

This enables catalog control and removes the driver's read-only guard while the manifest and changelog explicitly state that control has not been confirmed on hardware. The supplied mock-API tests do not satisfy the repository's requirement for HIL acceptance on every target host; SUPPORT_STATUS.md still records no hardware acceptance for either target. Keep the control path gated and the catalog read-only until the required hardware evidence is available.

AGENTS.md reference: AGENTS.md:L34-L35

Useful? React with 👍 / 👎.

frahlg and others added 4 commits November 21, 2026 17:53
…0.2.0)

The driver read a Zaptec Go but declared itself read-only, so FTW
accepted the charger and never steered it. An owner whose main fuse
was overloaded by the car had no way to see why.

Current goes to the charger's maxChargeCurrent, which Zaptec documents
for an external party that overrides its load balancer. The
installation's AvailableCurrent is not used: Zaptec asks for at most
one change per 15 minutes, too slow for a fuse guard.

Amps never exceed Core's per-phase budget: three phases are assumed
unless Core and the charger both say one, values round down and 0 A
goes out below 6 A. Pause is 0 A plus command 506, resume offers the
last order plus 507, and codes 520/528 count as done. Stand-alone mode
refuses orders and says why. The stand-down settles and retries after
five minutes when refused. Missing readings stay nil.

Written from Zaptec's API documentation; not yet confirmed on hardware.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
A resume right after a pause read the last poll, which still said
charging, and skipped command 507. The charger would have stayed
paused. Found by running the driver in FTW's Lua host. Resume now
always sends 507; 520 and 528 count as done.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
…safer phases

Review findings:
- A positive order on a paused charger now also sends 507, so a
  stand-down or Core restart cannot leave the car paused.
- 520 is ErrorCommunicatingWithDevice: the command never arrived, so it
  fails. 528 counts as done unless the driver paused the charger itself.
  A 200 carrying a non-zero Code is an error.
- A 1p order on an idle charger used one phase, so a three-phase car
  could draw 32 A on each phase. One phase now needs a one-phase
  installation, or Core asking for one with exactly one phase drawing.
- Resume offers 6 A, never above Core's last cap, instead of a stale
  order. A missing cap keeps Core's last one.
- A 401 signs in again once. A failed poll forgets phase currents.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
A pause Zaptec turned away (528, or no car plugged in) set the paused
flag. Once a car plugged in, a positive order resent 507, got 528 for
nothing to resume, and reported failure every 30 s until the car drew
current. The flag now follows only a pause the charger took.

A one-phase config no longer outvotes three phases measured. The
unused want_paused state is gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[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