Skip to content

feat(control): inverter-affinity routing — prefer local battery for each inverter's PV surplus #143

Closed

Description

@frahlg

Motivation

Right now `distributeProportional` (and the priority/weighted variants) split the fleet's desired charge/discharge by capacity ratio across all online batteries. That's agnostic to the physical plumbing: each inverter usually has its own PV strings and its own battery DC-coupled to it. Cross-charging (PV on inverter A → AC bus → inverter B → battery B) incurs DC→AC→AC→DC conversion losses (~3–4 pp round-trip) compared to keeping the energy DC-local (PV on A → battery A via A's DC coupling).

On a sunny summer season with ~2 MWh of PV routed through batteries, that's ~60–80 kWh of avoidable loss — not life-or-death but measurable.

Concrete case

Operator running Ferroamp + Sungrow, each with its own PV strings and own battery:

PV_ferroamp (4 kW) ──┐                  ┌── Battery_ferroamp
                      ├── Ferroamp inv ──┤
                      │                  └── (DC-coupled)
                      │
AC bus ───────────────┤
                      │
                      ├── Sungrow inv ───┬── Battery_sungrow
                      │                  │
PV_sungrow (4 kW) ────┘                  └── (DC-coupled)

When total surplus is 3 kW, today's dispatch might send 1.8 kW to Ferroamp battery + 1.2 kW to Sungrow battery (60/40 capacity split). If the 3 kW surplus is all physically on Sungrow's DC bus, the 1.8 kW we send to Ferroamp incurs avoidable conversion losses.

Proposed design

1. Config tag

Add an optional `inverter_group` string to each driver in `config.yaml`:

```yaml
drivers:

  • name: ferroamp
    lua: drivers/ferroamp.lua
    inverter_group: ferroamp
    battery_capacity_wh: 15200
  • name: sungrow
    lua: drivers/sungrow.lua
    inverter_group: sungrow
    battery_capacity_wh: 9600
    ```

Drivers that emit both PV and battery telemetry share the same `inverter_group`; an external PV driver on a separate inverter gets its own group.

2. Dispatch changes

In `go/internal/control/dispatch.go`, extend `distributeProportional`:

  • Compute per-group `local_surplus_i = Σ|PV_i_w| within group`.
  • For a charging correction (`totalCorrection > 0`):
    • First pass: allocate up to `local_surplus_i` to the group's battery.
    • Second pass: distribute the remaining correction proportionally across all batteries (fallback to today's behaviour when local surplus is exhausted or ungrouped).
  • For discharge: today's behaviour is fine (discharge flow goes to AC bus and is consumed wherever the load is; no DC locality benefit).

Per-battery max charge clamps, SoC guards, and fuse guard stay untouched — they run on top of the new allocation.

3. Operator-visible default

Make inverter-affinity the default when `inverter_group` tags are present. Operators with untagged drivers get today's proportional behaviour unchanged — no migration needed.

4. Tests

  • `TestInverterAffinity_PrefersLocalBatteryForLocalSurplus`: one group with surplus, one without, battery allocation should match.
  • `TestInverterAffinity_FallsBackToProportionalWhenLocalSurplusExceedsBatteryCap`: surplus bigger than the local battery's headroom (near full SoC) — overflow goes to other batteries.
  • `TestInverterAffinity_UntaggedDriversBehaveAsBefore`: no groups defined → identical results to current `distributeProportional`.
  • `TestInverterAffinity_DischargeStillProportional`: a discharge correction is split by capacity regardless of groups.

Scope

  • Battery dispatch only (discharging stays proportional).
  • No planner changes — DP keeps optimising against the aggregate fleet. Per-group awareness in the DP is a much larger piece (state-space grows per group) and not worth it until we see real-world measurements of the loss this fix claims to recover.

Related

  • Operator report 2026-04-20: observed only Sungrow charging while Ferroamp idle; root cause was the plan saying `bat_w=0` for the slot, not a distribution bug. But the architectural point about DC-locality stands for when the plan does want to charge.
  • Depends on nothing — can ship independently.

Activity

  1. added a commit that references this issue on Apr 20, 2026
    13270cd
  2. added a commit that references this issue on Apr 20, 2026
    cc3f1f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions