Multi-inverter balancing cannot act during a force export, and the target split worsens imbalance
Describe the bug
Two related problems in the multi-inverter code that let a fleet drift badly out of balance and then make it worse. Both found while investigating #4840 on a 3-inverter GivEnergy fleet (2x Gen1 hybrid + 1x AC3, soc_max 12.4 / 9.52 / 8.19 kWh).
1. balance_inverters() cannot act during a force export
can_power_house in apps/predbat/execute.py asks whether the other inverters could supply total_battery_power without this one:
can_power_house.append((total_discharge_rates - discharge_rates[id] - 200) >= total_battery_power)
During a force export every inverter is discharging at its max rate, so total_battery_power is approximately the sum of all the max rates and removing any single inverter always fails the test. The discharge-balance branch (which is gated on can_power_house[this_inverter]) is therefore structurally unreachable while exporting.
Measured on the reporter's log, force export 17:05-17:17:
discharge_rates = [2730, 2730, 3150] total 8610
battery_powers = [2886, 2886, 3172] total 8944
can_power_house[0] = 8610 - 2730 - 200 = 5680 >= 8944 -> False
can_power_house[2] = 8610 - 3150 - 200 = 5260 >= 8944 -> False
The result is that an export drains the lowest inverter hardest:
| inverter | 17:05 | 17:17 | delta |
|---|---|---|---|
| inv0 (12.4kWh, 2.6kW) | 5.71kWh 46% | 5.46kWh 44% | -0.25 |
| inv1 (9.52kWh, 2.6kW, full) | 9.52kWh 100% | 8.95kWh 94% | -0.57 |
| inv2 (8.19kWh, 3.0kW, lowest) | 3.69kWh 45% | 3.03kWh 37% | -0.66 |
The natural balancing action during a force export is the opposite of "who can power the house": it is to zero the discharge rate on the low inverters and let the full one carry the export, since the target is a fixed total export power rather than a house load. can_power_house is the wrong predicate for that state.
2. adjust_battery_target_multi() splits by charge rate, not by headroom
add_kwh = target_kwh - self.soc_kw
add_this = add_kwh * (inverter.battery_rate_max_charge / self.battery_rate_max_charge)
The fleet-level delta is apportioned by each inverter's share of the total charge rate, with no reference to how full or empty that inverter already is. For the case above (fleet 18.92kWh -> target 15.36kWh, delta -3.56kWh) this asks the 45% inverter to give up as much as the 100% one, so a fleet that is already out of balance is pushed further out by design.
This one is masked on GivEnergy (discharge target register not supported, export target not written, and the reserve is left at 4%) but it is live on any inverter that honours the target.
3. Minor: the partner ring only considers one other inverter
other_inverter = (this_inverter + 1) % num_inverters
Fine for two inverters; for three or more it picks an arbitrary partner rather than the most complementary one. In the trace above, inverter 2 (45%) is paired with inverter 0 (46%) and never considered against inverter 1 (100%).
Expected behaviour
Balancing should be able to act during a force export, and the per-inverter target split should take account of each inverter's headroom so that balancing improves rather than degrades.
Predbat version
Found on 8.53.5, code paths unchanged on current main (v8.53.5-194-g112b7cf4).
Environment details
3x GivEnergy (2x Gen1 hybrid + AC3) via GivTCP REST. Reported originally in #4840.
Automated first-pass triage — a maintainer will review before any action is taken.
Classification: bug · Priority: priority_medium
Verified against current main (v8.53.5-194-g112b7cf4), so both issues are still live — not something already fixed since 8.53.5.
1. can_power_house gate (apps/predbat/execute.py:1344) — confirmed structurally unreachable during a full force export. can_power_house[id] requires total_discharge_rates - discharge_rates[id] - 200 >= total_battery_power. During a force export total_battery_power tracks the sum of all discharge rates, so removing any single inverter's contribution from the LHS while the RHS still includes it can only pass if discharge_rates[id] <= -200, which never happens for a discharging inverter. This isn't a 3-inverter-specific edge case — the same holds for 2 inverters too, so it's broken for any multi-inverter export scenario, not just this reporter's 3-way fleet. The reporter's worked numbers (can_power_house[0] = 5680 >= 8944 → False, can_power_house[2] = 5260 >= 8944 → False) check out against the code as written.
2. adjust_battery_target_multi split (apps/predbat/execute.py:807-808) — confirmed. add_this = add_kwh * (inverter.battery_rate_max_charge / self.battery_rate_max_charge) apportions the fleet-wide SoC delta purely by each inverter's share of total charge/discharge rate (self.battery_rate_max_charge is the fleet-summed rate, set in execute.py:1011). Nothing in that formula references inverter.soc_kw / inverter.soc_max, so two inverters with the same rate get the same target delta regardless of current fill level — an already out-of-balance fleet is pushed further apart by design, exactly as described. Correctly noted that GivEnergy masks this because it doesn't honour the discharge target register; it would be live on any inverter that does.
3. Partner selection (apps/predbat/execute.py:1355) — confirmed, other_inverter = (this_inverter + 1) % num_inverters is a fixed ring, not a best-match search, so for 3+ inverters the comparison partner is arbitrary rather than the most complementary one.
Test coverage gap: tests/test_balance_inverters.py only ever configures num_inverters = 2 (line 160-161), and I didn't find a scenario there that drives all inverters near max discharge simultaneously (the force-export condition). Ran it via tools/triage_test.sh balance_inverters — passes cleanly on main, which is expected and doesn't contradict this report: none of the existing cases exercise the 3-inverter or full-force-export path where these bugs actually bite.
This looks like the underlying mechanism behind #4840 ("Random Predbat exports, often in the peak rate") — same reporter, same fleet, already labelled bug/priority_medium. Worth deciding whether to track both under one fix or keep separate; I haven't merged them since #4840 is a symptom report and this is the root-cause analysis.
No missing information — version, environment, and a full worked trace are already in the report.
I don't think this is the cause of 4840 - I think that exports because the settings make export more financially attractive - no penalty for battery cycling and a discount applied to stored energy.
1.
balance_inverters()cannot act during a force exportThe result is that an export drains the lowest inverter hardest:
inverter 17:05 17:17 delta inv0 (12.4kWh, 2.6kW) 5.71kWh 46% 5.46kWh 44% -0.25 inv1 (9.52kWh, 2.6kW, full) 9.52kWh 100% 8.95kWh 94% -0.57 inv2 (8.19kWh, 3.0kW, lowest) 3.69kWh 45% 3.03kWh 37% -0.66 The natural balancing action during a force export is the opposite of "who can power the house": it is to zero the discharge rate on the low inverters and let the full one carry the export, since the target is a fixed total export power rather than a house load.
can_power_houseis the wrong predicate for that state.
I think I am missing something here. I don't have balance inverters turned on for the reasons I mentioned in #4840, but if I did, would question whether balance inverters should be doing anything during a scheduled export.
A Predbat scheduled export should (I suggest) always be at full rate.
If balance inverters starts turning off discharge rate and curtailing the export to keep the inverter SoC's in balance then you're not going to get full rate export occurring. This would be especially true if you have dissimilar battery capacities on the inverters.
My expectation is that a full rate export is just that, full rate, and then only afterwards during Demand status would Predbat start trying to recover the inverters back to balance again
You have flat export rates, so the speed of export isn't required to hit a specific export slot. There is potential to export from the highest Soc battery preferentially to bring them back towards balance.
If full export power is needed to hit a specific slot, then driving all of them hard and worrying later might make sense, but since the same logic applies on grid charging potentially, then balancing would seem to imply cross charging might be the only way (other than selective self use) on a low solar day. I you just import/export and the rates mismatch then pure cycling would drive the batteries further and further into imbalance unless the import/export were balance aware.
I suspect there is a lot that predbat could do to improve multi inverter support, and a Claude account working on it would make some progress.
Fair point, if Predbat were executing to a target SoC value sufficient to preserve SoC for later on, then it wouldn't necessarily be doing a full rate export and it would make sense to export from the largest battery capacity first.
At the moment with plenty of battery capacity and plenty of solar each day, refilling the batteries next day isn't an issue. But once the heat pump is on, things will be different.
I suspect there is a lot that predbat could do to improve multi inverter support,
Yes agreed. I've always felt that multi-inverter support was a bit of an edge case for Trefor, and more could be done.
For amusement - I asked Claude to do a "state of the nation" review of multi-inverter state.
Thoughts? Not expecting currently to do much in this space - I'm spending enough on tokens to fix the other issues at present but it would be interesting to see how it maps to lived experience.
Assigning to you since you were I think looking at this stuff?
Assigning to you since you were I think looking at this stuff?
I am indeed. Up to my ears on getting Claude to test different fleet export/import models to improve the accuracy of multi-fleet charging & export.
Will take a look at this one as well
Revisiting this against current main and the tracking issue (#4856), as the code has moved on since it was raised.
-
Balancing can't act during a forced export (F6). Still open. balance_inverters now runs from the executor and can_power_house is gone. During a forced export balancing deliberately doesn't hold an inverter, so it can't cut the export the plan costed. The executor splits the planned fleet export by how much each inverter has to shed (allocate_fleet_export_rates(), F11), so they finish together. What is not done is choosing per-inverter export to pull an unbalanced fleet back towards level, for example letting the fullest inverter carry more of it. That would be a future iteration, and it needs care with full-rate exports, as discussed above.
-
adjust_battery_target_multi() splitting by charge rate, not headroom (F1). Complete, as a scope decision. #5906 caps each inverter at what it has room for and passes the overflow to the others. A forced export is split by export rate. The split is deliberately still a rate share. A capacity-proportional split would level the SoC, which brings back the stall in #1484 and ignores that inverters don't share load evenly. That is the whole of what will be delivered for this point.
-
Partner ring (F7). Fixed by the balancer port. The (this_inverter + 1) % num_inverters ring is gone and the guards ask whether any other inverter qualifies.
Separately, I'm working on the planner side in #4856: derived fleet power curves, so the plan stops counting on charge or export the inverters can't deliver. It doesn't change any of the three points above.