Skip to content

experiment(control): default slew → 3000 W/cycle + slew_enabled opt-out - #298

Merged
frahlg merged 2 commits into
masterfrom
experiment/slew-rate-tuning
May 25, 2026
Merged

frahlg merged 2 commits into
masterfrom
experiment/slew-rate-tuning

Conversation

@frahlg

@frahlg frahlg commented May 25, 2026

Copy link
Copy Markdown
Member

What

Two changes, both back-compat preserved:

  1. Default `slew_rate_w` 500 → 3000 W/cycle. At the 2 s default control interval that's a 1500 W/s ceiling — above Sungrow's internal ramp (~1000 W/s spec) and well above Ferroamp's ~200 ms EMS response, so the external slew rarely fires under normal operation but still bounds catastrophic post-windup snaps.

  2. New `site.slew_enabled` knob (default true). Operators can set it to `false` to disable the external slew entirely and trust the inverter's internal ramp control. Pointer typing preserves "unset → default" semantics on upgrade. Hot-reloadable via the configreload watcher.

Why

Operator question (2026-05-25): "does the external slew actually do anything useful when the inverter has its own ramp control?"

The honest answer: less than the 500 W/cycle default implied. Both production inverter families have internal ramp control loops; the external slew was originally a damper on reactive-PI swing under noisy meter sampling. It also interacts badly with PI integrator state — the 2026-05-25 morning recovery took ~3 min of slew-bounded ramping after the integral finally unwound, because each cycle could only contribute 500 W of correction even when PI was finally pointing the right way (paired fix in #297 unwinds the integral; this PR is the speed-up half).

This is structured as an experiment: bump the default to a less aggressive value AND provide an off-switch for live A/B comparison without redeploy.

Test plan

  • `go test ./...` green
  • `TestSlewDisabledPassesLargeStepThrough` — opt-out path lets a 3 kW step pass in one cycle
  • `TestSlewEnabledClampsLargeStep` — default path still caps step at slew_rate_w
  • `TestSlewDefaults` / `TestSlewExplicitDisablePreserved` — defaults + pointer semantics
  • Deploy on homelab-rpi; verify live step responses are faster but inverter doesn't protest
  • Try `slew_enabled: false` for a few hours and compare convergence latency

🤖 Generated with Claude Code

… opt-out knob

Operator question (2026-05-25): "does the external slew rate actually
do anything useful when the inverter has its own ramp control?"

It does, but less than the existing 500 W/cycle default implies. Both
production inverter families ramp internally:
  - Sungrow: ~1000 W/s spec, Modbus power setpoint
  - Ferroamp: ~200 ms response to charge/discharge MQTT command

The external slew was originally a damper on reactive-PI swing under
noisy meter sampling. It also interacts badly with PI integrator
state — the 2026-05-25 morning recovery took ~3 min of slew-bounded
ramping after the integral finally unwound, because each cycle could
only contribute 500 W of correction even when PI was finally pointing
the right way.

Two changes, both back-compat preserved:

  1. Default slew_rate_w 500 → 3000 W/cycle. At the 2 s default
     control interval that's a 1500 W/s ceiling — above Sungrow's
     internal ramp, so the external slew rarely fires under normal
     operation but still bounds catastrophic post-windup snaps.

  2. New site.slew_enabled config knob (default true). Operators
     can set it to false to disable the external slew entirely and
     trust the inverter's internal ramp control. Pointer typing
     preserves "unset → default" semantics on upgrade.

Hot-reloadable via the configreload watcher; no restart needed to
toggle between modes for live A/B comparison.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@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: 715d029674

ℹ️ 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 +132 to +134
if newEnabled != oldEnabled {
slog.Info("config reload: slew_enabled", "old", oldEnabled, "new", newEnabled)
w.ctrl.SlewEnabled = newEnabled

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 Apply slew toggle on config reload even without diff

This update only writes w.ctrl.SlewEnabled when newEnabled != oldEnabled, but handlePostConfig updates *Cfg immediately after saving (go/internal/api/api.go lines 1001-1003) before the file watcher fires, so oldCfg and newCfg can already match and this assignment is skipped. In that common /api/config flow, changing site.slew_enabled is persisted but not applied to the live controller until restart or another config change, which makes the new runtime opt-out unreliable.

Useful? React with 👍 / 👎.

@frahlg
frahlg merged commit 9117d73 into master May 25, 2026
1 check passed
@frahlg
frahlg deleted the experiment/slew-rate-tuning branch May 25, 2026 08:54
frahlg added a commit that referenced this pull request Dec 2, 2026
The setup guide wrote control_interval_s 5, slew_rate_w 500 and
min_dispatch_interval_s 5. It copied the defaults when it was added in
April (#66); the defaults moved to 2 s / 3000 W / 2 s in May (#293,
#298) and the guide did not follow. Settings → Control showed the same
old values as its fallbacks.

The guide now sends 2 / 3000 / 2, and Settings → Control shows them.
It cannot leave the fields out: with a house password the box stores
the guide's settings as sent and fills no defaults, so a missing
slew_rate_w would turn the ramp limit off.

wizardOrDefaultSeed still knows a guide seed only by 5 / 500 / 5. An
older Core saves 2 / 3000 / 2 for an untuned home, and that save must
import after a rollback.

Tests: a guard that the guide and the Control tab match applyDefaults,
the seed check for the old and new values, and an older Core's save
with default timings importing over live Settings.

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