Export price peak hides earlier export slots from the planner, so the battery fills before the solar peak
Opened by Claude on Rik's behalf.
Summary: in automatic mode the export threshold is rate_export_min + 0.5. Any slot at the tariff's lowest export price is therefore never offered to the planner as an export window. When that cheap period is the morning and a higher price comes in the afternoon, the plan can't export before the solar peak. The battery fills, and solar above load plus the export limit is clipped. The planner already costs clipping correctly: it simply never gets to consider the slots that would avoid it. This is separate from #5221, whose reported Axle case #5163 fixed. #5163 only removes tagged events (Axle, saving sessions) from the threshold; an ordinary price peak in the tariff itself still hides the cheaper slots. No user has reported this case yet. It is shown here on a synthetic tariff.
Repro
Take an export-limited system's debug dump (here the 4 Sep #4865 Axle dump, with its Axle session removed). Set export to 20p from midnight to noon and 90p from noon to midnight each day, and import to a flat 23.8p. Replay with --redo on main 8689aa74:
| Export tariff | Export threshold | Candidates before noon tomorrow | Predicted clipping | Plan metric |
|---|---|---|---|---|
| 20p / 90p, as main does it | 90p (20.5p, then raised to the lowest window found) | 0 | 1.20 kWh | -6454.6 |
| 20p / 90p, every export slot offered | 20p | 24 | 0.22 kWh | -6473.8 |
| Flat 20p, for reference | 20p | 24 | 0.10 kWh | -1885.5 |
With the morning slots visible, the plan exports 06:30-07:30 and 11:00-11:30 before the peak. Predicted clipping drops by about 1 kWh and the metric improves by 19.2p, on one day of one system.
Why the threshold can't be tuned to fix it
The threshold is worked out from price statistics alone. It knows nothing about how much energy has to leave the battery, or when. Moving the +0.5 / -0.1 margins changes which tariff shapes break, not whether any do. Offering every slot is safe for the plan but costs search time, which is why the threshold exists.
Possible direction
Keep the threshold, and add windows only where the plan would otherwise clip. Walk the do-nothing state of charge forward. Wherever it predicts clipping, admit the best-priced earlier slots, after the last time the battery was full, until they cover the clipped energy within the export limit. Then add those slots to high_export_rates and never remove any. A prototype of this was described on #5221 (25 Sep). The extra windows are purely additive, so a window the optimiser doesn't use costs only search time.
Related: #5221 (the Axle case, fixed by #5163), #4865, #6205.
๐ค Generated with Claude Code
Automated first-pass triage โ a maintainer will review before any action is taken.
Classification: enhancement ยท priority_low. Both labels were already on the ticket; I agree with each and have not changed them. No duplicate found.
Verified on current main (v9.8.0, 967347d6). The issue's base commit 8689aa74 is an ancestor of it and nothing since has touched this path (set_rate_thresholds(), the export window scan, high_export_rates), so the table above still stands. I reproduced its first two rows with a temporary probe inside test_set_rate_thresholds (a test written, run, then removed; nothing committed) on the same synthetic shape โ export 20p 00:00โ12:00 and 90p 12:00โ24:00, import flat 23.8p, combine_export_slots off:
threshold after set_rate_thresholds = 20.50
windows = 24, before noon = 0, all at 90.0p
threshold after the rescan = 90.00
same scan at the tariff minimum (19.9) = 24 windows before noon
So the mechanism is exactly as described. Confirmed in the code, which is what makes the premise hold:
- The automatic export branch sets the threshold from price statistics alone,
rate_export_min + 0.5on this shape, and the scan only admits minutes withrate >= threshold(andrate > 0). A slot priced at the tariff's own minimum can therefore never be admitted โ no margin can fix that, only moving the threshold to (or below) the minimum, which admits everything. calculate_plan()takes its export candidates by cloninghigh_export_rates, andclip_export_slots()only narrows or raises the targets of windows already enabled โ no pass in the plan can add a slot. Adding windows is indeed the only route.- Scoping point worth keeping in the issue: the
-0.1branch of that same automatic expression fires when the cheapest export pays more than the cheapest import, and already admits every slot. So this only bites on the common shape where the cheapest export is below the cheapest import. - When reading a reporter's dump: the threshold stored there is the ratcheted value (90p here), not the one the window scan actually used (20.5p). The rescan overwrites it after the candidate list is built, so it affects the published threshold and the plan table's rate shading, not that cycle's windows.
I did not re-run the plan-level replay โ it needs the 4 Sep #4865 dump, which is not in the repo โ so the clipping and metric columns are the issue's own. They are arithmetically consistent: 1.20 โ 0.22 kWh is ~0.98 kWh recovered, priced at 20p that is the 19.2p metric gain, so it reads as the value of the energy rather than an optimiser tie-break.
On the proposed direction โ adding windows only where the plan would otherwise clip looks right to me: it is the only middle path, since any price-only threshold either excludes the tariff's cheapest band or admits every slot. Five things I would want settled before implementation:
- Where it lives matters more than it looks. Not in fetch's rate scan โ that has the rates but no predicted SoC. The natural hook is at the start of
calculate_plan(), right after the baseline prediction the plan already runs before the search ("Simulate current settings"). On a typical automatic-mode systemcharge_window/export_windoware empty, so that baseline is close to the do-nothing trajectory the proposal wants; worth confirming it is actually empty on any system this is tested against. Doing it there also gives the tariff-comparison and annual paths the same behaviour for free, which a change in fetch would not (both rescanhigh_export_ratesthemselves). - The clipped energy is not returned today.
run_prediction()returns cost, the kWh totals, SoC, cycle and keep figures, and no clipped figure, andpredict_clipped_bestis only populated for the saving runs (best,test,compare,yesterday) โ the plan copies it for the final saved plan only. The pass needs either a save-enabled baseline run or clipped energy added to what a prediction returns. (The same gap is what blocks the cheaper option on #6205, so it may be worth doing once.) - Do not add the extra slots to
high_export_ratesitself. That list drives the publishedsensor.predbat_high_rate_export_start/_end/_cost/_durationandbinary_sensor.predbat_high_rate_export_slot, plus the plan table's rate shading throughrate_export_cost_threshold. Clipping-driven slots are the tariff's cheapest ones, so publishing them as the "next high export rate" would be wrong. A separate candidate list feedingexport_window_bestavoids that. - Cost. A saving plan run makes on the order of a quarter of a million predictions, so candidate windows are not free per iteration. Compute the admitted set once per plan and reuse it across the search's iterations, and keep the "until they cover the clipped energy" bound, otherwise a fully clipped afternoon will admit the whole day. Follow the slot granularity fetch already produced (
combine_export_slotson = one window per band, off =plan_interval_minutesslots) rather than re-splitting. - "Never remove any" is safe after the search, not before it. The plan already drops windows the search left idle (
discard_unused_export_slots()) and slots that change nothing in the nominal plan (prune_dead_plan_slots()), so additive candidates cannot leak into the executed plan. That is the property that makes the approach low-risk โ worth stating in the issue.
A cheaper variant, if the extra prediction is unwelcome: seed this cycle's window set from the previous cycle's predict_clipped_best, which the last saved plan already keeps. That costs nothing at plan time and converges within a cycle or two on a slow-moving problem, at the price of reacting to where the previous plan clipped rather than the do-nothing trace.
Related: #5221, closed today โ its Axle-event case was fixed by PR #5163, and this is the general, no-event form it grew into. Also #4865 (PV clipping protection, closed), #1206 (clipping buffer, open), #6205 (shared need for a returned clipped total).
No information requested; the ticket is complete as written.