evcc icon indicating copy to clipboard operation
evcc copied to clipboard

Tariffs: add temperature type and OpenMeteo

Open daniel309 opened this issue 9 months ago • 29 comments

Update: restricted this PR to the new temperature tariff. The household load profile adjustments based on temperature will be handled separately in PR https://github.com/evcc-io/evcc/pull/28232

TODO

  • [ ] add UI @naltatis
  • [x] move tariff to yaml/jq

--

leaving the full PR description below for history and context of the discussion.

Problem

The evopt energy optimizer uses a household load profile (gt) to predict how much energy the home will consume in each future 15-minute slot. This profile is currently computed as a 30-day historical average — the same flat pattern is repeated regardless of weather conditions.

This is a significant blind spot: heating and cooling loads are strongly temperature-dependent. On a cold winter day, a home with a heat pump or electric heating can consume 30–80% more energy than on a mild day. When the optimizer doesn't know this, it:

  • Under-estimates household demand on cold days → schedules EV charging at times when grid power is actually needed for heating
  • Over-estimates household demand on warm days → unnecessarily avoids cheap/green charging windows
  • Misses opportunities to pre-charge the battery before a cold night when heating demand will spike

Solution

This PR adds two things:

  1. A new open-meteo weather tariff that fetches 10 days of hourly outdoor temperatures from Open-Meteo (free, no API key, no account required) in a single call: 7 days of past actuals + 3 days of forecast. The data is exposed as api.Rates where Rate.Value is the temperature in °C.

  2. Temperature correction of the household load profile in homeProfile(). The historical lookback is reduced from 30 days to 7 days as outdoor temperatures can significantly change within such a long period of time. Household life usually happens within 1 week rhythms so this seemed a better default. Before the profile is passed to the optimizer, each slot's load is adjusted based on how the forecast temperature at that slot deviates from the 7-day historical average at the same hour-of-day:

load[i] = load_avg[i] × (1 + heatingCoefficient × (T_past_avg[h] − T_forecast[i]))

where:

  • T_past_avg[h] = average temperature at hour-of-day h over the past 7 days
  • T_forecast[i] = forecast temperature at the wall-clock time of slot i
  • heatingCoefficient = fractional load sensitivity per °C (default 0.05 = 5%/°C)

The correction is gated on the 24h average actual temperature of the past 24 hours. If that average is at or above heatingThreshold (default 12°C), heating is considered off and no correction is applied to any slot. Using past actuals (not forecast) for the gate is more reliable: if it was cold yesterday, heating is likely still running today.

Example: With default settings (heatingThreshold=12°C, heatingCoefficient=0.05) and a 7-day historical average of 8°C at a given hour:

  • Forecast 8°C → no correction (delta = 0, factor = 1.0)
  • Forecast 3°C → +25% load (delta = +5°C, factor = 1.25)
  • Forecast −2°C → +50% load (delta = +10°C, factor = 1.50)
  • Forecast 13°C → −25% load (delta = −5°C, factor = 0.75)

The correction is relative to the historical average that produced the baseline load, so daily patterns (e.g. higher consumption in the evening) are preserved — only the magnitude is adjusted. This is consistent with standard heating degree-day methodology.

If no weather tariff is configured, applyTemperatureCorrection() is a no-op and behaviour is identical to before.

Files Changed

File Change
tariff/weather.go New — Weather tariff type polling Open-Meteo hourly (past_days=7&forecast_days=3)
api/tariff.go Added TariffTypeWeather and TariffUsageWeather constants
api/globalconfig/types.go Added Weather config.Typed to Tariffs struct
tariff/tariffs.go Added Weather api.Tariff field; Get() handles TariffUsageWeather
cmd/setup.go Wires up weather tariff in configureTariffs()
core/site.go Added HeatingThreshold and HeatingCoefficient config fields
core/site_optimizer.go Reduced lookback to 7 days; homeProfile() calls new applyTemperatureCorrection() and nearestRate() helper

Configuration

The feature is opt-in — no changes needed for existing setups.

To enable, add to evcc.yaml:

tariffs:
  # ... existing tariff config ...
  weather:
    type: open-meteo
    latitude: 48.137   # your location
    longitude: 11.576

site:
  title: My Home
  meters:
    grid: grid0
    pv: pv0
  # Optional tuning (these are the defaults):
  heatingThreshold: 12.0    # °C — 24h avg of past-day temperatures above which all corrections are disabled
  heatingCoefficient: 0.05  # fraction — load changes by this fraction per °C delta from historical average

Tuning guidance

  • heatingThreshold: Set to the 24h average outdoor temperature above which your heating system is fully off. Typical values: 10–15°C depending on building insulation and personal preference. The default of 12°C suits an average insulated house.
  • heatingCoefficient: Represents how sensitive your home's energy consumption is to temperature, as a fraction of the average load per °C. A well-insulated passive house might use 0.02; a poorly insulated older building might use 0.08 or higher. You can estimate it by comparing your historical energy consumption on cold vs. mild days.

Notes

  • Open-Meteo is fetched once per hour with exponential backoff on failure. If the forecast is unavailable, the optimizer falls back to the unmodified historical profile (safe degradation).
  • The correction only applies to future slots in the optimizer horizon — historical data in the database is not modified.
  • Past temperatures (7 days) and future forecast (3 days) are fetched in a single Open-Meteo API call using past_days=7&forecast_days=3&timezone=UTC.
  • The 24h average gate (heatingThreshold) is based on past 24h actual temperatures (not forecast), preventing the correction from running in summer. Using actuals is more reliable: if it was warm yesterday, heating is off today regardless of what the forecast says.
  • This does not model cooling loads (summer A/C). A coolingThreshold / coolingCoefficient could be added similarly in a follow-up.
  • The open-meteo tariff type name follows the existing tariff registry naming convention (provider name, lowercase).

TODO

  • [ ] UI @naltatis
  • [x] remove Go tariff and use jq @daniel309

daniel309 avatar Feb 27 '26 22:02 daniel309

You've hit an actual problem spot-on, but I'm not sure that the solution is the right one, conceptually and technically: you're assuming that household energy depends on heating demand and imply a heatpump- what if you don't have one?

Imho the "right" approach here would be to measure and collect heating demands separately and have a different "heating" optimizer model for those.

/cc @ekkea @t0mas

andig avatar Mar 01 '26 10:03 andig

The weather tariff is a nice touch (really: it's temperature, not weather?) and might be a separate PR on its own that will become useful sooner or later.

andig avatar Mar 01 '26 10:03 andig

you're assuming that household energy depends on heating demand and imply a heatpump- what if you don't have one?

If you dont have a heatpump (or more general, heating that uses electricity), you dont configure/add the heatingCoefficient or heatingThreshold parameters to evcc.yaml (under site).

Imho the "right" approach here would be to measure and collect heating demands separately and have a different "heating" optimizer model for those.

Yes, that would be most clean. It would require the heating meter and a bunch other things (separate optimizer model) likely making config and implementation more complicated. And I am really wondering if all that additional code, effort and complication (to the user) is really worth it.

Assume a single-family home household like ours: when heating (heatpump in our case) is active, daily energy consumption is dominated by that one energy consumer. In numbers:

  • Household consumption (appliances, cooking, lights, ...): 5-9 kwh/day, through the entire year.
  • Car: 5-7 kwh/day (we drive less than 50km/day on avg)
  • Heatpump: 17 kwh/day (mildest day this winter) to 45 kwh (coldest day this winter, Jan 7th 2026 for us)

The weather tariff is a nice touch (really: it's temperature, not weather?) and might be a separate PR on its own that will become useful sooner or later.

Happy to split this out (and rename to temperature) or do it all at once together with the heating code that uses it. Let me know how to proceed.

daniel309 avatar Mar 01 '26 11:03 daniel309

Yes, that would be most clean.

Yes :)

It would require the heating meter

Yes. And we'd need to figure out how meters (not even necessarily) chargers would be handed to the optimizer. Collecting arbitrary metrics is already "almost" done: https://github.com/evcc-io/evcc/pull/23185 (btw, would love help with this PR).

and a bunch other things (separate optimizer model)

That's already in the backlog, examples exist.

likely making config and implementation more complicated.

Happy to discuss how to do this, maybe in separate issue. Or join the #optimizer group on Slack.

andig avatar Mar 01 '26 16:03 andig

hmm, ok, not sure how to proceed.

It sounded like you would like to break this down into re-useable parts, and maybe get some use early to test how well it works now that heating is still on for a few weeks. Otherwise next opportunity is October 2026.

so, I could split this work into 3 pieces:

  1. introduce "temperature" tariff as per above. Unrelated to heating and no users/exploiters (yet). Just to have a clean and separate PR.

  2. then, on top, a second PR that introduces temperature-based correction of the household profile (func (site *Site) applyTemperatureCorrection). This would introduce the new site config params (heatingThreshold, heatingCoefficient), use the temperature tariff and apply it to the general household consumption profile (gt). this would give immediate value to heating users and give early test results, although not perfect as gt profile is mixing up heating with other consumers today.

it would also serve as a testbed for debugging etc.

  1. split out heating consumption (based on https://github.com/evcc-io/evcc/pull/23185), apply the temperature correction only there and use a separate optimizer model/run. this is the "clean" solution above and the desired final state.

does that sound feasible?

(btw. not sure how much time I can dedicate to this, 3. for sure is not a quick change. I do think 1. and 2. are possible relatively short-term though).

daniel309 avatar Mar 02 '26 11:03 daniel309

@andig instead of a separate optimizer, my first thought on this would be to make the household load prediction more similar to how we handle tariffs. That would add flexibility for users to configure it with just the "historic" strategy that we have today, or create a more complex calculation with temperature adjustment factors.

I guess some users would be able to remove the heating energy from their basic prediction (set a different meter?), make a separate time series just for heating, adjust that one based on temperature, and then combine those two time series to generate the input for the optimizer.

If you agree this would be helpful I could probably write that? Then combined with the weather tariff and adjustment strategy that @daniel309 made you have full flexibility. The only thing is... It won't be easy to make a visual UX for configuration of these kinds of structures.

t0mas avatar Mar 02 '26 15:03 t0mas

I guess some users would be able to remove the heating energy from their basic prediction (set a different meter?)

most heatpump "chargers" already provide energy and power, wouldnt that be sufficient to track heating consumption as a separate timeseries?

example: https://github.com/evcc-io/evcc/blob/a4a4f50d6802e71c22f9b985528f2373b956d040/templates/definition/charger/luxtronik.yaml#L262

daniel309 avatar Mar 02 '26 15:03 daniel309

I would really appreciate if we could move this brain storming out or PRs ;)

introduce "temperature" tariff as per above. Unrelated to heating and no users/exploiters (yet). Just to have a clean and separate PR.

Yes, that's absolutely obvious

most heatpump "chargers" already provide energy and power, wouldnt that be sufficient to track heating consumption as a separate timeseries?

Yes, still needs to tracking PR to complete. Who/ when?

split out heating consumption (based on https://github.com/evcc-io/evcc/pull/23185), apply the temperature correction only there and use a separate optimizer model/run. this is the "clean" solution above and the desired final state.

make a separate time series just for heating, adjust that one based on temperature, and then combine those two time series to generate the input for the optimizer.

Yes and yes- but I don't have any good idea how to do that right now (but also didn't try). We've really always tried to not shoot ourselves into the foot and do things properly and in steps.

andig avatar Mar 02 '26 15:03 andig

  1. updated PR description as per latest discussion and removed the temperature adjustment logic.
  2. marked as ready for review
  3. will open discussion to continue the load adjustment topic for eletrical heatings (heatpumps, IR heating, distributed AC heating devices, ...)

update: discussion on temperature adjustment logic: https://github.com/evcc-io/evcc/discussions/27873

daniel309 avatar Mar 02 '26 15:03 daniel309

ok, build is green. can you have another look @andig ?

daniel309 avatar Mar 02 '26 16:03 daniel309

@andig yaml/jq solution ready to merge.

what kind of UI changes you have in mind?

daniel309 avatar Mar 04 '26 13:03 daniel309

@andig I would suggest to split UI changes into separate PR and open a tracking issue (epic) to tie everything together. After all, this is the base work for the temp correction algorithm for temperature-dependent household loads (heating) and ultimately for optimizer to deal properly with those loads.

So the todo list is

  1. weather tariff,
  2. ui changes,
  3. gt: split out heating load
  4. temp-dependent scaling of heating load
  5. gt merge back: combine normal household load and scaled heating load into gt, feed to optimizer

daniel309 avatar Mar 06 '26 08:03 daniel309

@andig @ekkea @t0mas I worked on the full implementation on my fork as a PR just to feel out the changes. Doesnt look too bad or complicated.

see: https://github.com/daniel309/evcc/pull/1

daniel309 avatar Mar 11 '26 21:03 daniel309

@andig @ekkea @t0mas I worked on the full implementation just to feel out the changes and test how it works.

https://github.com/evcc-io/evcc/pull/28232

I am testing with a build from this branch and for the first time, optimizer now creates good estimates for household consumption including the heating.

I am continuing to test, but I feel this is close to ready now.

btw. PR https://github.com/evcc-io/evcc/pull/28232 looks heavy, but it is based on the temp tariff. once this is merged it will be less than 200 lines across 3 files.

daniel309 avatar Mar 15 '26 09:03 daniel309

Was it planned that the temperature-forecast could be optionally calibrated using a real temperature sensor (e.g., one that is read into evcc via Modbus TCP from the heating control system), similar to how PV production forecasts are handled (for now, as an experimental feature)?

florian240483 avatar Mar 20 '26 10:03 florian240483

Was it planned that the temperature-forecast could be optionally calibrated using a real temperature sensor (e.g., one that is read into evcc via Modbus TCP from the heating control system), similar to how PV production forecasts are handled (for now, as an experimental feature)?

no, I didnt plan that. The open meteo data has pretty accurate (for my case at least) past temperature readings.

If this is not accurate for your case, this could be a nice follow-on PR.

daniel309 avatar Mar 20 '26 10:03 daniel309

@naltatis would we want to merge this even if not actively used yet just to collect metrics? Then we'd need a UI here ;)

andig avatar May 24 '26 21:05 andig

I addressed the review comments from @andig. Any chance @naltatis you could have a look at the UI side of this? Not sure if much work needed, I am assuming the existing visualizations for forecasts can be (mostly) used as is?

daniel309 avatar Jun 19 '26 13:06 daniel309

@daniel309 yes, I’ll look into this.

naltatis avatar Jun 20 '26 07:06 naltatis

Update: history integration for outdoor temperature

Upstream commit b8284ab (Metrics: add soc and temp, #30926) introduced soc_temp and is_temp DB columns to the metrics schema. This update wires our temperature tariff into those fields so outdoor temperature is now recorded in the history database alongside energy data.

What I just changed (4 files, ~15 lines):

core/metrics/collector.go — added Temperature = "temperature" group constant core/metrics/db_history.go — appended temperature to GroupOrder for correct history export ordering core/site.go — registers a dedicated temperature collector entity on startup (always created, inactive when no temperature tariff is configured) core/site_tariffs.go — each 15-minute slot, if a temperature tariff is active and returns a valid reading, writes the current °C value into soc_temp with is_temp=true

Result: when open-meteo-temperature is configured, the history view and CSV export gain a temperature.temperature.temp.degC column, giving a per-slot record of outdoor temperature alongside energy consumption

@andig @naltatis ^^

daniel309 avatar Jun 28 '26 12:06 daniel309