Repository navigation
fix(inverter): treat a 0W live rate limit as unset, so Predbat's own 0W write cannot latch the rate at 0 (#5219) - #5626
springfall2008 wants to merge 5 commits into
Conversation
…5219) A limit sensor that mirrors the charge/discharge rate Predbat writes (the Sunsynk template's max-charge-rate sensor) reads back Predbat's own 0W freeze-export write, which zeroed battery_rate_max_charge and made find_charge_curve divide by zero on every cycle, so no plan was ever made to restore the rate. Treat a non-positive inverter_limit_charge/_discharge reading as no reading, and skip the curve search when the rate is 0W. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
springfall2008
left a comment
There was a problem hiding this comment.
Automated comment from the triage bot.
Reviewed head commit 11c5c16 (fix(inverter): don't crash the plan when a live rate limit reads 0W (#5219)): 1 finding posted inline, 0 in the body. Overall the fix addresses the root cause the way the GH#5219 triage recommended (treat a <=0W live limit reading as "no reading" at refresh_config(), plus a <=0 guard in find_charge_curve()), and the PR body's claims check out against the code.
What I verified as correct:
- One computation site:
Inverter.__init__(inverter.py:436) callsrefresh_config(), andbattery_rate_max_charge/_discharge/_exportare assigned only at inverter.py:709-713, so the guard at lines 697-702 covers the only path that can zero them from a limit read. The fallback (battery_rate_max_raw) is already assigned at that point (lines 666-672). - The PR's claim that the second division site is covered:
adjust_battery_target_multidivides the per-inverter rate by the fleet sum assigned at execute.py:1433/1454, so a single-inverter install - the reporter's - sums to exactly the zeroed rate and the division is 0/0. The guard removes that. {}fromfind_charge_curve()is handled by its caller: execute.py:1370-1398 falls back tobattery_charge_power_curve_defaultor setscomputed_*_curvein non-auto mode; auto mode keeps retrying (the normal auto-mode signature per the debug journal).- The schema claim is right:
zero: Falseon all four limit keys (config.py:2710-2713) means a 0W value can only reachrefresh_config()from a live sensor, so the guard never overturns an apps.yaml value. None <= 0is not reachable:get_arg()with a float default guarantees a float (userinterface.py:326-335), which is also whatmin()on main received.- Both new tests fail without the fix by code reading (no code executed, per review rules):
test_zero_limit_sensor_falls_backfails becausemin(0, 5000)/MINUTE_WATTis 0, not 5000;test_find_charge_curve_zero_ratereaches the pre-fix division via the same fixture (create_test_history_data) the sibling curve tests use to reach it. TheMINUTE_WATTroundtrip in the assertions is consistent (const.py:127, 60000), both tests restoremy_predbat.argsanddummy_itemsinfinally, and both are registered in theirrun_*functions. - Docs need no change:
docs/apps-yaml.mddescribes the four limit keys but makes no zero-handling statement, and this change alters no setting, entity or default.
The disclosed behaviour choice (a genuine 0W limit reading is now planned at battery_rate_max with a per-cycle Warn:) is reasonable: pre-fix that state crashed every cycle, so nothing that planned correctly changes.
…nd inverter_limit_export too (#5219) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DECISION_NEEDEDPosted by Claude on behalf of @chalfontchubby. What should Predbat do with a live charge or discharge limit that reads 0 W? Main crashes on it in the curve search (auto mode / no curve yet), but plans no charging when the curve is fixed. This PR replaces 0 W with
|
Main (#6212) removed find_charge_curve() and its test file; the rate grid learner that replaced it already returns early when max_power is 0. The PR's guard in find_charge_curve and its zero-rate test go with them. The 0W live-limit fallback in update_status stays. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Posted by Claude on behalf of @chalfontchubby. Going ahead with option A. The DECISION_NEEDED question from 23 Oct has had no response, so this PR now does A: a live The options that were on the table:
Also changed by merging main (581e59e): main removed |
This is an automated draft PR generated from issue #5219 — a maintainer should review it before merging.
Fixes #5219
Summary
The Sunsynk template points
inverter_limit_charge/_dischargeat sensors that mirror the charge/discharge current Predbat writes. When a freeze export starts, Predbat writes 0W tocharge_rate. On the next cyclerefresh_config()reads that 0W back as the limit, sobattery_rate_max_chargebecomes 0. When this PR was opened,find_charge_curve()then divided by it and raisedZeroDivisionError, abortingupdate_pred()every cycle.Update 16 Nov 2026 (Claude, for @chalfontchubby), after merging main: main has since removed
find_charge_curve()(#6212); the rate grid learner that replaced it returns early when the maximum rate is 0, and theexecute.pydivision mentioned below is gone too. So main no longer crashes on a 0W reading. The latch remains: withbattery_rate_max_chargeat 0 the plan cannot charge in that direction, and the 0W Predbat wrote keeps reading back as the limit, so the rate is never restored. This PR now fixes only that, and thefind_charge_curve()guard and its test have gone with the function.The change:
Inverter.refresh_config()(inverter.py:692): aninverter_limit_charge/inverter_limit_dischargereading of 0W or less is treated as no reading. The rate falls back tobattery_rate_maxand aWarn:line is logged. The apps.yaml schema already rejects zero for these keys ("zero": False), so a 0W value only reaches this code from a live sensor. This fixes the cause, and it also covers the second division on the same value that triage found inexecute.py(inverter.battery_rate_max_charge / self.battery_rate_max_charge, now line 1213).inverter_limit_charge_dcandinverter_limit_exportdefault from the corrected values, so they inherit the fix.Testing
test_zero_limit_sensor_falls_back(tests/test_inverter.py) builds anInverterwhose limit sensors read 0W and checks that the charge, discharge and export maximums fall back tobattery_rate_max(5000W).inverter.pystashed,tools/triage_test.sh inverterfailed withbattery_rate_max_charge/_discharge/_export ... got 0W../run_pre_commitpasses: all hooks pass, and the quick suite it runs reports "All tests passed (4 slow tests skipped)".Notes
battery_rate_maxrather than at 0. That is a real behaviour change, not only a crash fix. The divide-by-zero was in the charge-curve search, which ran only in auto mode or before a curve had been worked out. So on main at the time, an inverter with a fixed or already-computed curve did not crash on a 0W reading: it planned no charging in that direction, which is right while the battery really refuses charge. With this PR that case plans full-rate charging the inverter can't deliver, and logs aWarn:every cycle. In return, the PR fixes the self-latching case, where Predbat's own 0W write keepsbattery_rate_max_chargeat 0 so the rate is never restored. (Correction added by Claude on behalf of @chalfontchubby, who asked for this PR; the earlier wording said nothing that worked before changes.) If you'd rather such a reading pause planning in that direction, that needs a wider change, because several sites divide by these rates.impact()ratesrefresh_configHIGH. That is because it sits on the per-cycleupdate_pred/fetch_inverter_datapath, not because of how far the change reaches. No signatures change, and behaviour changes only for a ≤ 0W limit reading (see Behaviour choice above for the cases where main did not crash).detect_changes()reports low risk.Warn:rather than adding once-only state.🤖 Generated with Claude Code