Skip to content

Fix/battery auto size#3983

Merged
springfall2008 merged 3 commits into
mainfrom
fix/battery_auto_size
May 30, 2026
Merged

Fix/battery auto size#3983
springfall2008 merged 3 commits into
mainfrom
fix/battery_auto_size

Conversation

@springfall2008
Copy link
Copy Markdown
Owner

No description provided.

@springfall2008 springfall2008 marked this pull request as ready for review May 30, 2026 18:35
Copilot AI review requested due to automatic review settings May 30, 2026 18:35
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 targets reliability of Predbat’s automatic battery sizing by adjusting when battery size tracking runs during inverter initialization, tuning the find_battery_size heuristics, and adding a regression test to ensure an auto-detected soc_max persists across subsequent update cycles.

Changes:

  • Move battery_size_tracking() later in Inverter.__init__ (after charge/discharge rate limits are computed).
  • Modify find_battery_size() heuristics (power threshold, clipping range, minimum % change).
  • Add a regression test intended to ensure calculated soc_max persists across cycles when not configured.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
apps/predbat/inverter.py Reorders battery_size_tracking() call and adjusts battery size estimation heuristics.
apps/predbat/tests/test_find_battery_size.py Adds a regression test and wires it into the test runner.

Comment thread apps/predbat/inverter.py
Comment thread apps/predbat/inverter.py
Comment on lines +1219 to +1222
# --- Second cycle: new Inverter reads from updated args ---
# In real operation fetch_config_options resets battery_scaling_auto to whatever
# is in apps.yaml (False when not configured).
my_predbat.battery_scaling_auto = False
Comment on lines +1240 to +1242
if second_calls[0] > 0:
print("WARN: find_battery_size was called on second cycle (today already in history)")

Comment thread apps/predbat/inverter.py
Comment on lines 772 to 775
# Find continuous charging periods and calculate battery size from energy/SoC relationship
# Data is indexed backwards: minute 0 = now, minute N = N minutes ago
max_power_threshold = max_power * 0.9
max_power_threshold = 50

Comment thread apps/predbat/inverter.py
Comment on lines 836 to 841
for m in range(charge_end_minute, charge_start_minute + 1):
curr_soc = int(soc_percent.get(m, 0))
next_soc = int(soc_percent.get(m + 1, 0)) # m+1 is older
# Check if this is a stable minute (no upcoming transition) and within range
if curr_soc >= 20 and curr_soc <= 80 and curr_soc != next_soc:
if curr_soc >= 10 and curr_soc <= 90 and curr_soc != next_soc:
clipped_end_minute = m
Comment on lines +1219 to +1222
# --- Second cycle: new Inverter reads from updated args ---
# In real operation fetch_config_options resets battery_scaling_auto to whatever
# is in apps.yaml (False when not configured).
my_predbat.battery_scaling_auto = False
Comment on lines +1240 to +1242
if second_calls[0] > 0:
print("WARN: find_battery_size was called on second cycle (today already in history)")

@springfall2008 springfall2008 merged commit a7eafd5 into main May 30, 2026
1 check passed
@springfall2008 springfall2008 deleted the fix/battery_auto_size branch May 30, 2026 18:49
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