Repository navigation
Charge car on solar excess - #4683
Closed
romain-intel wants to merge 5 commits into
Closed
romain-intel wants to merge 5 commits into
romain-intel wants to merge 5 commits into
Conversation
romain-intel
force-pushed
the
pr/car-solar
branch
2 times, most recently
from
August 26, 2026 09:17
d006958 to
42af2d7
Compare
Contributor
Author
|
Anything I need to change on this one? I've been running it at my house for several weeks and it seems fairly stable and to do what is intended. Is it too specific for Tesla cars? |
romain-intel
force-pushed
the
pr/car-solar
branch
2 times, most recently
from
August 31, 2026 06:56
8e426ea to
bd2545e
Compare
romain-intel
force-pushed
the
pr/car-solar
branch
from
September 7, 2026 08:47
bd2545e to
23e24e8
Compare
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)
New input_number.predbat_car_charging_solar_battery_soc, default 0% so nothing changes for anyone who leaves it alone. Below that level surplus solar goes to the house battery and no car window is offered; at or above it the car has first call as before. Solar car charging gives the car the surplus whenever there is any, which is the right default but not always what is wanted: a car that does not need a full charge today is a worse home for a kWh than a battery facing an expensive evening. This is the mirror of car_charging_plan_min_soc - that one caps how much of the car you pay for, this one says how much battery you want banked before the car is worth more than the pack. The level is judged per slot from a battery estimate walked forward as the held surplus fills it, not from the SoC at planning time, so a pack that reaches the level mid-morning releases the car mid-morning rather than holding all day. What the battery cannot physically absorb within a slot is not held back either, since that surplus would otherwise be exported at whatever midday pays. The value is clamped to 0-100 rather than trusted, so a mistyped level cannot produce a threshold above the pack that holds the car back forever. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
New select.predbat_manual_car_away, a per-slot override in the same shape as the other manual overrides. Slots marked away are skipped when planning car charging. car_charging_planned reports whether the car is plugged in now, which is exactly right for deciding whether to charge in this moment and no use at all for planning. A plan made this morning will schedule an afternoon charge for a car that is going to be out, and only discovers otherwise when the afternoon arrives - by which point the surplus it reserved has been spent on nothing. Marking the afternoon away instead lets Predbat move the charge to a slot the car is actually there for, and use the sun it would have spent on the house battery. Skipped entirely rather than shortened or repriced: a car that is not there cannot take cheap import or surplus solar, so there is nothing to reprice. The test sits before the have-enough check rather than after, or the first away slot would break out of the loop and take every later slot with it, silently emptying the plan - which is what the second regression test pins. Overlap rather than an exact start match, so a marker suppresses any window it touches rather than only one beginning on the same minute. Deliberately not added to manual_all_times: that set forces charge and export windows into existence, and this does the opposite. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…hile it is here The battery-priority hold assumes the car can catch up later, which stops being true the moment the afternoon is marked away. With the level at 100% the car never saw a solar window at all: every slot was either withheld for the battery in the morning or suppressed as away in the afternoon, so the plan fell through to buying at the day rate - reported from a live system as "plenty of solar but it doesn't use it". The hold now gives up exactly what the car can still take from the slots it will be present for. That figure is what it needs, capped by what those slots can actually deliver, so the battery keeps everything beyond it - it has the rest of the day, the car does not. Zero when no away time is set, so the everyday behaviour is untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
romain-intel
force-pushed
the
pr/car-solar
branch
from
September 17, 2026 07:37
23e24e8 to
1d253f6
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.