Skip to content

Fix incorrect SoC when battery_scaling_auto is enabled#3974

Merged
springfall2008 merged 1 commit into
springfall2008:mainfrom
nickgee31:fix-battery-degradation-soc
May 30, 2026
Merged

Fix incorrect SoC when battery_scaling_auto is enabled#3974
springfall2008 merged 1 commit into
springfall2008:mainfrom
nickgee31:fix-battery-degradation-soc

Conversation

@nickgee31
Copy link
Copy Markdown
Contributor

Fixed battery degradation auto-scaling so it respects the configured battery_scaling baseline.

Previously, battery_scaling_auto could update soc_max without keeping the effective runtime battery scale consistent. This could make Predbat’s displayed SoC diverge from the real inverter SoC, especially on systems using battery_scaling for DoD correction, such as 0.8.

The change now treats the configured per-inverter battery_scaling value as the upper bound, and only allows auto degradation to reduce from that baseline. For example, battery_scaling: 0.9 can auto-adjust within 0.72-0.9, while battery_scaling: 0.8 can adjust within 0.64-0.8. This preserves manual DoD/SOH correction while still allowing measured battery degradation to be applied consistently to both soc_max and shown SoC.

#3940 - fixes this issue.

Preserve manual DoD/usable config when battery_scaling_auto is enabled by introducing battery_scaling_config and clamping auto-scaling to [config*0.8, config]. Update Inverter to set battery_scaling from the computed value and to default battery_scaling to 1.0 when no nominal capacity is configured. Add/adjust unit tests: helper _clamped_auto_scaling, assert battery_scaling is updated in existing auto-scaling tests, add test_battery_scaling_auto_preserves_configured_scaling to ensure measured degradation below configured DoD is applied, and wire the new test into the test runner.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a battery degradation auto-scaling inconsistency that could cause Predbat’s displayed SoC to drift from the inverter’s real SoC when battery_scaling_auto is enabled alongside a configured battery_scaling baseline (e.g., DoD correction like 0.8). It does this by treating the configured battery_scaling as an upper bound and only allowing auto-scaling to reduce from that baseline.

Changes:

  • Introduces a per-inverter baseline (battery_scaling_config) captured from the configured battery_scaling value.
  • Updates battery_size_tracking() to clamp auto-scaling to [0.8 * configured_scaling, configured_scaling] and to update self.battery_scaling alongside soc_max.
  • Extends the battery sizing tests to validate both soc_max and battery_scaling, including a new case ensuring configured scaling is preserved as an upper bound.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
apps/predbat/inverter.py Stores configured scaling baseline and clamps battery_scaling_auto relative to it while updating runtime battery_scaling consistently.
apps/predbat/tests/test_find_battery_size.py Updates expected scaling calculations and adds coverage ensuring auto-scaling respects configured battery_scaling as the cap.

@springfall2008 springfall2008 merged commit 909eff3 into springfall2008:main May 30, 2026
1 check passed
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.

3 participants