Fix/battery auto size#3983
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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 inInverter.__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_maxpersists 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 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 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 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)") | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.