Skip to content

Commit b68c043

Browse files
committed
Added an open_meteo_cache_max_age config option to control Open-Meteo JSON reponse caching
1 parent 9fcd8c1 commit b68c043

5 files changed

Lines changed: 21 additions & 1 deletion

File tree

docs/forecasts.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ curl -i -H 'Content-Type:application/json' -X POST -d {} http://localhost:5000/a
9494
curl -i -H 'Content-Type:application/json' -X POST -d '{"weather_forecast_cache_only":true}' http://localhost:5000/action/naive-mpc-optim
9595
```
9696

97+
#### Caching Open-Meteo Weather Service Usage
98+
99+
When you have EMHASS configured to use the Open-Meteo weather service, to minimize API calls to the service, and to provide
100+
resilience in case of transient connectivity issues, EMHASS caches successful calls to the Open-Meteo API in a
101+
`cached-open-meteo-forecast.json` file in the data directory. The JSON file contains the default 3 days of weather forecast data.
102+
This Open-Meteo cache is independent of the PV cache discussed above and will be used even when the PV cache is not enabled.
103+
By default, when the JSON file is older than 30 minutes, attempts will be made to replace it with a more recent version
104+
from the Open-Meteo weather service. It will only be replaced if this is successful. If any errors occur the older version
105+
will continue to be used until a new version can been fetched. The maximum cache age, with a default value of 30 minutes, can be
106+
configured using the `open_meteo_cache_max_age` setting in config.json or as a parameter in EMHASS REST API calls.
107+
The value is specified in minutes. If you want to disable caching you can specify a value of 0.
108+
97109
#### Adjusting PV Forecasts using machine learning
98110
EMHASS provides methods to adjust the PV power forecast using machine learning regression techniques. The adjustment process consists of two steps: training a regression model using historical PV data and then applying the trained model to correct new PV forecasts.
99111

src/emhass/data/associations.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ optim_conf,battery_dynamic_min,battery_dynamic_min
4646
optim_conf,weight_battery_discharge,weight_battery_discharge
4747
optim_conf,weight_battery_charge,weight_battery_charge
4848
optim_conf,weather_forecast_method,weather_forecast_method
49+
optim_conf,open_meteo_cache_max_age,open_meteo_cache_max_age
4950
optim_conf,def_start_timestep,start_timesteps_of_each_deferrable_load,list_start_timesteps_of_each_deferrable_load
5051
optim_conf,def_end_timestep,end_timesteps_of_each_deferrable_load,list_end_timesteps_of_each_deferrable_load
5152
optim_conf,list_hp_periods,load_peak_hour_periods

src/emhass/data/config_defaults.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
0
4444
],
4545
"weather_forecast_method": "open-meteo",
46+
"open_meteo_cache_max_age": 30,
4647
"load_forecast_method": "naive",
4748
"delta_forecast_daily": 1,
4849
"load_cost_forecast_method": "hp_hc_periods",

src/emhass/forecast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def get_weather_forecast(
335335
method == "open-meteo" or method == "scrapper"
336336
): # The scrapper option is being left here for backward compatibility
337337
if not os.path.isfile(w_forecast_cache_path):
338-
data_raw = self.get_cached_open_meteo_forecast_json()
338+
data_raw = self.get_cached_open_meteo_forecast_json(self.optim_conf["open_meteo_cache_max_age"])
339339
data_15min = pd.DataFrame.from_dict(data_raw["minutely_15"])
340340
data_15min["time"] = pd.to_datetime(data_15min["time"])
341341
data_15min.set_index("time", inplace=True)

src/emhass/static/data/param_definitions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@
150150
],
151151
"default_value": "open-meteo"
152152
},
153+
"open_meteo_cache_max_age": {
154+
"friendly_name": "Open-Meteo Cache Max Age",
155+
"Description": "The maximum age, in minutes, of the cached open-meteo json response, after which a new version will be fetched from Open-Meteo. Defaults to 30.",
156+
"input": "int",
157+
"default_value": 30
158+
},
153159
"maximum_power_from_grid": {
154160
"friendly_name": "Max power from grid",
155161
"Description": "The maximum power that can be supplied by the utility grid in Watts (consumption). Defaults to 9000.",

0 commit comments

Comments
 (0)