From 976c81c5337f27bd71e56259da589bdb1d0e38d4 Mon Sep 17 00:00:00 2001 From: thewhale21 Date: Mon, 19 Oct 2026 08:55:50 +0000 Subject: [PATCH] feat(octopus): switch to trust Intelligent dispatches in the PV10 scenario The PV10 scenario assumes every Intelligent dispatch minute more than 30 minutes ahead is withdrawn and prices it at the tariff maximum. That rule has no setting of its own, so pv_metric10_weight carries both the solar hedge and the dispatch-withdrawal risk (GH#5540). A high PV10 weight stops Predbat cycling the battery in a cheap dispatch window that it cycles when the same rate comes from the tariff or manual rates. Add switch.predbat_octopus_intelligent_pv10_dispatch_gone (expert mode, default On, so behaviour is unchanged). Off, neither engine assumes a dispatch is gone in PV10. io_adjusted itself is untouched, as the rate replication, the IOG charge skew and the dynamic dispatch check still need it. The kernel sees the switch through io_flag, so no kernel rebuild or ABI change is needed. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UK7LNGFfiNxzmmDLaJ7DkU --- apps/predbat/config.py | 7 ++++ apps/predbat/fetch.py | 1 + apps/predbat/predbat.py | 1 + apps/predbat/prediction.py | 6 +++- apps/predbat/prediction_kernel.py | 4 ++- apps/predbat/tests/test_kernel_parity.py | 22 ++++++++++++ apps/predbat/tests/test_pv90.py | 44 ++++++++++++++++++++++++ docs/car-charging.md | 2 ++ docs/customisation.md | 1 + tools/debug-journal.md | 2 +- 10 files changed, 87 insertions(+), 3 deletions(-) diff --git a/apps/predbat/config.py b/apps/predbat/config.py index 0e1021cf3f..4f816c4777 100644 --- a/apps/predbat/config.py +++ b/apps/predbat/config.py @@ -936,6 +936,13 @@ "default": True, "enable": "expert_mode", }, + { + "name": "octopus_intelligent_pv10_dispatch_gone", + "friendly_name": "Assume Intelligent dispatches can vanish in the PV10 scenario", + "type": "switch", + "default": True, + "enable": "expert_mode", + }, { "name": "car_charging_plan_smart", "friendly_name": "Car Charging Plan Smart", diff --git a/apps/predbat/fetch.py b/apps/predbat/fetch.py index 85fb598ad0..440a70ed54 100644 --- a/apps/predbat/fetch.py +++ b/apps/predbat/fetch.py @@ -3980,6 +3980,7 @@ def fetch_config_options(self): self.octopus_intelligent_consider_full = self.get_arg("octopus_intelligent_consider_full") self.octopus_intelligent_trust_slots = self.get_arg("octopus_intelligent_trust_slots") self.octopus_intelligent_dynamic = self.get_arg("octopus_intelligent_dynamic") + self.octopus_intelligent_pv10_dispatch_gone = self.get_arg("octopus_intelligent_pv10_dispatch_gone") self.car_energy_reported_load = self.get_arg("car_energy_reported_load") self.get_car_charging_planned() self.dynamic_load_car_check_config() diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index a95032d91b..335d92da91 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -560,6 +560,7 @@ def reset(self): self.octopus_intelligent_consider_full = False self.octopus_intelligent_trust_slots = True self.octopus_intelligent_dynamic = True + self.octopus_intelligent_pv10_dispatch_gone = True self.notify_devices = ["notify"] self.octopus_url_cache = {} self.dispatch_timeline_last = {} diff --git a/apps/predbat/prediction.py b/apps/predbat/prediction.py index d5310117b9..652c4700f6 100644 --- a/apps/predbat/prediction.py +++ b/apps/predbat/prediction.py @@ -195,6 +195,8 @@ def __init__( self.rate_import = base.rate_import self.rate_export = base.rate_export self.io_adjusted = base.io_adjusted + # Off trusts Intelligent dispatch rates in PV10 too, without touching io_adjusted itself (GH#5540) + self.octopus_intelligent_pv10_dispatch_gone = getattr(base, "octopus_intelligent_pv10_dispatch_gone", True) # The tariff's own highest import rate, without event rewards - the floor for a dispatch that goes away self.rate_max = base.rate_import_tariff_max self.pv_forecast_minute_step = pv_forecast_minute_step @@ -555,7 +557,9 @@ def run_prediction(self, charge_limit, charge_window, export_window, export_limi rate_import = self.rate_import rate_export = self.rate_export - io_adjusted = self.io_adjusted + # With the switch Off no minute is assumed gone in PV10. io_adjusted itself is kept for the rate replication, + # the IOG charge skew and the dynamic dispatch check, so only this local view is emptied. + io_adjusted = self.io_adjusted if getattr(self, "octopus_intelligent_pv10_dispatch_gone", True) else {} # Data structures creating during the prediction predict_soc = {} diff --git a/apps/predbat/prediction_kernel.py b/apps/predbat/prediction_kernel.py index dfb9a80bef..a1e1f213a6 100644 --- a/apps/predbat/prediction_kernel.py +++ b/apps/predbat/prediction_kernel.py @@ -651,6 +651,7 @@ def build_static_context_arrays(pred, n_steps, minutes_now, num_cars): # temperature instead of repeated for every step. On the benchmark that is 17,856 calls per plan # for a handful of answers. temp_cap_memo = {} + dispatch_gone_enable = getattr(pred, "octopus_intelligent_pv10_dispatch_gone", True) for k in range(n_steps): minute = k * PREDICT_STEP minute_absolute = minute + minutes_now @@ -659,7 +660,8 @@ def build_static_context_arrays(pred, n_steps, minutes_now, num_cars): alert_keep.append(pred.all_active_keep.get(minute_absolute, 0)) # Negative means no ceiling at this step - 0 is a real request to empty the battery alert_keep_max.append(pred.all_active_keep_max.get(minute_absolute, -1)) - io_flag.append(1 if pred.io_adjusted.get(minute_absolute, 0) else 0) + # Mirrors prediction.py: with octopus_intelligent_pv10_dispatch_gone Off no minute is assumed gone in PV10 + io_flag.append(1 if (dispatch_gone_enable and pred.io_adjusted.get(minute_absolute, 0)) else 0) pv.append(pred.pv_forecast_minute_step[minute]) pv10.append(pred.pv_forecast_minute10_step[minute]) pv90.append(pred.pv_forecast_minute90_step[minute]) diff --git a/apps/predbat/tests/test_kernel_parity.py b/apps/predbat/tests/test_kernel_parity.py index bea9d9fb6d..6df626ea3f 100644 --- a/apps/predbat/tests/test_kernel_parity.py +++ b/apps/predbat/tests/test_kernel_parity.py @@ -776,6 +776,28 @@ def run_edge_case_tests(my_predbat): pv90_step=pv90_step, load90_step=load90_step, ) + # switch.predbat_octopus_intelligent_pv10_dispatch_gone Off: both engines must trust the dispatch in PV10 (GH#5540) + my_predbat.rate_import_tariff_max = 50.0 + my_predbat.octopus_intelligent_pv10_dispatch_gone = False + try: + failed |= dual_run( + "{}_scenario_{}_dispatch_gone_off".format(case_name, PV_SCENARIO_PV10), + my_predbat, + pv_step, + pv10_step, + load_step, + load10_step, + charge_limit[:], + [dict(window) for window in charge_window], + [], + [], + PV_SCENARIO_PV10, + my_predbat.forecast_minutes, + pv90_step=pv90_step, + load90_step=load90_step, + ) + finally: + my_predbat.octopus_intelligent_pv10_dispatch_gone = True my_predbat.io_adjusted = {} return failed diff --git a/apps/predbat/tests/test_pv90.py b/apps/predbat/tests/test_pv90.py index d582c2d994..732948ea69 100644 --- a/apps/predbat/tests/test_pv90.py +++ b/apps/predbat/tests/test_pv90.py @@ -741,6 +741,49 @@ def test_pv10_dispatch_gone_never_cheaper_than_the_slot(my_predbat): return failed +def test_pv10_dispatch_gone_switch(my_predbat): + """switch.predbat_octopus_intelligent_pv10_dispatch_gone Off trusts Intelligent dispatch rates in PV10 (GH#5540). + + With the switch On (the default) an io_adjusted minute beyond the first 30 is priced at the tariff max in + PV10, so on identical series PV10 costs more than nominal. With it Off PV10 must cost the same as nominal, + and io_adjusted itself must be left alone because the rate replication, the IOG charge skew and the dynamic + dispatch check still read it. + """ + from prediction import Prediction + + failed = False + saved = my_predbat.octopus_intelligent_pv10_dispatch_gone + reset_inverter(my_predbat) + reset_rates(my_predbat, 10.0, 5.0) + n = my_predbat.forecast_minutes + my_predbat.minutes_now + flat_pv = {minute: 0.0 for minute in range(0, n, 5)} + flat_load = {minute: 0.01 for minute in range(0, n, 5)} + + try: + for switch in (True, False): + my_predbat.octopus_intelligent_pv10_dispatch_gone = switch + pred = Prediction(my_predbat, flat_pv, flat_pv, flat_load, flat_load, flat_pv, flat_load, soc_kw=0, soc_max=0) + _force_python_engine(pred) + io_adjusted = {minute: 1 for minute in range(0, n)} + pred.io_adjusted = io_adjusted + pred.rate_max = 50.0 + nominal = pred.run_prediction([], [], [], [], PV_SCENARIO_NOMINAL, my_predbat.forecast_minutes) + pv10 = pred.run_prediction([], [], [], [], PV_SCENARIO_PV10, my_predbat.forecast_minutes) + if switch and pv10[0] - nominal[0] < 1e-3: + print("ERROR: with the switch On PV10 cost {} should be above nominal {} - the dispatch is not assumed gone".format(pv10[0], nominal[0])) + failed = True + if not switch and abs(pv10[0] - nominal[0]) > 1e-6: + print("ERROR: with the switch Off PV10 cost {} should equal nominal {} - the dispatch was still assumed gone".format(pv10[0], nominal[0])) + failed = True + if len(pred.io_adjusted) != len(io_adjusted): + print("ERROR: the switch must not change io_adjusted itself") + failed = True + finally: + my_predbat.octopus_intelligent_pv10_dispatch_gone = saved + reset_rates(my_predbat, 10.0, 5.0) + return failed + + def test_pv90_no_charge_derate(my_predbat): """pv90 must charge at the full rate; the pv10-only charge_scaling10 de-rate must not apply to it. @@ -1471,6 +1514,7 @@ def run_pv90_tests(my_predbat): failed |= test_pv90_scenario_selects_arrays(my_predbat) failed |= test_pv90_no_io_penalty_on_identical_series(my_predbat) failed |= test_pv10_dispatch_gone_never_cheaper_than_the_slot(my_predbat) + failed |= test_pv10_dispatch_gone_switch(my_predbat) failed |= test_pv90_no_charge_derate(my_predbat) metric_state = save_metric_state(my_predbat) diff --git a/docs/car-charging.md b/docs/car-charging.md index 2a37bfb9d0..6730702b62 100644 --- a/docs/car-charging.md +++ b/docs/car-charging.md @@ -706,6 +706,8 @@ In that scenario, any part of a dispatch more than 30 minutes ahead that is chea The rest of the house then pays the peak rate for those minutes, and the battery is not held for the car, although the car's own charging is still costed at the dispatch rate so the two scenarios stay comparable. The effect is that with a low battery Predbat may top it up in the first half hour of a dispatch, which is treated as certain, so that it can carry the house through to the fixed off-peak window if the rest of the dispatch disappears. This applies whether the dispatches come from the Octopus Energy integration or from Predbat's own Octopus connection. +Because it shares that weight with the solar forecast, a high **input_number.predbat_pv_metric10_weight** can stop Predbat cycling the battery in a cheap dispatch window that it would cycle if the same rate came from your tariff. +Turn **switch.predbat_octopus_intelligent_pv10_dispatch_gone** (*expert mode*, On by default) Off to trust dispatch rates in the PV10% scenario as well, so dispatch windows plan like any other cheap rate while the PV10% solar weighting stays in place. - Let the Octopus app control when your car charges. diff --git a/docs/customisation.md b/docs/customisation.md index 41dfb9ed8e..e4a2c569f6 100644 --- a/docs/customisation.md +++ b/docs/customisation.md @@ -311,6 +311,7 @@ These are described in detail in [Car Charging](car-charging.md) and are listed - **switch.predbat_octopus_intelligent_ignore_unplugged** (_expert mode_) - used with Octopus Intelligent to prevent Predbat from assuming the car will be charging when the car is unplugged - **switch.predbat_octopus_intelligent_dynamic** (_expert mode_) - On by default: cancels Octopus Intelligent slots, and their cheap rate, while the car is in a dispatch but not charging (from **car_charging_now**, or the house load when the car is inside the CT clamp), see [Checking Intelligent dispatches against the car](car-charging.md#checking-intelligent-dispatches-against-the-car) - **switch.predbat_octopus_intelligent_trust_slots** (_expert mode_) - when Off, Octopus Intelligent slots are assumed not to happen until the car is seen charging in one, see [Car charging](car-charging.md) +- **switch.predbat_octopus_intelligent_pv10_dispatch_gone** (_expert mode_) - On by default: in the pessimistic PV10% scenario, Intelligent dispatches more than 30 minutes ahead are assumed to go away. Turn Off to trust dispatch rates while keeping the PV10% solar weighting, see [Car charging](car-charging.md) - **binary_sensor.predbat_car_charging_slot** - set to On by Predbat when the car should be charged (Predbat-led charging) - **select.predbat_car_charging_plan_time** - the time you want the car to be charged by - **switch.predbat_car_charging_plan_smart** - allows Predbat to allocate car charging slots to the cheapest times rather than all low-rate slots in time order (default On) diff --git a/tools/debug-journal.md b/tools/debug-journal.md index 9c3ae60a1a..a68ec7ea7b 100644 --- a/tools/debug-journal.md +++ b/tools/debug-journal.md @@ -167,7 +167,7 @@ Grep for the named symbol rather than trusting a line number. | IOG: battery flat inside an evening dispatch that runs on into 23:30, plan waits until 01:00 to charge | Two causes, both **fixed on main in PR #5304 (merged 2026-09-30, v9.3.3)** - keep the mechanisms for pre-#5304 logs. (1) Dispatches applied by `rate_add_io_slots()` (Predbat's own Octopus component) never set `io_adjusted`, so the PV10 "slot goes away" re-pricing never fired; it now flags the minutes it lowers, matching BottlecapDave's `adjust_intelligent_rates()`, which flags only rates it lowered - never the fixed off-peak or over-cap time; and from PR #5392 (v9.3.6) "lowered" means by more than `IO_RATE_TOLERANCE` (a penny), so sub-penny dp2-rounding differences no longer mark the fixed off-peak window as adjusted or re-price it at the dispatch price. (2) With `car_charging_from_battery: false` the PV10 case still held the battery for the car in a vanished dispatch, so an early top-up had no value; PV10 now keeps the car at the dispatch rate but off the battery and releases the hold (kernel parity 15). Pre-fix check: `io_adjusted: {}` in the dump alongside live `octopus_slots`. The debug replay reuses the dump's `rate_import`/`io_adjusted` and never re-runs `rate_add_io_slots()`, even with `--redo`, so it cannot show a rate-overlay change - re-apply the overlay from `rate_import_no_io` in a wrapper. Also: with only the first (trusted) half hour left before 23:30 the benefit is under `metric_min_improvement_plan` (2p), so a dump taken late in the dispatch rightly shows no change. | | IOG: the house battery charges at the back of (or not at all during) a long smart-charge dispatch whose rate is equally cheap throughout | Within-block placement is **metric-neutral** — the cost model has no term preferring the earlier minutes of an equally-priced dispatch (GH#5330, probe-verified on the reporter's own replay at main 57ec7bf1: charged-early 10:00–11:30 = 148.5602p, continuous 10:00–12:00 = 148.5586p, the reporter's 10:30 late ramp = 148.5745p — equal to rounding), so placement is decided by search convergence plus plan retention (`metric_min_improvement_plan`) — **second live instance GH#5344** (GE Hybrid + one car on IOG, 2026-10-02, reporter-log-verified): the mid-band charge limit flapped between equally-scored shapes tick to tick and the overnight limit shrank toward a later cap (91% at 00:05 → 99% by 04:45 → 100%) as the horizon narrowed, which is the tie surface shrinking, not an execute fault; concurrent battery charging during the car's dispatch is allowed and executed on this shape, so do not read a car dispatch as a charge window blocker; the IOG earlier-charge skew that *does* exist (`IO_ADJUST_SLOPE`/`_PIVOT`/`_MAX_DISCOUNT`/`_MAX_PENALTY`/`_DISCOUNT_HORIZON`, `_io_rate_adjustment()` inside `sort_window_by_price_combined()`, plan.py) is ranking-level only — a signed gradient over `io_adjusted`-flagged window starts, reordering candidate windows, never a tie-break in the metric — so equal-cost placements land wherever the search converged. Suspected, not verified: PR #5304's PV10 "dispatch gone" hedge can *systematically* steer the planner to the un-flagged tail of a dispatch (the integration's `io_adjusted` flags can stop short of the dispatch end); and which search/retention path resolves equal-metric placements late. Cheap A/B technique: replay the dump, then compare direct `run_prediction()` variants — any placement fix must survive metric evaluation (a real cost term, or an explicit equal-metric tie-break that slides windows earlier inside an `io_adjusted` run). See also the previous row — pre-#5304 the dispatch minutes also were never `io_adjusted`-flagged, so the PV10 hedge did not even see them. | | IOG: the house battery charges cheaply for the first few minutes of a car dispatch that started the moment it was published, then the plan reverts | The car-need gate from PR #5403 (v9.3.6, for #4482) can only withhold dispatch minutes from the half hour **after** the current one — `octopus_surplus_from()` returns `(minutes_now // 30 + 1) * 30` (octopus.py; the docstring states the carve-out as deliberate: the car may already have charged in the current one), and `rate_add_io_slots()` skips only `minute in self.octopus_surplus` — so a same-instant-start dispatch still cheap-stamps the current half hour even with `octopus_intelligent_consider_full` on (GH#5424, diffed the published v9.3.5 tarball against main). The only veto inside that half hour is the dynamic-load evidence path — 3 min start + 2 min sensor grace (`DYNAMIC_LOAD_CAR_START_MINUTES`/`DYNAMIC_LOAD_CAR_SENSOR_MINUTES`, const.py) then replan + strip — and with `octopus_intelligent_trust_slots` off the running decision `dynamic_load_car_cancelled.get(car_n, default_cancelled)` (plan.py) can retain a stale not-cancelled from a dormant (slot-less) phase, so a trust-off user's first cycle inside a brand-new dispatch is still trusted until the grace evidence lands. The car-side skip (`Car 0 is already charged, ignoring additional charging slot`, execute.py) does not stop the house plan. So "upgrade fixes it" is not an answer to a same-instant-start dispatch report without checking which half hour the dispatch started in. Overnight dispatches inside the fixed 23:30–05:30 band are tariff-cheap regardless (`in_iog_fixed_window` excludes them from the gate) — don't attribute overnight dispatch-stamp plans to this class; #4516 is the open umbrella for the residual. | -| Plan won't charge or export inside Intelligent dispatch windows while the same cheap price from manual rates cycles normally - and `pv_metric10_weight` alone turns the behaviour on/off | The PV10 scenario re-prices every `io_adjusted`-flagged minute past the first 30 simulated minutes at `max(rate_max, import_rate)` (the `dispatch_gone` rule, prediction.py mirrored in prediction_kernel.cpp; deliberate since PR #5304 fixing GH#5392, pinned by `test_dispatch_gone_priced_at_tariff_max` and the kernel-parity cases). The flags are set by the rate feed wherever a fetch carries an `adjust_key` (`fetch.py`, `is_intelligent_adjusted`), with no `octopus_intelligent_*` config gate; a manual rate over a flagged slot keeps the flag (`apply_manual_rates()`); the only per-minute deleter is `dynamic_load_car_strip_feed_rates()` - so PV10 can worst-case a dispatch minute Predbat itself stamped. `plan.py` weights the PV10 plan by `pv_metric10_weight` (default 0.15): one setting carries both solar pessimism and dispatch-withdrawal risk (GH#5540). Diagnostic: `io_adjusted` present around the window in the debug yaml. Fix trap: Python reads `io_adjusted` while the C kernel sees `io_flag` (`prediction_kernel.py`), so any switch must gate both in lockstep or `test_kernel_parity` fails. | +| Plan won't charge or export inside Intelligent dispatch windows while the same cheap price from manual rates cycles normally - and `pv_metric10_weight` alone turns the behaviour on/off | The PV10 scenario re-prices every `io_adjusted`-flagged minute past the first 30 simulated minutes at `max(rate_max, import_rate)` (the `dispatch_gone` rule, prediction.py mirrored in prediction_kernel.cpp; deliberate since PR #5304 fixing GH#5392, pinned by `test_dispatch_gone_priced_at_tariff_max` and the kernel-parity cases). The flags are set by the rate feed wherever a fetch carries an `adjust_key` (`fetch.py`, `is_intelligent_adjusted`), with no `octopus_intelligent_*` config gate; a manual rate over a flagged slot keeps the flag (`apply_manual_rates()`); the only per-minute deleter is `dynamic_load_car_strip_feed_rates()` - so PV10 can worst-case a dispatch minute Predbat itself stamped. `plan.py` weights the PV10 plan by `pv_metric10_weight` (default 0.15): one setting carries both solar pessimism and dispatch-withdrawal risk (GH#5540). `octopus_intelligent_pv10_dispatch_gone` (expert switch, default On) turns the rule off in both engines without touching `io_adjusted`, which the rate replication, IOG charge skew and dynamic dispatch check still need - check it in the debug yaml first. Diagnostic: `io_adjusted` present around the window in the debug yaml. Fix trap: Python reads `io_adjusted` while the C kernel sees `io_flag` (`prediction_kernel.py`), so any switch must gate both in lockstep or `test_kernel_parity` fails. | | "Random" exports that lose money on a flat export tariff | `metric_battery_value_scaling` below 1.0, then `metric_cloud_enable` being off. See "Check configuration before code" above (GH#4840) — the protective margin is ~1%, so a small reduction is enough. | | Exports at the outgoing-Agile peak then imports through the rest of the evening at a higher rate — "it never sells above my buy price, so it is not optimised for cost" | Working as designed: the governing comparison is the sell price vs the **refill** price (overnight IOG band), not vs the simultaneous import price (GH#5509, dump-read + replay-denied arithmetic, 2026-10-12): selling ~12 kWh at ~25.6p and refilling ~17 kWh at ~3.8p nets ~+£2.3/day, and the pennies-scale loss is only the last stretch below the SoC floor. The reporter had also zeroed the overnight outgoing rate via their own `rates_export_override`, which strands the surplus at 0p and makes the daytime export look worse. The knob is `best_soc_keep` (soft, kWh). Reading the plan table card: the second/third columns are import/export rates, not SoC — cross-check a window's `average` against the rate column before reading the rows (the same misread cost GH#5509 its first pass). Distinct from #5205 (a midnight-split charge slot re-splitting into charge-export-charge — a genuine slot-splitting bug) and #4869 (negative prices). Second confirming report GH#5566 (Fox KH7 + IOG import + ~29p export band → 7.62p refill, 2026-10-16, plan/log-parsed): the family is neither Agile-outgoing- nor Sigenergy-specific, and the planner **cannot express "export hard but stop at 45%"** — every export-window target rung is `calc_percent_limit(self.best_soc_min, self.soc_max)` (plan.py; `optimise_export()` sweeps only window start plus IDLE/FREEZE/low-power modes), so a planned export discharges at full power and the stop line is the window length. The limit % a plan row displays is the **achieved** SoC, not a chosen level — `clip_export_slots()` raises the recorded target to the SoC the simulation reached (the `best_soc_min` target minus a 10-minute discharge margin) when it never got there — so don't read "34% limit" off a plan row as a planner decision; `set_export_low_power`'s rungs `[0.7, 0.5, 0.3]` (`LOW_EXPORT_POWER_LEVELS`) are the granularity lever, and `best_soc_keep` is the right knob for the tail because the penalty is **import-rate-weighted** (prediction.py) — it bears hardest exactly in peak-drain reports; `set_reserve_min` is the harder, round-the-clock floor. Refill-price governs the arithmetic: sell at the export band, refill at the cheap band, with only the pennies-scale tail below the keep-point losing — quoting that split settles the report. **Third instance of the family, GH#5579 (2026-10-17, code-read on main — all three sites re-verified 2026-10-18):** the recurring "don't let exports run the battery down to the true reserve; keep N% back during export windows" ask maps to `best_soc_min` (kWh, expert mode, default 0 — no config item named "export reserve" exists), and it binds **only inside planned export windows**, at three layers: the model floor `discharge_min = max(soc_max × export_limit%, reserve, best_soc_min)` (prediction.py), the export-window candidate target rungs (`calc_percent_limit(best_soc_min, soc_max)` in `optimise_export()`, plan.py) and the execute stop level `max(target, reserve, best_soc_min)` (execute.py) — outside export windows the floor is the reserve alone. Two nuances before a fix conversation: units are kWh (`soc_max × 25%` for a "25%" ask), and the plan writes its own export target register during the window — `export_target_soc_percent()` raises the written target to `max(reserve, best_soc_min)` only when `set_reserve_enable` is off (PR #4685's rule: where Predbat owns the reserve register the reserve enforces the floor and the target is left alone) — so "plan at 25% but leave the portal target at 20%" is not a mode that exists; the 20% floor lives in the reserve register outside windows. The maintainer's remedy on #5566 itself was raising `load_scaling90`'s default 0.7 → 0.9 (PR #5577, 2026-10-17) — the PV90 scenario's 15% weight now hedges a heavier load too. | | Battery charges or freezes when it shouldn't | Freeze paths in `prediction.py` and the inverter component's control write; check `best_soc_keep` and the freeze-related config in the replay. Rule the plan out first: the signature of a *planned* freeze is a charge window whose limit equals the reserve percent, which `prediction.py` turns into a freeze and then blocks discharge across for the whole window, with execute writing `charge_limit` = current SoC and a 0 W discharge rate. All three together mean the planner chose it and the inverter did as it was told - on a tariff where every cycle loses money and stored energy is credited at replacement cost, holding the battery full and importing everything is the arithmetic working, not a control failure (GH#4890). |