Skip to content

Fix charge/discharge curve spam warnings and calculate_yesterday soc_kw_h0 fallback#3937

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-battery-curve-warnings
Draft

Fix charge/discharge curve spam warnings and calculate_yesterday soc_kw_h0 fallback#3937
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-battery-curve-warnings

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 17, 2026

Two regressions from v8.39.4 that fire every cycle: the battery curve fitter warns continuously when no full-rate charge-to-full event exists in history (normal in cost-optimised operation), and calculate_yesterday hard-exits when soc_kw_h0 HA history is unavailable, leaving savings_yesterday_* permanently unavailable and savings_total_* cumulatives frozen.

Charge/discharge curve warnings (inverter.py, execute.py)

The fitter requires a "charge to 100% at max rate" event in the history window. Under cost-optimised Predbat operation the battery rarely if ever hits 100%, so no qualifying event is found — and computed_charge_curve was never set True on failure, causing find_charge_curve to be called (and warn) every single cycle.

  • inverter.py: Downgrade "no full rate cycle found" from WarnInfo. This is expected behaviour, not a configuration error.
  • execute.py: After a failed curve search when battery_charge_power_curve_auto is off, set computed_charge_curve = True to stop retrying every cycle. Same for discharge.
# Before: computed_charge_curve stayed False → retried every cycle
# After:
elif not self.battery_charge_power_curve_auto:
    self.computed_charge_curve = True  # stop retrying; warn fired once at startup

calculate_yesterday soc fallback (output.py)

calculate_yesterday was re-fetching predbat.soc_kw_h0 from HA and doing an early return on failure — blocking the entire savings pipeline. fetch.py already fetches and parses this into self.soc_kwh_history every cycle; there's no need to re-query HA.

  • Use self.soc_kwh_history (in-memory, already populated by fetch.py) as the primary SoC data source.
  • If soc_kwh_history is empty, fall back to a fresh HA history fetch.
  • If both fail, log at Info and substitute soc_yesterday (from savings_total_soc) as a constant rather than bailing out — savings computation continues with a degraded but non-zero SoC estimate.

Tests

Added _test_soc_kw_h0_fallback to test_calculate_yesterday.py with two sub-cases:

  • A: both soc_kwh_history empty and HA history absent → function runs to completion (no early exit).
  • B: soc_kwh_history populated, HA history absent → function uses in-memory data and sets savings_last_updated.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.octopus.energy
    • Triggering command: /home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --quick (dns block)
  • gitlab.com
    • Triggering command: /usr/lib/git-core/git-remote-https /usr/lib/git-core/git-remote-https origin REDACTED (dns block)
  • https://api.github.com/repos/springfall2008/batpred/contents/apps/predbat
    • Triggering command: /home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --quick (http block)
    • Triggering command: /home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --test find_charge_curve --test calculate_yesterday (http block)
    • Triggering command: /home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --test calculate_yesterday (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI and others added 2 commits May 17, 2026 15:47
Copilot AI changed the title [WIP] Fix battery charge/discharge curve fitter warnings in v8.39.4 Fix charge/discharge curve spam warnings and calculate_yesterday soc_kw_h0 fallback May 17, 2026
Copilot AI requested a review from springfall2008 May 17, 2026 15:51
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.

v8.39.4: charge/discharge curve fitter and "Calculate yesterday: No soc_kw_h0 data" warnings firing every cycle; savings_total_* cumulatives stuck

2 participants