Skip to content

feat(control): DC-link protective PV curtail — pre-empt Ferroamp fault - #310

Merged
frahlg merged 1 commit into
masterfrom
feat/dc-link-protective-curtail
May 25, 2026
Merged

frahlg merged 1 commit into
masterfrom
feat/dc-link-protective-curtail

Conversation

@frahlg

@frahlg frahlg commented May 25, 2026

Copy link
Copy Markdown
Member

Live incident — 2026-05-25 14:53:20

Ferroamp EnergyHub tripped to fault state 0x8030 (DC-link safety). Reconstructed trigger:

14:53:11   load=  +456 W   PV=-6200   grid=-5750   (steady-state export)
14:53:17   load= +1131 W   PV=-6200   grid=-5070   ← load spike #1 (+660 W)
14:53:23   load= +2740 W   PV=-6200   grid=-3460   ← load spike #2 (+1600 W)
14:53:20   ehub_state → 0x8030 (FAULT)
14:53:32   PV collapses 6.2 → 3.4 kW (inverter trips)

A 2.7 kW load step under 6 kW PV + 85 % SoC dragged grid from -5.5 kW export to -3 kW; the inverter's DC-link couldn't ramp PV down in time. Operator framing: "prefer to lose a bit of PV revenue over having the inverter trip and stop charging entirely."

What this PR does

Adds an opt-in PV-curtail trigger that engages on the configurable risk window:

SoC ≥ DCLinkProtectionSoCThreshold   (default 0.80)
   AND
PV > load + 2 × DCLinkProtectionMarginW   (default 1000 W)

When it engages the PV limit becomes load + margin, so a load step inside margin lands without re-curtail recompute.

Composes safely with existing curtail sources

Existing source Behaviour
Operator manual hold Tighter cap wins; protection never relaxes
Planner directive Min(...) layering; tighter planner cap stays
Driver-scoped hold Bypassed (explicit operator override)
No PV-curtail-capable driver No-op

Config

site:
  dc_link_protection_enabled: true       # off by default
  dc_link_protection_soc_threshold: 0.80
  dc_link_protection_margin_w: 1000

All three hot-reload via the configreload watcher.

Tests

  • TestProtectivePVCurtailEngagesAtHighSoCWithSurplus — 85 % SoC + 5.5 kW surplus → curtail to load + margin
  • TestProtectivePVCurtailSkipsBelowSoCThreshold — 50 % SoC, same surplus, no curtail
  • TestProtectivePVCurtailNeverRelaxesManualHold — manual cap tighter than protection wins
  • Full suite green

Activation

After deploy, set site.dc_link_protection_enabled: true via the API (hot-reload). The fix only engages when the conditions hit — on a cloudy or low-SoC day it stays inert.

🤖 Generated with Claude Code

Live incident 2026-05-25 14:53:20: Ferroamp EnergyHub tripped to
fault state 0x8030 (DC-link safety). Reconstructed trigger from
history: a 2.7 kW load step under 6 kW PV generation with battery
at 85 % SoC dragged grid from -5.5 kW export to -3 kW, fast enough
that the inverter's internal DC-link voltage couldn't ramp PV down
in time. Operator framing: \"prefer to lose a bit of PV revenue
over having the inverter trip and stop charging entirely.\"

This adds an opt-in PV-curtail trigger that engages on the
operator-tunable risk window: SoC at or above DCLinkProtectionSoC­
Threshold (default 80 %) AND PV exceeds load by more than 2× the
margin (default 1000 W). When it engages the PV limit becomes
`load + margin`, so a load step inside `margin` lands without
re-curtail. Disabled by default; enable per-site via
`site.dc_link_protection_enabled: true`.

Composes safely with existing curtail sources:
  - Operator manual hold: never relaxed (tightest cap wins).
  - Planner directive: protection layered on top via min(...);
    a tighter planner cap stays in force.
  - Driver-scoped hold: bypassed (operator is explicitly forcing
    one driver, don't auto-engage elsewhere).
  - Sites with no PV-curtail-capable driver: no-op.

Config:
  site.dc_link_protection_enabled            (default false)
  site.dc_link_protection_soc_threshold      (default 0.80)
  site.dc_link_protection_margin_w           (default 1000)

All three hot-reload via the configreload watcher.

Tests:
  - TestProtectivePVCurtailEngagesAtHighSoCWithSurplus — happy
    path: 85 % SoC + 5.5 kW surplus → curtail to load + margin
  - TestProtectivePVCurtailSkipsBelowSoCThreshold — 50 % SoC,
    same surplus, no curtail
  - TestProtectivePVCurtailNeverRelaxesManualHold — manual cap
    tighter than protection wins

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@frahlg
frahlg merged commit fe30c23 into master May 25, 2026
1 check passed
@frahlg
frahlg deleted the feat/dc-link-protective-curtail branch May 25, 2026 13:51

@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: 94a4aad3a3

ℹ️ 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 on lines +1904 to +1908
for _, r := range store.ReadingsByType(telemetry.DerBattery) {
batW += r.SmoothedW
}
for _, r := range store.ReadingsByType(telemetry.DerPV) {
pvW += r.SmoothedW

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 Ignore stale offline DER readings in load estimator

siteLoadW computes load from every battery/PV sample returned by ReadingsByType, but it never checks DriverHealth.IsOnline(). Since the telemetry store retains last-known readings for offline drivers, stale kW-scale values can skew load and cause protectiveCurtailLimitW to either miss a real DC-link risk or clamp PV when it should not. This protection is live-state logic, so it should filter to online drivers (as other dispatch helpers do) before summing battery/PV power.

Useful? React with 👍 / 👎.

Comment on lines +1881 to +1883
loadW := siteLoadW(state, store)
if pvAbs < loadW+2*margin {
// Surplus already inside the safe margin — no need to engage.

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 Treat missing site-meter telemetry as no-decision

When the site meter reading is missing, siteLoadW returns 0, but protectiveCurtailLimitW still evaluates the surplus gate against that zero (pvAbs < loadW+2*margin). In practice, any high-PV period with SoC above threshold will trigger a curtail limit (margin watts) during meter outages, even though load is unknown. That is a behavior regression for this new feature because it turns missing telemetry into an active curtail decision instead of skipping protection until meter data is available.

Useful? React with 👍 / 👎.

frahlg added a commit that referenced this pull request Oct 17, 2026
* ci: stop new direct reads of cached telemetry outside the telemetry package

A reading stays in telemetry.Store after its driver goes stale, offline
or faulted. Every direct reader of RawW, SmoothedW, ReadingsByType or
ReadingsByDriver must check driver health itself, and review caught the
missing check in #36, #85, #310, #647, #664 and #740.

The check counts those reads per file outside go/internal/telemetry and
fails when a pull request adds one. Existing reads (147 today) may only
go down. The error names the health-gated accessors to use instead.
On the merged commits of #36, #85, #310 and #647 it fails.

* ci: count telemetry reads across platforms and validate exceptions

Signed-off-by: Fredrik Ahlgren <[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