Skip to content

Charge car on solar excess - #4683

Open
romain-intel wants to merge 2 commits into
springfall2008:mainfrom
romain-intel:pr/car-solar
Open

Charge car on solar excess#4683
romain-intel wants to merge 2 commits into
springfall2008:mainfrom
romain-intel:pr/car-solar

Conversation

@romain-intel

Copy link
Copy Markdown
Contributor

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.

romain-intel and others added 2 commits August 24, 2026 21:29
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)
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.

1 participant