Repository navigation
feat(control): wire MPC pv_limit_w into per-driver curtail dispatch - #236
Conversation
The MPC's annotateCurtailment has been computing PVLimitW for slots where exporting more PV would lose money (negative-spot hours, no positive feed-in tariff) for a while now — but the value only surfaced in /api/mpc/diagnose. The dispatch loop ignored it, so on 2026-05-02 with spot at −5 öre the site happily exported 6 kW of unconstrained PV at the operator's expense. This wires the missing leg: - mpc.SlotDirective gains PVLimitW (echoed via the main.go adapter into the control package's mirror struct). - New control.ComputePVCurtail returns one CurtailTarget per affected driver. The site-wide cap is allocated proportionally to each driver's live |PV|, so a 1.5 kW limit splits 0.9 kW / 0.6 kW across a 6 kW + 4 kW PV pair. - New State.SupportsPVCurtail (per-driver opt-in) gates dispatch. Drivers without the flag are silently skipped — an EV charger wouldn't know what to do with a `curtail` payload anyway. The lua side (sungrow / ferroamp / deye / huawei / solis) has shipped curtail handlers for a while; this just turns on the Go-side dispatcher per driver. - New State.LastCurtailedDrivers tracks who got non-zero curtail last tick. ComputePVCurtail diffs against the new set and emits exactly one LimitW=0 release target when a previously-curtailed driver drops out — main.go translates that to `curtail_disable` so the cap is released on slot rollover instead of silently staying applied. - main.go's dispatch tick now runs ComputeDispatch (batteries) and ComputePVCurtail (PV) sequentially, sending each result through reg.Send with the matching action. - New config.Driver.SupportsPVCurtail (`yaml: supports_pv_curtail`) carries the opt-in. Hot-reloadable via the same path as InverterGroups + DriverLimits. Regression suite covers: stale plan → no targets, PVLimitW=0 → no targets, proportional split across two PV drivers, non-supporting driver skipped, non-generating driver skipped, release-on-slot- rollover, and deterministic ordering.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 631c2f0b7c
ℹ️ 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".
| if len(next) == 0 { | ||
| state.LastCurtailedDrivers = nil | ||
| } else { |
There was a problem hiding this comment.
Retry curtail_disable until command is acknowledged
ComputePVCurtail clears LastCurtailedDrivers before main.go attempts to send the generated curtail_disable command, so a transient reg.Send failure leaves the inverter capped with no further release attempts. This occurs when a driver was curtailed in the previous tick, drops out of next, and the disable send fails once (e.g., brief MQTT/Modbus outage): subsequent ticks return nil because state was already cleared, so the one-shot release is lost permanently until manual intervention.
Useful? React with 👍 / 👎.
Move the pin to srcfl/device-drivers@28c771fd (#279). zaptec_cloud 0.3.0 uses host.set_command_timeout_s and driver_release from this PR. The pin also carries the easee_cloud fixes merged since e7b94b11 (#183, #227, #194, #236, #200), whose Core side (#2050, #2062) is already on master. Tell the stopped instance's default apart from a replacement's startup default in TestOtherStopsKeepTheSafeDefault (review finding). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…val (#2079) * fix(drivers): give slow cloud drivers time, hand devices back on removal A Zaptec Cloud command that took longer than 5 s failed, and the safe default then paused the charger at 0 A. A driver can now ask for up to 30 s per call with host.set_command_timeout_s; the control tick still waits only its short deadline and the call finishes in the driver's queue. Removing or disabling a driver calls its optional driver_release instead of driver_default_mode, so a charger goes back to the owner's own current rather than staying at FTW's 0 A. Restarts, shutdown and stale readings keep the safe default. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(drivers): bundle zaptec_cloud 0.3.0 and easee_cloud 1.5.0 Move the pin to srcfl/device-drivers@28c771fd (#279). zaptec_cloud 0.3.0 uses host.set_command_timeout_s and driver_release from this PR. The pin also carries the easee_cloud fixes merged since e7b94b11 (#183, #227, #194, #236, #200), whose Core side (#2050, #2062) is already on master. Tell the stopped instance's default apart from a replacement's startup default in TestOtherStopsKeepTheSafeDefault (review finding). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Wires the missing leg between
mpc.annotateCurtailment(which has been computing PV curtail recommendations for a while) and the actual driver-side action. Operators with negative-spot pricing now seecurtailcommands fire when the plan says exporting unconstrained PV would lose money.mpc.SlotDirectivegainsPVLimitW— surfaced through the main.go adapter into the control package's mirror struct.control.ComputePVCurtailallocates the site-wide cap proportionally to each PV-supporting driver's live|PV|. Returns oneCurtailTargetper affected driver;LimitW=0means "release any prior curtail" (curtail_disable).State.SupportsPVCurtail(per-driver opt-in) gates dispatch. Lua side has shipped curtail handlers in sungrow / ferroamp / deye / huawei / solis for a while — this just turns on the Go-side dispatcher per driver. Operators setsupports_pv_curtail: truein YAML.State.LastCurtailedDriversdiffs across ticks so a previously-curtailed driver gets exactly onecurtail_disablewhen it drops out of the active set (slot rollover, plan no longer asking for curtail). No silent caps left applied.main.godispatch tick now runsComputePVCurtailafterComputeDispatchand sends each result throughreg.Send.Why
Real incident on 2026-05-02: spot at −5 öre/kWh, the operator's site exporting ~6 kW of PV, MPC plan reported
pv_limit_w: 1338for the active slot — but no Go code read it. The lua drivers have curtail handlers; the wiring just wasn't there.Test plan
go test ./...— 782 passed (+7 new inpv_curtail_test.go)supports_pv_curtail: trueonsungrowandferroampdrivers, switch to a planner mode during a negative-spot hour, confirm/api/mpc/diagnoseshowspv_limit_w > 0AND the inverters' export limit registers reflect the cap (sungrow holding 13073, ferroamppplimMQTT echo).curtail_disableand PV inverter resumes uncapped output.