Skip to content

fix(inverter): avoid double-counting inverter losses when estimating battery capacity from DC power (#5831) - #6524

Open
iangregory wants to merge 4 commits into
springfall2008:mainfrom
iangregory:fix/5831-battery-size-dc-power
Open

iangregory wants to merge 4 commits into
springfall2008:mainfrom
iangregory:fix/5831-battery-size-dc-power

Conversation

@iangregory

@iangregory iangregory commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

find_battery_size() currently applies both battery charging losses and inverter conversion losses to historical battery power measurements:

loss_factor = self.base.battery_loss * self.base.inverter_loss

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_loss again 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_dc apps.yaml setting.

  • Defaults to false, preserving existing behaviour.
  • When true, only battery charging losses are applied during capacity estimation.
  • Applies to whichever sensor find_battery_size() selects: battery_size_power or battery_power.
  • Does not change the inverter efficiency assumptions used by the prediction engine.
  • Supports inverter-specific configuration through the existing indexed argument mechanism, subject to configuration validation.

Real-world evidence

On a Sigenergy SigenStor installation, sustained overnight charging produced the following measurements:

AC input DC battery power Conversion loss
2,556 W 2,448 W 4.23%
2,454 W 2,348 W 4.32%
2,145 W 2,047 W 4.57%

The proposed change removes the duplicated inverter loss without making assumptions about actual physical battery degradation.

Refs #5831.

iangregory and others added 3 commits December 4, 2026 17:07
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.
@github-actions github-actions Bot added the BOT_REVIEW Trigger an autotriage label Dec 4, 2026
@iangregory iangregory changed the title Fix/5831 battery size dc power fix(inverter): avoid double-counting inverter losses when estimating battery capacity from DC power (#5831) Dec 4, 2026

@springfall2008 springfall2008 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread apps/predbat/inverter.py Resolved
@springfall2008 springfall2008 removed the BOT_REVIEW Trigger an autotriage label Dec 4, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants