Repository navigation
feat(control): inverter-affinity charge routing prefers DC-local battery - #144
Conversation
Closes #143. Each physical inverter unit (hybrid PV + battery or separate PV + battery pair on the same string) can keep incoming PV energy DC-coupled to the same-unit battery, avoiding the DC→AC→AC→DC round-trip that cross-inverter charging incurs — roughly 3-4 pp of round-trip efficiency on a typical two-inverter site over a sunny season. The dispatcher now accepts an optional `inverter_group: <tag>` per driver. At ComputeDispatch time we sum PV telemetry per group, then feed that map into distributeProportional. When the fleet is charging (desiredTotal > 0), the function routes up to `min(desiredTotal, ΣPV_g)` preferentially to batteries whose group also has live PV output, and spreads any overflow capacity-proportionally across the whole fleet — the existing behaviour. Discharge and the no-PV case skip the locality math and collapse to the capacity-proportional split, so no-group sites see no behaviour change. Within a group with multiple batteries, the local share is split by that group's capacity ratio (same rule as fleet-wide). With only one group represented across the fleet, the formula is mathematically identical to today's proportional split — so a single-inverter installation gets zero behaviour change from tagging. Wiring: - config.Driver gains optional `inverter_group` YAML key. - control.State.InverterGroups holds the driver→group map; wired from config at startup and swapped under ctrlMu on config-reload so the control loop's 5 s tick can't race a live edit. - main.go's inverterGroupsFrom helper builds the map from cfg.Drivers. Tests (go/internal/control/control_test.go): - TestInverterAffinity_PrefersLocalBatteryForLocalSurplus - TestInverterAffinity_FallsBackToProportionalOnOverflow - TestInverterAffinity_UngroupedBehavesAsBefore (backcompat) - TestInverterAffinity_DischargeStillProportional (discharge path) - TestInverterAffinity_EndToEndViaComputeDispatch (wiring sanity) Docs: - docs/configuration.md: new "Inverter affinity" subsection with concrete example tags for a ferroamp + sungrow two-inverter site. - go/internal/control/CLAUDE.md: "What NOT to do" updated with the groupPV guardrail. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 13270cdaca
ℹ️ 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".
| var totalPV float64 | ||
| for _, w := range groupPV { | ||
| totalPV += w | ||
| } |
There was a problem hiding this comment.
Exclude PV-only groups from locality denominator
This sums totalPV across every tagged PV group, including groups that have no online battery capacity in bats; later, those groups are skipped by the capG > 0 check, so their portion of localCap is never reassigned. In scenarios like a PV-only tagged group (or a group's battery going offline), the dispatched targets add up to less than desiredTotal, which leaves persistent grid error and under-charging until PI winds up. totalPV should be computed only from groups that have dispatchable battery capacity.
Useful? React with 👍 / 👎.
Closes #143.
Summary
Why
Cross-inverter charging (PV on A → AC bus → inverter B → battery B) eats ~3-4 pp round-trip vs DC-local routing on the same unit. Over a sunny season at ~2 MWh routed through batteries that's 60-80 kWh silently lost. No config change needed for single-inverter sites — untagged drivers keep current behaviour exactly.
Worked example
```
drivers:
inverter_group: ferroamp
battery_capacity_wh: 15200
inverter_group: sungrow
battery_capacity_wh: 9600
```
Fleet charging at 3 kW. Ferroamp PV = 4 kW, Sungrow PV = 0 kW:
Fleet charging at 6 kW. Same PV:
Backcompat
Untagged sites → `InverterGroups` map is empty → `groupPV` map is empty → `distributeProportional` falls through to the legacy capacity-proportional split. Five new tests + 51 existing control tests pass. `make test` + `make e2e` green.
Test plan
Out of scope
🤖 Generated with Claude Code