Skip to content

ferroamp 2.2.0: cap at the EnergyHub limit, scale by measured delivery, report each ESO - #299

Merged
frahlg merged 1 commit into
mainfrom
ferroamp-eso-delivery
Dec 4, 2026
Merged

frahlg merged 1 commit into
mainfrom
ferroamp-eso-delivery

Conversation

@frahlg

@frahlg frahlg commented Dec 4, 2026

Copy link
Copy Markdown
Member

Problem

A help file from a site with three ESOs (two on 17.5 kWh Pylontech, one on a smaller PSM pack) showed two faults in the battery path.

  1. The EnergyHub refuses setpoints above its limit. It answers nak with Max allowed power level is 18000.0 W. and keeps its previous setpoint. With one ESO full, a 16 kW charge was scaled to 24 kW on the wire, refused, and the pack sat near 8.9 kW for half an hour. The log shows 972 such refusals in a week.
  2. N_eso / N_active is only a guess. With one ESO at its limit (faultcode 520), the other two delivered about half the on-wire setpoint, not two thirds. So 1.5x left the pack near 75% of target. While the small pack tapered but still counted as active, the pack gave about 82% at 1.0x. Core anchors its slew on measured battery power, so a steady shortfall became a fixed gap: in the telemetry, measured power sits exactly 1000 W below the command for the whole discharge.

Change

  • Cap. The driver learns the EnergyHub limit from that refusal, or takes it from config ehub_max_w, and never sends more. The lower of the two wins.
  • Measured scale. Once a command has had 3 s to act, the next one moves the scale halfway towards on-wire / delivered, and straight down when the pack over-delivers.
    • It starts from the N_eso / N_active estimate and stays within [1, min(2.0, estimate × 1.5)]. So a limit outside the ESO split can lift the setpoint at most 1.5x when every unit delivers.
    • It starts only on a shortfall above 5%, so a pack that delivers keeps today's exact 1.0x.
    • It forgets what it learned on a refused command (for example Other transaction in progress), a direction flip, idle or stale data.
  • Per-ESO diagnostics on multi-ESO sites: eso_<id>_w (site sign), eso_<id>_soc (fraction) and eso_<id>_faultcode, plus eso_dispatch_on_wire_w and ehub_max_w. The help file then shows which unit stands still and why.

The curtail and curtail_disable paths are unchanged.

Tests

  • New drivers/tests/lua_harness/test_ferroamp_delivery.lua replays the site:
    • one stuck ESO, the other two giving a quarter of the setpoint each;
    • recovery, a refused command, an unsettled command, a pack inside the dead band;
    • a direction flip, idle, the learned and configured cap, and the per-ESO metrics.
    • The first scaled command fails on 2.1.2 (6000 instead of 7000).
  • make test-driver ID=ferroamp: 167 passed, 16 skipped.
  • make check: 5572 passed, 927 skipped.
  • Core's own Ferroamp tests (go test ./internal/drivers/) pass with this file bundled, under Core's Lua 5.1. They caught a tonumber() call that Lua 5.5 accepts and Lua 5.1 does not, now fixed.

No hardware test yet. The site owner can confirm on the next beta.

Paired change

Core allows planner PV curtailment only for reviewed Ferroamp source hashes (go/internal/drivers/pv_generation_limit.go). The FTW pin PR that bundles this version adds its hash, since the pplim commands are unchanged.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 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-12-04T17:45:46.860204Z 6bf9c9a 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.

@frahlg
frahlg force-pushed the ferroamp-eso-delivery branch from 6bf9c9a to 2c5aa88 Compare December 4, 2026 17:43

@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: 6bf9c9a897

ℹ️ 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/ferroamp.lua
Comment on lines +867 to +868
last_delivered_w = delivered
last_delivered_ms = now

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 Timestamp delivery samples by telemetry arrival, not poll time

When ESO messages pause after a command, this block reuses the cached pre-command power but stamps it with the current poll time. The learning gate then treats it as a settled response to the new setpoint. Using the Lua harness, three ESOs reporting 3000 W total before a 6000 W discharge request, followed by a poll without MQTT messages at 3500 ms, causes the next request to publish 9000 W. A responsive battery can therefore exceed Core's requested power solely because telemetry was delayed. Preserve the measurement's actual arrival time and require a post-settle telemetry sample before learning.

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

Useful? React with 👍 / 👎.

Comment thread drivers/lua/ferroamp.lua
if not err then last_control_mode = "discharge" end
if not err then
last_control_mode = name
last_cmd_ms = now

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 Allow learning across repeated refreshes of the same setpoint

When battery commands arrive less than three seconds apart, every successful publish resets last_cmd_ms, so the settled-sample condition can never pass—even if the same setpoint has been applied continuously. In the Lua harness, refreshing a 4000 W discharge request once per second while receiving fresh 3000 W measurements leaves the command at 4000 W indefinitely. This preserves the steady shortfall that the new feedback loop is intended to correct. Keep the settling window across unchanged setpoint refreshes, or track an eligible command/sample pair separately.

Useful? React with 👍 / 👎.

Comment thread drivers/lua/ferroamp.lua
name = "Ferroamp EnergyHub",
manufacturer = "Ferroamp",
version = "2.1.2",
version = "2.2.0",

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 Mark the new control loop experimental until hardware verification

Version 2.2.0 introduces measured-delivery scaling, but DRIVER.verification_status remains production with verification dated 2026-04-18. That evidence predates this control algorithm, and the commit explicitly states that it has not been hardware-tested. AGENTS.md requires the control path to remain experimental until an owner confirms it on real hardware and records the report in tested_devices; retain control availability but update the verification status until that evidence exists.

AGENTS.md reference: AGENTS.md:L34-L38

Useful? React with 👍 / 👎.

The EnergyHub refuses any setpoint above its limit ("Max allowed power
level is 18000.0 W.") and keeps the old one. An up-scaled 24 kW charge
held one 3-ESO site at ~8.9 kW for half an hour. The driver now learns
the limit from that refusal, or takes it from config `ehub_max_w`, and
never sends more.

The same site showed that N_eso / N_active is a guess. With one ESO at
its limit (faultcode 520) the other two delivered about half the on-wire
setpoint, so 1.5x left the pack near 75% of target; with a tapering unit
still counted as active the pack gave ~82% at 1.0x. Core anchors its
slew on measured battery power, so a steady shortfall became a fixed gap
below target. The driver now measures delivery: once a command has had
3 s to act, the next one moves the scale halfway towards on-wire /
delivered, and straight down on over-delivery. It starts from the
N_eso / N_active estimate, stays within [1, min(2.0, estimate x 1.5)],
starts only on a shortfall above 5%, and forgets on a refused command,
a direction flip, idle or stale data.

Multi-ESO sites also get power, SoC and fault code per ESO
(eso_<id>_w, eso_<id>_soc, eso_<id>_faultcode), plus
eso_dispatch_on_wire_w and ehub_max_w.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@frahlg
frahlg force-pushed the ferroamp-eso-delivery branch from 2c5aa88 to 9f4caaa Compare December 4, 2026 17:46
@frahlg
frahlg merged commit 5eb7189 into main Dec 4, 2026
5 checks passed
@frahlg
frahlg deleted the ferroamp-eso-delivery branch December 4, 2026 17:48
frahlg added a commit to srcfl/ftw that referenced this pull request Dec 4, 2026
…2176)

Moves the pin to srcfl/device-drivers 5eb7189d, which brings:

- ferroamp 2.2.0 (srcfl/device-drivers#299): never sends the EnergyHub a
  setpoint above the limit the hub reports when it refuses one, or above
  ehub_max_w; scales by what the ESOs measurably deliver instead of
  guessing an even split; reports power, SoC and fault code per ESO.
- solaredge_pv 1.2.3 and solaredge_legacy 0.3.4
  (srcfl/device-drivers#298): read the serial only once the inverter
  answers, and ask again every five minutes after three misses, so a
  restart while the inverter sleeps no longer leaves the forecast
  identity pending until the next restart.

Planner PV curtailment accepts only reviewed Ferroamp source hashes.
2.2.0's pplim commands are byte for byte those of 2.1.2, so its hash
joins the list. Two Core tests run the new behaviour under Core's
Lua 5.1: the cap learned from the refusal, and the measured scale with
per-ESO metrics. Both fail on 2.1.2.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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