Charge car on solar excess - #4683
Open
romain-intel wants to merge 2 commits into
Open
Conversation
Car slots were placed on import price alone, with no awareness of sunshine, so a car could be scheduled to buy energy overnight while the next day's surplus was exported instead. New switch.predbat_car_charging_solar (off by default) places slots on forecast PV first, and because the existing loop stops once the car's requirement is met, the price-based pass then only covers the shortfall. A slot qualifies on two tests, mirroring the pair iBoost already has for the same "divert rather than export" decision: - forecast PV power at least car_charging_solar_excess (default 1kW) - export rate no higher than car_charging_rate_threshold_export (default 99p), which is what "it isn't worth exporting" means in practice car_charging_plan_min_soc splits the plan in two, for setups where only part of the charge is worth paying for. Bought slots stop at that percentage and must complete by the ready time, so it is the charge guaranteed whatever the weather; solar slots carry on past it to the full car_charging_limit. Left at its 100% default both targets are identical and nothing changes. This mirrors the minimum slider in Tesla's Charge on Solar, so Predbat's forecast of the car's draw can be kept in step with what the car will actually do. Because solar is opportunistic rather than a promise, solar windows run to the forecast horizon while bought windows stop at the ready time - otherwise an early morning deadline would exclude every daylight hour. Overlapping candidates are planned once, and solar windows bypass car_charging_plan_max_price since their energy is not bought. They are priced at the export rate given up, which is their real cost. Slots carry a solar flag through to the car plan attributes. Car planning now runs after the PV forecast is fetched rather than before it; nothing between the two positions reads the car plan. No new mechanism was needed for the battery-versus-export trade-off: the car's demand is already part of the prediction, so an export that drains the battery is priced against the import the car then needs. Measured with car_charging_from_battery on, a 5p export rate keeps the charge and 60p sells it, and letting the battery serve the car cut grid import from 8.4kWh to 6.4kWh. Pinned by a test, since it is not obvious from reading either module alone. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> (cherry picked from commit adf0db9e17c681b6439b5d8c1077f001d9873d3d)
…'s rating A charge-on-solar charger modulates to whatever the sun leaves over the house, but the plan assumed it drew its full rated power for the whole slot - a 7kW charger booked 3.5kWh into every half hour regardless of whether there was 7kW spare or 1kW. That error does not stay inside the car plan. The car's predicted draw is part of the load the battery is planned around, so demand the sun cannot meet went into the forecast and the battery looked like it had to cover the difference, skewing the charge and export decisions that followed. Solar slots are now sized as forecast PV less forecast house load, capped at what the charger can take. Surplus is computed per five minute bucket and floored at zero in each, because a car cannot charge on an average - a bright half hour either side of a dark one yields the bright half, not their sum. The same measure now backs the car_charging_solar_excess gate, which is what that setting's name has always claimed: 4kW of sun against a 4kW house left the car nothing and used to qualify anyway. The house load forecast this needs is the one calculate_plan builds, which does not exist yet when car slots are planned during the fetch, so it is rebuilt here from the same inputs. Car planning moves after the modal filter, the historical load forecast and load_inday_adjustment, all three of which feed that load; nothing in between reads the car plan. It is built once per car plan rather than per window, as step_data_history walks every previous day for every bucket. The historical load it derives from already has car charging subtracted out of it, so the car's own draw cannot feed back in as house load. Bought slots are unchanged: there Predbat is asking for the charger's full rate, and gets it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> (cherry picked from commit e2c6863667b8d0e5fae6a015ad05a39e06009437)
romain-intel
force-pushed
the
pr/car-solar
branch
from
August 25, 2026 04:36
b5b23f4 to
d006958
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR allows for a car to charge on excess solar power. It is meant to mimic (and is therefore compatible) with the "Charge on Solar" offered by Tesla.
With this change, PredBat will activate car charging slots during the day when there is enough solar for the car to charge and it is not worth keeping the power to export it to the grid (low buy rates). You can then hook up an automation to switch your car's charger on/off if needed. The assumption is that the car charger will modulate the current it pulls to only use solar power (which is what the Tesla "Charge on Solar" does).
"Charge on Solar" exposes another value which is the "charge from any source". It is, unfortunately, not yet exposed through the API so this is a manual setting. WIth this setting PredBat will also schedule night slots (ie: when power is cheaper) to charge to at least that amount.
This was designed to work with Tesla's "Charge on Solar" but should work with any other system that has a similar characteristic.