You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prefer early charging if economics are similar #163
One potential enhancement I see is that the optimizer seems to favor later charging over earlier charging when price differences are very small (for example, below €0.5 ct/kWh). Especially for home batteries, I would often prefer earlier charging in such situations.The reason is that a PV forecast is inherently uncertain. By postponing charging, there is a risk that the battery ends up not fully charged, even though there was an earlier opportunity to do so at nearly the same cost. The consequence can be additional grid imports later, which are typically far more expensive than the small price advantage gained by delaying charging.I realize this is not a simple optimization problem. It involves forecast uncertainty, risk tolerance, and the trade-off between expected savings and the cost of a missed charging opportunity.
The optimal strategy will likely differ between use cases, which may make sense as a user-configurable "risk appetite" setting. Some users may prefer the lowest expected cost, while others may prefer a more conservative strategy that prioritizes charge certainty when cost differences are negligible.
Not sure if it fits here but there's also the issue of charging the car sooner than later while home battery could still be filled later. This is preferred since the car might leave and the home battery not be able to absorb remaining energy. Maybe this is like a "risk of avoidable surplus" that might have a value here?
I'd separate two things that the "risk appetite" framing merges. The optimizer currently minimizes cost along a single forecast path, so it evaluates cost at the mean instead of taking the mean of the cost. The optimizer cost is convex in PV output, short of forecast you import, over it you export at a fraction of the price, so a point forecast handed to the optimizer understates the cost of waiting. Even a purely risk-neutral agent, given a distribution rather than a path, would prefer earlier charging at small spreads. Risk aversion is the separate question of paying more on average to avoid very expensive days; a purely rational user should not want this as it means less money in their pocket at the end of the year.
That suggests making optimizer aware of forecast probabilities before one took the further step of factoring in a user’s risk preferences: let the request carry weighted scenarios (forecast 80%, 120% of forecast; passing along historical probability of vehicle availability), solve them jointly with the first interval shared, execute it and replan next cycle. A single scenario at p=1 for forecast accuracy and vehicle ability is today's behaviour.
Happy to sketch the formulation if there's appetite for going that route.
tldr: once you factor in forecast uncertainty, economics will generally favor earlier charging without any hard coding, we should do this...
Aside: backup-capable house batteries have a dual payoff from maintaining a higher SOC: backup service. Separate issue / mechanism, but may motivate the OPs gut sense that earlier higher SOCs are better.
A relatively simple solution would be to work with a pessimistic scenario for PV. This could be a setting, or (more impactful) derived from historic predictions compared to the actual energy generated. That still doesn’t answer the question on how certain you want to be that the battery is fully charged, and at what price that may be. I think this can be mathematically determined, but not sure how.
A relatively simple solution would be to work with a pessimistic scenario for PV
I don’t think so. Optimizer will work with variable tariff just as well, no PV required. This also wouldn’t help with early charging. Maybe we need to separate the two topics.
Let's see if I can separate the several use cases you see:
Given dynamic prices and given that feeding into the grid is most often way less beneficial than taking energy from the grid:
I want the battery to charge early to prevent late charging because of curtailing;
I want the car to charge early so that unforeseen absence doesn't have a major influence;
I want both the car and the battery to charge early to overcome negative differences in the actual solar energy production compared to the forecasted production (timing and/of total production).
I think the common thread in all use cases is that assumptions the optimizer makes are not 'right enough' for a series of edge cases. E.g. optimizer assumes that solar forecast is a guarantee, rather than a probabilistic estimate; optimizer has no concept that a car may be disconnected after it's plugged in; the third being the juxtaposition of the prior two.
Proposed solution: use probability weighted scenarios which specify a range of plausible PV yields. Let's say the scenario as-is gets a weight of 80% and the max and min PV yield scenarios are each weighted 10%.
Internally the time-indexed variables are replicated per scenario, all scenarios are constrained to share the decision for the current step, and the objective becomes the probability-weighted sum of the per-scenario objectives.
A first step in this direction would be entirely on the optimizer side, take the solar forecast and generate a 70% and 130% yield scenarios. Then, as a second step, this range could be calculated from the observed error between forecast and actual PV yield. A more elaborate version later on would use the currently discarded forecast bands (max / min PV yield) services like pvnode provide.
The same mechanism extends to charging availability, separately.
I'll post a branch with the concrete changes necessary (plus a technical tweak vis a vis a penalty term) later tonight.
Ok, tried out a few ideas (see linked branch), one thing is clear...adding more probabilistic information (via a crude approach) increases running time without relevant performance gains.
More sophisticated solutions are definitely out there, but my gut sense is that we start eking out additional <2-5% efficiency for a lot of work and complexity. If forecast was so off such that a forecast adjustment changes optimizer behavior, then optimizer would be giving poor results already. But it mostly works, incredibly well at that.
Where I do see space for meaningful gains is car charging availability…at the moment it assumes once car is plugged in, it will stay plugged in, if car unplugged it won’t be plugged back in. But we have charging data that should let us, analogous to the house electrical load heuristics, calculate whether car is likely to be plugged in or unplugged during a given window.
Hi, I think this discussion is generally important, as it addresses a main weakness of the optimizer: An imprecise forecast.
By nature there will always be differences to the forecast, the question is how we can control the system in a way, that these differences do not lead to stupid decisions.
I see two things that already cover this (mostly).
#131 which addresses the information if a car will be there later. With this information we can fix that optimizer is planning to charge the car later in a time, when it is not connected anymore.
#162 which let's us define priorities (fill home battery first, car A second, car B third)
And generally we already have the optimizer strategy "fill battery first" which prioritizes battery filling first, before we export to grid.
This however only comes into play if it doesn't matter economically, if I charge battery first or I export to grid first. However it should fix the issue where the forecast is too optimistic, because if I fill the batteries first, the only thing I "lose" is that less energy is exported to grid - which is what we want in this scenario, right?
We are going to a lot of effort to create an 'automatic' mode, and yet we are now introducing a somewhat extensive manual configuration, car presence / absence, which may a) may need to be manually adjusted over time; b) for which we already have decent historical data for inferring the same thing.
Forecasts are by their nature imprecise and many forecasts output a range of likely outcomes. The optimizer should on average deliver the best outcome across this range (assuming the forecast is imprecise but on average calibrated). At the moment we 'throw away' information we could be using to improve average performance.
It does matter economically exactly when we charge the battery. Depending on your feed-in rules, you may be constrained in max feed-in power (kW), the battery timing ensures electricity isn't thrown away.
Hi, I think this discussion is generally important, as it addresses a main weakness of the optimizer: An imprecise forecast.
And: uncertainty about the vehicle remaining connected. The home battery always is.
I see two things that already cover this (mostly).
#131 which addresses the information if a car will be there later. With this information we can fix that optimizer is planning to charge the car later in a time, when it is not connected anymore.
It doesn't imho. It only addresses the "will for sure not be there" case.
#162 which let's us define priorities (fill home battery first, car A second, car B third)
Also think that's not the right thing to do. The whole point of the optimizer is automatic economics. Putting vehicle before home battery on a fixed priority is imho contradictory.
Wait, you’re looking for some kind of optimizer log here? How do I get those out of either the optimizer logs or the evcc logs? Because until now I couldn’t find meaningful logs to show what happened here.
I want to contribute some datapoints to this discussion.
Motivation: My experience having the optimizer on "full" for two weeks now is that its results are "intuitive" when there is a clear economically superior plan. Things get "unintutive" whenever there is a large number of economically equivalent plans (within the 2ct solver gap). I have argued before that "intuitive plans" are important for user experience: trusting the optimizer to control loadpoints and batteries. Technically, having many economically equivalent plans is good (ie. the house has more options), but practically seeing the the solver flip/flop around between charging the car tomorrow vs today on the tinies change in inputs is undermining my trust.
Here's a quick example of "equivalent" plans flipping car charges:
Take one kWh of PV surplus today and one tomorrow. Plan A stores today's kWh in the car and exports tomorrow's. Plan B exports today's and stores tomorrow's. Both end with the same car, the same losses (eta 0.9 for every battery) and the same export revenue, because the feed-in price is flat at 7.54 ct/kWh. To the objective, A and B cost exactly the same.
I had expected that the preference tie-breakers would "stabilize" plan selection from the two "efficient plateaus" (charging today or tomorrow) but in the current production version they don't.
I record all optimizer requests in my house so I can replay them and had claude create a backtest of different solutions discussed in here. You can look at the in the attached zip, which contains 23 solver requests picked over a real day as forecasts and actual consumptions evolved + an interactive data explorer. For the backtest I also synthesized 13 "variations" of the request with small modifications to inputs to judge how "stable" plan outcomes are (so I ran 299 solves for each method)
My main findings and interpretation
todays model shows a lot of "flapping" between equivalent plans with very different control inputs to evcc
feat: r_departure, the chance a device leaves per time step #184 departure risk modelling produces the most stable plans (my car did actually depart that day), but it has a few anomalies because it seems to not consider that the car will eventually return for charge
A new strategy I came up with called a "holding value" which assigns a value to stored energy. The idea is that stored energy is an insurance against forecast and demand uncertainty. It uses a different method as the charge_before_export perference, which in my dataset doesn't "bite".
I think then main question we‘re struggling with is exactly how we‘d model the preferred intuitive strategy in mathematical terms of the optimizer without breaking the economic preferences. Any actually implemented and tested or implementable idea is welcome. „Should be modeled“ is unfortunately not an idea.
I think we should gather some scenarios first to understand where this is an issue right now. For me it's still quite theoretical at the moment.
The creator wrote:
The consequence can be additional grid imports later, which are typically far more expensive than the small price advantage gained by delaying charging
This could be solved already with "charge battery first" strategy right? And if we'd prioritized the house-battery over the car battery (isn't this already the case?) we make sure that the "uncertainty" of the solar only affects the car charging. So at the end of the day we don't lose any money.
Maybe I don't see the scenario right now.
Theoretically we could run a second model with X% (depending on risk appetite) of the solar forecast and then analyze which behavior is financially most successful with both scenarios.
@andig so i take it you're open to new ideas in this space? I'm happy to do some further exploration of the "holding value" idea and open a draft PR with it then.
Based on my early testing it has some nice properties but coming up with the holding value is the crux. I have some ideas around this that I'm going to explore:
some concepts of portfolio theory (corellation in forecast/demand errors) and black-scholes option pricing are applicable. Returns are also not symmetric, i.e. in my backtesting a few outlier days with grid charging eat up any economic benefit of tightly optimizing for feed-in (this is intuitive of course when feed-in price << grid price)
car departure risk is a sensible input for a "per battery holding value", i.e. the cars holding value increases with increased departure risk
Do you have a pool of longitudinal data, i.e. evcc metrics + snapshots of historic forecasts per house over time? I had to build mine with a combination of evcc + HA data. Building such an open dataset helps backtesting optimizer strategies. I'd be happy to donate some data to the pool.
30. This could be solved already with "charge battery first" strategy right? And if we'd prioritized the house-battery over the car battery (isn't this already the case?) we make sure that the "uncertainty" of the solar only affects the car charging. So at the end of the day we don't lose any money.
My understanding is that there is no priorization between home and car battery. Especially without #99 they are economically equivalent to the optimizer. The analysis I posted above (see the zip) explores this phenomenon in detail. The "charge battery first" strategy doesn't solve this.
There are proposals for using probabilistic assumptions for car charging. I think this is not right. Probabilistic assumptions are fine for small variations as they will statistically even out (e.g. washing machine, toaster, etc.). For a huge consumption like charging a car that does not work. It will produce extremely wrong results a lot of times with correspondingly negative consequences.
In my view, for a car (or similar large consumer) the only "safe" solution for most users is that the user defines when the car is available at the charger or defines a certain electricity demand at a period of time (e.g. for charging). This can then be used by the optimiser with confidence. If the user then does not plug in the car as defined, then it is also clear who is to blame for inefficient results: the user.
I am actively using the optimiser and I am generally very happy. I only use it for the house battery (also for the reasons given above). I would be happy to tell the optimiser when I need a significant amount of electricity (e.g. for car charging). See also #279
Generally, my strategy is to treat the car as a flexible load. The optimiser should ensure that the battery can cover periods of high prices and power the home as efficiently as possible. If there is a surplus expected (which I can easily see in evcc), I will then plug in the car if it is at home and flexibly use the surplus. If that is not enough to charge the car for the next day, I will then charge the car at night at the cheapest rate available.
I think the optimiser has no chance as it does not know when the car is available, how much I drive and how much I will have to charge. Only in a very predictable setting (always leave at 8:00, come back at 17:00 and drive 45 km daily) a full automation would really work.
Can't vouch for the previous post in entirety (haven't made my way through it in detail), but the 'optimality' point isn't wrong...optimizer-level "Optimal" only means optimal given the imperfect forecast available at that 15-minute step, not optimal against what actually happened; if a hedge pulls away from forecast inaccuracy then it can yield savings...
@andig exactly what @jeremiahpslewis said. The perfect plan is the optimiser solution from replacing forecast data with actual pv, tariff and consumption data, ie. as having perfect foresight.
Activity
andig commentedon Sep 20, 2026
@ekkea any idea how we would do this? It seems early charging is better than late and would have economic value in this case?
andig commentedon Sep 20, 2026
Not sure if it fits here but there's also the issue of charging the car sooner than later while home battery could still be filled later. This is preferred since the car might leave and the home battery not be able to absorb remaining energy. Maybe this is like a "risk of avoidable surplus" that might have a value here?
jeremiahpslewis commentedon Sep 20, 2026
I'd separate two things that the "risk appetite" framing merges. The optimizer currently minimizes cost along a single forecast path, so it evaluates cost at the mean instead of taking the mean of the cost. The optimizer cost is convex in PV output, short of forecast you import, over it you export at a fraction of the price, so a point forecast handed to the optimizer understates the cost of waiting. Even a purely risk-neutral agent, given a distribution rather than a path, would prefer earlier charging at small spreads. Risk aversion is the separate question of paying more on average to avoid very expensive days; a purely rational user should not want this as it means less money in their pocket at the end of the year.
That suggests making optimizer aware of forecast probabilities before one took the further step of factoring in a user’s risk preferences: let the request carry weighted scenarios (forecast 80%, 120% of forecast; passing along historical probability of vehicle availability), solve them jointly with the first interval shared, execute it and replan next cycle. A single scenario at p=1 for forecast accuracy and vehicle ability is today's behaviour.
Happy to sketch the formulation if there's appetite for going that route.
tldr: once you factor in forecast uncertainty, economics will generally favor earlier charging without any hard coding, we should do this...
Aside: backup-capable house batteries have a dual payoff from maintaining a higher SOC: backup service. Separate issue / mechanism, but may motivate the OPs gut sense that earlier higher SOCs are better.
andig commentedon Sep 20, 2026
It is what?
This is what's stated above.
This is what's asked above:
krispek commentedon Sep 20, 2026
A relatively simple solution would be to work with a pessimistic scenario for PV. This could be a setting, or (more impactful) derived from historic predictions compared to the actual energy generated. That still doesn’t answer the question on how certain you want to be that the battery is fully charged, and at what price that may be. I think this can be mathematically determined, but not sure how.
andig commentedon Sep 20, 2026
I don’t think so. Optimizer will work with variable tariff just as well, no PV required. This also wouldn’t help with early charging. Maybe we need to separate the two topics.
krispek commentedon Sep 20, 2026
Let's see if I can separate the several use cases you see:
Given dynamic prices and given that feeding into the grid is most often way less beneficial than taking energy from the grid:
Am I right on this?
jeremiahpslewis commentedon Sep 20, 2026
I think the common thread in all use cases is that assumptions the optimizer makes are not 'right enough' for a series of edge cases. E.g. optimizer assumes that solar forecast is a guarantee, rather than a probabilistic estimate; optimizer has no concept that a car may be disconnected after it's plugged in; the third being the juxtaposition of the prior two.
Proposed solution: use probability weighted scenarios which specify a range of plausible PV yields. Let's say the scenario as-is gets a weight of 80% and the max and min PV yield scenarios are each weighted 10%.
Internally the time-indexed variables are replicated per scenario, all scenarios are constrained to share the decision for the current step, and the objective becomes the probability-weighted sum of the per-scenario objectives.
A first step in this direction would be entirely on the optimizer side, take the solar forecast and generate a 70% and 130% yield scenarios. Then, as a second step, this range could be calculated from the observed error between forecast and actual PV yield. A more elaborate version later on would use the currently discarded forecast bands (max / min PV yield) services like pvnode provide.
The same mechanism extends to charging availability, separately.
I'll post a branch with the concrete changes necessary (plus a technical tweak vis a vis a penalty term) later tonight.
fix: model the downside only, and correct three scenario defects (evc…
docs: note the mean the two scenario scheme plans against (evcc-io#163)
jeremiahpslewis commentedon Sep 20, 2026
Ok, tried out a few ideas (see linked branch), one thing is clear...adding more probabilistic information (via a crude approach) increases running time without relevant performance gains.
More sophisticated solutions are definitely out there, but my gut sense is that we start eking out additional <2-5% efficiency for a lot of work and complexity. If forecast was so off such that a forecast adjustment changes optimizer behavior, then optimizer would be giving poor results already. But it mostly works, incredibly well at that.
Where I do see space for meaningful gains is car charging availability…at the moment it assumes once car is plugged in, it will stay plugged in, if car unplugged it won’t be plugged back in. But we have charging data that should let us, analogous to the house electrical load heuristics, calculate whether car is likely to be plugged in or unplugged during a given window.
ScumbagSteve commentedon Sep 26, 2026
Hi, I think this discussion is generally important, as it addresses a main weakness of the optimizer: An imprecise forecast.
By nature there will always be differences to the forecast, the question is how we can control the system in a way, that these differences do not lead to stupid decisions.
I see two things that already cover this (mostly).
#131 which addresses the information if a car will be there later. With this information we can fix that optimizer is planning to charge the car later in a time, when it is not connected anymore.
#162 which let's us define priorities (fill home battery first, car A second, car B third)
And generally we already have the optimizer strategy "fill battery first" which prioritizes battery filling first, before we export to grid.
This however only comes into play if it doesn't matter economically, if I charge battery first or I export to grid first. However it should fix the issue where the forecast is too optimistic, because if I fill the batteries first, the only thing I "lose" is that less energy is exported to grid - which is what we want in this scenario, right?
jeremiahpslewis commentedon Sep 27, 2026
Three thoughts:
andig commentedon Sep 27, 2026
And: uncertainty about the vehicle remaining connected. The home battery always is.
It doesn't imho. It only addresses the "will for sure not be there" case.
Also think that's not the right thing to do. The whole point of the optimizer is automatic economics. Putting vehicle before home battery on a fixed priority is imho contradictory.
None of these fix this issue in a satisfying way.
krispek commentedon Sep 27, 2026
3 remaining items
andig commentedon Sep 30, 2026
@krispek I'm closing any image-only posts without further notice. Without the actual optimizer request to analyze they're useless.
krispek commentedon Sep 30, 2026
Wait, you’re looking for some kind of optimizer log here? How do I get those out of either the optimizer logs or the evcc logs? Because until now I couldn’t find meaningful logs to show what happened here.
ScumbagSteve commentedon Sep 30, 2026
Under the "optimizer" page there is a request and a response.
This is what is sent to optimizer, and what optimizer answered to this.
With the request everyone gets the same response, so this builds the "log" for investigating where the behavior comes from.
krispek commentedon Sep 30, 2026
Check. Those are for the future, so I don’t have them for this situation. Next time I foresee this, I’ll post it.
feat: value the state of charge the device is expected to leave with (c…
JohannesRudolph commentedon Nov 3, 2026
I want to contribute some datapoints to this discussion.
Motivation: My experience having the optimizer on "full" for two weeks now is that its results are "intuitive" when there is a clear economically superior plan. Things get "unintutive" whenever there is a large number of economically equivalent plans (within the 2ct solver gap). I have argued before that "intuitive plans" are important for user experience: trusting the optimizer to control loadpoints and batteries. Technically, having many economically equivalent plans is good (ie. the house has more options), but practically seeing the the solver flip/flop around between charging the car tomorrow vs today on the tinies change in inputs is undermining my trust.
Here's a quick example of "equivalent" plans flipping car charges:
I had expected that the preference tie-breakers would "stabilize" plan selection from the two "efficient plateaus" (charging today or tomorrow) but in the current production version they don't.
I record all optimizer requests in my house so I can replay them and had claude create a backtest of different solutions discussed in here. You can look at the in the attached zip, which contains 23 solver requests picked over a real day as forecasts and actual consumptions evolved + an interactive data explorer. For the backtest I also synthesized 13 "variations" of the request with small modifications to inputs to judge how "stable" plan outcomes are (so I ran 299 solves for each method)
My main findings and interpretation
charge_before_exportperference, which in my dataset doesn't "bite".Charge Today or Tomorrow.zip
I'd be curious what you guys think in terms of conclusions we can draw from this and if the "holding value" idea should be explored further.
andig commentedon Nov 4, 2026
I think then main question we‘re struggling with is exactly how we‘d model the preferred intuitive strategy in mathematical terms of the optimizer without breaking the economic preferences. Any actually implemented and tested or implementable idea is welcome. „Should be modeled“ is unfortunately not an idea.
ScumbagSteve commentedon Nov 4, 2026
I think we should gather some scenarios first to understand where this is an issue right now. For me it's still quite theoretical at the moment.
The creator wrote:
This could be solved already with "charge battery first" strategy right? And if we'd prioritized the house-battery over the car battery (isn't this already the case?) we make sure that the "uncertainty" of the solar only affects the car charging. So at the end of the day we don't lose any money.
Maybe I don't see the scenario right now.
Theoretically we could run a second model with X% (depending on risk appetite) of the solar forecast and then analyze which behavior is financially most successful with both scenarios.
JohannesRudolph commentedon Nov 4, 2026
@andig so i take it you're open to new ideas in this space? I'm happy to do some further exploration of the "holding value" idea and open a draft PR with it then.
Based on my early testing it has some nice properties but coming up with the holding value is the crux. I have some ideas around this that I'm going to explore:
Do you have a pool of longitudinal data, i.e. evcc metrics + snapshots of historic forecasts per house over time? I had to build mine with a combination of evcc + HA data. Building such an open dataset helps backtesting optimizer strategies. I'd be happy to donate some data to the pool.
JohannesRudolph commentedon Nov 4, 2026
My understanding is that there is no priorization between home and car battery. Especially without #99 they are economically equivalent to the optimizer. The analysis I posted above (see the zip) explores this phenomenon in detail. The "charge battery first" strategy doesn't solve this.
ansgarherkert commentedon Nov 6, 2026
There are proposals for using probabilistic assumptions for car charging. I think this is not right. Probabilistic assumptions are fine for small variations as they will statistically even out (e.g. washing machine, toaster, etc.). For a huge consumption like charging a car that does not work. It will produce extremely wrong results a lot of times with correspondingly negative consequences.
In my view, for a car (or similar large consumer) the only "safe" solution for most users is that the user defines when the car is available at the charger or defines a certain electricity demand at a period of time (e.g. for charging). This can then be used by the optimiser with confidence. If the user then does not plug in the car as defined, then it is also clear who is to blame for inefficient results: the user.
I am actively using the optimiser and I am generally very happy. I only use it for the house battery (also for the reasons given above). I would be happy to tell the optimiser when I need a significant amount of electricity (e.g. for car charging). See also #279
Generally, my strategy is to treat the car as a flexible load. The optimiser should ensure that the battery can cover periods of high prices and power the home as efficiently as possible. If there is a surplus expected (which I can easily see in evcc), I will then plug in the car if it is at home and flexibly use the surplus. If that is not enough to charge the car for the next day, I will then charge the car at night at the cheapest rate available.
I think the optimiser has no chance as it does not know when the car is available, how much I drive and how much I will have to charge. Only in a very predictable setting (always leave at 8:00, come back at 17:00 and drive 45 km daily) a full automation would really work.
JohannesRudolph commentedon Nov 14, 2026
andig commentedon Nov 14, 2026
How would it do that if todays plan is already proven optimal? Sorry, sounds like AI garbage.
jeremiahpslewis commentedon Nov 14, 2026
Can't vouch for the previous post in entirety (haven't made my way through it in detail), but the 'optimality' point isn't wrong...optimizer-level "Optimal" only means optimal given the imperfect forecast available at that 15-minute step, not optimal against what actually happened; if a hedge pulls away from forecast inaccuracy then it can yield savings...
JohannesRudolph commentedon Nov 14, 2026
@andig exactly what @jeremiahpslewis said. The perfect plan is the optimiser solution from replacing forecast data with actual pv, tariff and consumption data, ie. as having perfect foresight.