Skip to content

Split charge windows at dawn for any combine_charge_slots user, not just low power mode - #4604

Merged
springfall2008 merged 1 commit into
mainfrom
feat/dawn-split-without-low-power
Aug 20, 2026
Merged

Split charge windows at dawn for any combine_charge_slots user, not just low power mode#4604
springfall2008 merged 1 commit into
mainfrom
feat/dawn-split-without-low-power

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

Summary

  • calc_dawn() (added for Low power charge toggle does nothing #4557) splits a charge window at the light/dark PV boundary so a window spanning sunrise doesn't get treated as one indivisible block. It was only ever computed when set_charge_low_power was on.
  • But the split only matters when combine_charge_slots is on in the first place — with it off, find_charge_window already forces a break every charge_slot_split minutes (= plan_interval_minutes, the same granularity calc_dawn buckets at), so the dawn boundary can never be reached and computing it was a no-op there.
  • That gating also meant combine_charge_slots users without low power charging never got the split, even though it has a benefit independent of low power: it lets the plan optimizer charge just the dark portion of a combined window and skip the daylight portion where solar may cover the load.
  • New calc_pv_light_dark() decides whether to call calc_dawn(), gated on combine_charge_slots instead of set_charge_low_power.
  • calc_dawn() now also logs the calculated dawn time each cycle it runs, so it's visible in the log whether the detected dawn looks sane.

Test plan

  • ./run_all --test find_charge_window — new test_calc_pv_light_dark covers all four combine_charge_slots × set_charge_low_power combinations; existing test_calc_dawn and Path J (pv_light_dark boundary) tests unaffected
  • ./run_all --quick — full quick suite passes, including the random scenario plan regression against the committed baseline
  • ./run_pre_commit — black/ruff/cspell/docstring coverage all pass

🤖 Generated with Claude Code

…s user, not just low power mode

The dawn light/dark split (calc_dawn, #4557) only ever mattered when
combine_charge_slots could merge a window across sunrise - with it off,
find_charge_window already forces a break every charge_slot_split minutes
(= plan_interval_minutes, the same granularity calc_dawn buckets at), so the
split was already a no-op there. It was gated on set_charge_low_power
instead, which meant combine_charge_slots users without low power charging
never got it, even though the split also lets the plan optimizer charge just
the dark portion of a combined window and skip the daylight portion where
solar may cover the load - a benefit independent of low power charging.

New calc_pv_light_dark() gates the split on combine_charge_slots directly.
Also logs the calculated dawn time each time it runs, so it's visible
whether the detected dawn looks sane.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 19, 2026 19:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts how Predbat splits charge windows at the PV light/dark (dawn) boundary so the split is applied for any user with combine_charge_slots enabled, rather than only when set_charge_low_power is enabled. This improves the planner’s ability to treat cheap-rate windows spanning sunrise as separable dark/light portions for optimization.

Changes:

  • Add calc_pv_light_dark() to gate dawn-splitting on combine_charge_slots and update fetch_sensor_data() to use it.
  • Enhance calc_dawn() documentation and add logging of the detected dawn time (or absence of one).
  • Add a new unit test test_calc_pv_light_dark covering all combine_charge_slots × set_charge_low_power combinations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
apps/predbat/fetch.py Introduces calc_pv_light_dark() and switches dawn boundary computation to be driven by combine_charge_slots; adds dawn-time logging in calc_dawn().
apps/predbat/tests/test_find_charge_window.py Adds test_calc_pv_light_dark and wires it into the existing test_find_charge_window test flow.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread apps/predbat/fetch.py
@springfall2008
springfall2008 merged commit 3a5eb03 into main Aug 20, 2026
3 checks passed
@springfall2008
springfall2008 deleted the feat/dawn-split-without-low-power branch August 20, 2026 16:37
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.

2 participants