Skip to content

fix(car-charging): hold battery discharge during car charging regardless of car_energy_reported_load (#4246)#4264

Merged
springfall2008 merged 5 commits into
mainfrom
fix/car-charging-discharge-hold
Jul 17, 2026
Merged

fix(car-charging): hold battery discharge during car charging regardless of car_energy_reported_load (#4246)#4264
springfall2008 merged 5 commits into
mainfrom
fix/car-charging-discharge-hold

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

Fixes #4246. Carries over the fix from #4247 (by @chalfontchubby) into the main repo so the cross-platform kernel binaries can be rebuilt and committed by CI (the kernel-binaries auto-commit job can't run on fork PRs, which is why #4247 failed the checked-in-binary parity verify step).

The fix

Removes the and self.car_energy_reported_load condition from the discharge-hold gate in execute.py and prediction.py (mirrored in prediction_kernel.cpp for C++/Python parity), so car_charging_from_battery = Off always holds discharge during car-charging windows, regardless of CT-clamp visibility.

Why a new PR

#4247 came from a fork, so the kernel-binaries job (which needs contents: write to cross-build and commit the prediction_kernel_lib_*.so binaries back to the branch) was skipped. That left the checked-in x86_64 binary stale relative to the modified prediction_kernel.cpp, failing the parity verify step. Opening from a branch in this repo lets that job run and refresh the binaries.

Original commits and authorship from @chalfontchubby are preserved on this branch.

Verification

  • New/updated regression test (no_discharge_car_demand1b in test_execute.py) passes against the fix, fails against main.
  • Full local suite passes, including kernel_parity and model_kernel.
  • run_pre_commit passes cleanly.

Supersedes #4247. Credit to @chalfontchubby for the fix.

chalfontchubby and others added 4 commits July 14, 2026 09:01
…rted_load is Off

Adds a regression case mirroring no_discharge_car_demand1 but with
car_energy_reported_load=False, asserting discharge should still be
held (status "Hold for car", pause_discharge=True). Currently fails,
reproducing the reported behaviour where the discharge-hold protection
is silently skipped for CT-clamp-blind-spot topologies where the
battery and car still share a busbar. See issue #4246.
…ess of car_energy_reported_load

car_energy_reported_load only controls whether car load is visible to the
CT clamp for house-load/export accounting purposes - it says nothing about
whether the battery can physically reach the car. Previously the discharge-hold
gate for car_charging_from_battery=Off was also conditioned on
car_energy_reported_load being On, so CT-clamp-blind-spot topologies (e.g. a
Henley block tapped ahead of the clamp) where the battery and car still share
a busbar got no discharge protection at all during car charging.

Removes that condition in execute.py and prediction.py (with the matching
change mirrored in prediction_kernel.cpp to keep C++/Python parity), so
discharge is held whenever car_charging_from_battery is Off, independent of
CT-clamp visibility. The charge decision itself is unaffected - charge
window/rate and discharge-hold are controlled by separate code paths, so a
window that's genuinely charging from grid still charges as planned.

Updates no_discharge_car_demand1b to assert the corrected behaviour and folds
in the reproduction case added previously. See issue #4246.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot review flagged that "the battery shares the same busbar either
way" is a claim Predbat can't actually verify from car_energy_reported_load
alone - that switch only reflects whether EV energy is counted in the
CT-clamp house-load model. Reworded the remaining comments (execute.py,
prediction.py, prediction_kernel.cpp) to match the wording already applied
to the test_execute.py comment, stating only what the setting controls
rather than asserting a specific wiring topology.
Copilot AI review requested due to automatic review settings July 17, 2026 09:26

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 fixes an incorrect discharge-hold gating condition during EV charging windows: battery discharge is now held whenever car_charging_from_battery = Off, even when car_energy_reported_load = Off (shared-busbar / upstream-of-CT topologies). This aligns both the runtime execution path and the Python/C++ prediction engines with the intended semantics of those switches.

Changes:

  • Remove car_energy_reported_load from the discharge-hold gate in execute.py, so discharge hold is enforced during active car slots whenever charging-from-battery is disabled.
  • Apply the same logic change to the Python prediction engine (prediction.py) and the C++ kernel (prediction_kernel.cpp) to maintain parity.
  • Update the execute regression test (no_discharge_car_demand1b) to assert “Hold for car” + discharge pause when car_energy_reported_load=False.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
apps/predbat/execute.py Enforces discharge-hold during car charging whenever car_charging_from_battery is disabled, independent of CT-clamp visibility.
apps/predbat/prediction.py Mirrors the same discharge-hold behavior in the Python prediction model for correctness and parity.
apps/predbat/prediction_kernel.cpp Mirrors the same change in the C++ kernel to keep compiled-kernel behavior aligned with Python.
apps/predbat/tests/test_execute.py Adjusts regression expectations to validate the corrected discharge-hold behavior when car_energy_reported_load=False.

@springfall2008
springfall2008 merged commit f3ddd50 into main Jul 17, 2026
2 checks passed
@springfall2008
springfall2008 deleted the fix/car-charging-discharge-hold branch July 17, 2026 09:46
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.

Battery discharges during car charging when car_energy_reported_load: Off, despite predbat.status showing 'Charging' (shared-busbar topology)

3 participants