diff --git a/apps/predbat/config.py b/apps/predbat/config.py index f62a893ff..95da4044a 100644 --- a/apps/predbat/config.py +++ b/apps/predbat/config.py @@ -944,6 +944,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 3fae36e54..03ea6a162 100644 --- a/apps/predbat/fetch.py +++ b/apps/predbat/fetch.py @@ -5093,6 +5093,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 7d079e3fe..df2620ba9 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -608,6 +608,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 2beeca3ec..38da10a5c 100644 --- a/apps/predbat/prediction.py +++ b/apps/predbat/prediction.py @@ -191,6 +191,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) self.io_confirmed_credit = base.io_confirmed_credit # 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 @@ -607,8 +609,11 @@ 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 + io_confirmed_credit = self.io_confirmed_credit + # 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 440b3c95d..473539a45 100644 --- a/apps/predbat/prediction_kernel.py +++ b/apps/predbat/prediction_kernel.py @@ -719,6 +719,7 @@ def build_static_context_arrays(pred, n_steps, minutes_now, num_cars): # The battery ceiling curves are a pure function of the temperature at that step (Prediction.rate_curves, memoised # there per temperature), and a forecast normally holds one value for hours at a time, so each distinct curve # becomes one row of a small table and each step carries its row index. + 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 @@ -727,8 +728,9 @@ 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) io_credit.append(pred.io_confirmed_credit.get(minute_absolute, 0.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 ff1bbda16..f67ee9880 100644 --- a/apps/predbat/tests/test_kernel_parity.py +++ b/apps/predbat/tests/test_kernel_parity.py @@ -867,6 +867,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 d582c2d99..732948ea6 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 0768e995b..a11f5bd6f 100644 --- a/docs/car-charging.md +++ b/docs/car-charging.md @@ -786,6 +786,8 @@ The effect is that with a low battery Predbat may top it up in the first half ho Once your car is charging in the dispatch (see **Charging the battery while the car is charging** below), the rest of that dispatch is no longer assumed to go away: if it did, Predbat would notice within a cycle (5 minutes). Instead the house and battery pay the peak rate for 5 minutes of each half hour of it, and the car's own charging pays none of that, as the car stops with its dispatch. 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. - When a dispatch is withdrawn, the Octopus Energy integration's import rate sensor can keep showing its cheap rate for a while. Predbat puts those minutes back to your normal rate once no dispatch covers them, as long as it saw a dispatch covering them before. Nothing is changed while a car is charging, as Octopus briefly lists no dispatches while it re-plans a running charge. With **switch.predbat_octopus_intelligent_dynamic** Off the half hour in progress is left alone too, as the car may have charged in it before the dispatch was withdrawn. diff --git a/docs/customisation.md b/docs/customisation.md index 31e9dcb4f..98c485391 100644 --- a/docs/customisation.md +++ b/docs/customisation.md @@ -358,6 +358,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 cd9209ebb..82ef36446 100644 --- a/tools/debug-journal.md +++ b/tools/debug-journal.md @@ -769,7 +769,7 @@ What a report or log shows, and where to start. Where a symptom belongs to one i - **IOG: battery flat inside an evening dispatch running past 23:30, plan waits until 01:00** — fixed in PR #5304 (2026-09-30). Replays, even `--redo`, reuse the dump's `rate_import`/`io_adjusted`; overlay from `rate_import_no_io`. - **IOG: the battery charges at the back of a long, equally cheap dispatch, or the limit flaps tick to tick** — placement is metric-neutral, so search convergence and `metric_min_improvement_plan` decide it. Since PR #5635 (2026-10-19) `io_confirmed_credit_update()` adds a small score-only early credit in a confirmed run, and since PR #5896 (2026-11-05) PV10's dispatch-gone hedge (re-pricing `io_adjusted` minutes at `max(rate_max, import)`) is skipped for those confirmed minutes in both engines — so a dump with a non-empty `io_confirmed_credit` scores PV10 kinder than the #5304-era math; check that map before calling it a hedge regression. Open. (GH#5330, GH#5344) - **IOG: the battery charges cheaply for the first minutes of a dispatch that started the moment it was published** — `octopus_surplus_from()` withholds only from the next half hour; in the current one only dynamic-load evidence vetoes. Umbrella #4516 open. (GH#5424) -- **Plan won't use Intelligent dispatch windows, and `pv_metric10_weight` alone toggles it** — PV10's `dispatch_gone` rule prices `io_adjusted` minutes after the first 30 at `max(rate_max, import)`; any feed with an `adjust_key` sets the flags. Gate the kernel's `io_flag` too or `test_kernel_parity` fails. (GH#5540) +- **Plan won't use Intelligent dispatch windows, and `pv_metric10_weight` alone toggles it** — PV10's `dispatch_gone` rule prices `io_adjusted` minutes after the first 30 at `max(rate_max, import)`; any feed with an `adjust_key` sets the flags. Gate the kernel's `io_flag` too or `test_kernel_parity` fails; `octopus_intelligent_pv10_dispatch_gone` Off disables the rule. (GH#5540) - **Predbat charged the car at peak rate** — before PR #5251 (2026-09-26) `car_charging_plan_smart` defaulted false. A saving-session reward on the import rate can drop that hour from `low_rates`, gapping the car slots. (GH#2716) - **A short dispatch, the car never charged in it, and the battery charged through it at day rate** — short dispatches structurally cannot reach a dynamic-load-car cancel verdict: load-path evidence needs the whole PREDICT_STEP window inside the dispatch (`dynamic_load_car_evidence()`), the grace is timed on the 5-minute grid clock, and once the verdict cycle falls at/after the dispatch end the expired dispatch drops out — a ≤~15-min dispatch is never cancelled, not cancelled late. `dispatch_too_short()` only distrusts sub-5-minute dispatches (`OCTOPUS_SLOT_MIN_MINUTES`), and `octopus_intelligent_trust_slots` defaults On. Any new evidence path must not reuse dynamic_load_car's confirmation clocks, which mutate in place every poll. (GH#5914, verified 2026-11-10) - **Repeating `Warn: Out of range index N within item car_charging_planned` (or `_plugged`, `_energy`)** — fewer charger entries than `num_cars`, so extra cars read unplugged; keep a fix car-arg-scoped, as per-inverter args rely on the fallback. PR #4928 open. (GH#5783)