Repository navigation
fix(inverter): avoid double-counting inverter losses when estimating battery capacity from DC power (#5831) - #6524
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
## Summary Adds an opt-in `battery_size_power_is_dc` setting so capacity estimation does not apply inverter conversion loss a second time when the selected battery-power sensor is already on the DC side. - Preserves the existing AC-side behaviour by default. - Supports one scalar value for all inverters or one value per inverter. - Applies to `battery_size_power`, or `battery_power` when no dedicated capacity sensor is configured. - Adds diagnostic logging for the selected sensor, measurement side, and loss factor. - Documents the seven-day history transition after changing the setting. ## Validation - Focused battery-size and configuration tests passed. - All pre-commit checks passed. - The quick suite passed across 4 workers (8 slow tests skipped). Refs springfall2008#5831.
springfall2008
left a comment
There was a problem hiding this comment.
Automated comment from the triage bot.
Verdict: 🟡 Amber - Recommend addressing the feedback, then approval
The loss-factor change itself is correct and its new test pins the AC/DC split, but the option is not wired into the one integration Predbat configures with a DC-side sensor by itself (Sunsynk), and its name points at a different sensor than the common battery_power-only case.
Reviewed head commit 3e10600 (1 inline finding, 1 finding below). Checked find_battery_size() and its caller battery_size_tracking(), the APPS_SCHEMA / get_arg handling of a single_value_ok boolean list, Sunsynk's battery_power_bms() and its automatic_config() bindings, and web.py's BatteryDegradation chart (it reads degradation_percent from the soc_max_calculated sensor, so the new docs claim holds). The new test's ratio checks (dc_true vs ac_false / 0.96, and invariance to inverter_loss) would fail with the change reverted, so it is a real regression test rather than a restatement; I did not execute the suite.
apps/predbat/sunsynk.py:1940 - Sunsynk binds a DC-side sensor automatically but never sets battery_size_power_is_dc
Sunsynk sets battery_size_power to sensor.predbat_sunsynk_<serial>_battery_power_bms, and battery_power_bms() is -bmsCurrent * bmsVolt - current and voltage at the battery terminals, i.e. DC-side, with the inverter conversion already upstream of the measurement. That is exactly the case this option is for, and the fallback branch (no BMS link) binds battery_power, which is also the inverter's battery-side current x voltage. So on every Sunsynk install the estimate keeps applying inverter_loss (~4% low at defaults) after this PR, and the user has no battery_size_power line in their apps.yaml to notice they should set a flag named after it. Suggest binding it where battery_size_power is bound (set_arg_auto("battery_size_power_is_dc", [True for ...], overwrite=False)), and, if it stays manual, saying so in docs/components.md:1838, which currently documents the BMS binding as if nothing else were needed.
This is the only integration in the tree that supplies a capacity-estimation power sensor itself; the other reporters on #5831 (Victron, Fox, Sigenergy) do own their battery_power, so the manual option is fine for them.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Problem
find_battery_size()currently applies both battery charging losses and inverter conversion losses to historical battery power measurements:This is appropriate when the source sensor measures AC-side charging power. However, for DC-side measurements, inverter conversion losses have already occurred before the measurement point.
Consequently, applying
inverter_lossagain underestimates battery capacity and overstates apparent degradation. Changing inverter efficiency settings for planning purposes also changes the calculated capacity without any physical change to the battery.Issue #5831 contains examples from Victron, Sunsynk and FoxESS installations. This has now also been observed on a Sigenergy SigenStor installation.
Proposed change
Introduce an optional
battery_size_power_is_dcapps.yaml setting.false, preserving existing behaviour.true, only battery charging losses are applied during capacity estimation.find_battery_size()selects:battery_size_powerorbattery_power.Real-world evidence
On a Sigenergy SigenStor installation, sustained overnight charging produced the following measurements:
The proposed change removes the duplicated inverter loss without making assumptions about actual physical battery degradation.
Refs #5831.