diff --git a/CHANGELOG.md b/CHANGELOG.md index 915c314e..b53feee2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Improving documentation, added "what is this" section and added some infographics. - Added new forecasts methods chapter in documentation. - Added publish of sensors for p_grid_forecast & total value of cost function. +- Implemented now/current value forecast correction when using MPC. ## [0.3.15] - 2022-06-06 ### Fix diff --git a/src/emhass/forecast.py b/src/emhass/forecast.py index edfe7247..e737949f 100644 --- a/src/emhass/forecast.py +++ b/src/emhass/forecast.py @@ -348,7 +348,10 @@ def get_power_from_weather(self, df_weather: pd.DataFrame, P_PV_forecast = mc.results.ac if set_mix_forecast: - P_PV_forecast = forecast.get_mix_forecast(df_now, P_PV_forecast, 0.5, 0.5, 'sensor.power_photovoltaics') + P_PV_forecast = forecast.get_mix_forecast( + df_now, P_PV_forecast, + self.params['passed_data']['alpha'], self.params['passed_data']['beta'], + 'sensor.power_photovoltaics') return P_PV_forecast @@ -532,7 +535,10 @@ def get_load_forecast(self, days_min_load_forecast: Optional[int] = 3, method: O P_Load_forecast = copy.deepcopy(forecast_out['yhat']) if set_mix_forecast: - P_Load_forecast = forecast.get_mix_forecast(df_now, P_Load_forecast, 0.5, 0.5, 'sensor.power_load_no_var_loads') + P_Load_forecast = forecast.get_mix_forecast( + df_now, P_Load_forecast, + self.params['passed_data']['alpha'], self.params['passed_data']['beta'], + 'sensor.power_load_no_var_loads') return P_Load_forecast diff --git a/src/emhass/utils.py b/src/emhass/utils.py index db8c63d1..711f40a4 100644 --- a/src/emhass/utils.py +++ b/src/emhass/utils.py @@ -109,7 +109,7 @@ def treat_runtimeparams(runtimeparams: str, params:str, retrieve_hass_conf: dict params = json.loads(params) else: params = {'passed_data':{'pv_power_forecast':None,'load_power_forecast':None,'load_cost_forecast':None,'prod_price_forecast':None, - 'prediction_horizon':None,'soc_init':None,'soc_final':None,'def_total_hours':None}} + 'prediction_horizon':None,'soc_init':None,'soc_final':None,'def_total_hours':None,'alpha':None,'beta':None}} freq = int(retrieve_hass_conf['freq'].seconds/60.0) delta_forecast = int(optim_conf['delta_forecast'].days) forecast_dates = get_forecast_dates(freq, delta_forecast) @@ -134,6 +134,16 @@ def treat_runtimeparams(runtimeparams: str, params:str, retrieve_hass_conf: dict else: def_total_hours = runtimeparams['def_total_hours'] params['passed_data']['def_total_hours'] = def_total_hours + if 'alpha' not in runtimeparams.keys(): + alpha = 0.5 + else: + alpha = runtimeparams['alpha'] + params['passed_data']['alpha'] = alpha + if 'beta' not in runtimeparams.keys(): + beta = 0.5 + else: + beta = runtimeparams['beta'] + params['passed_data']['beta'] = beta forecast_dates = copy.deepcopy(forecast_dates)[0:prediction_horizon] if 'pv_power_forecast' in runtimeparams.keys(): if type(runtimeparams['pv_power_forecast']) == list and len(runtimeparams['pv_power_forecast']) >= len(forecast_dates): diff --git a/src/emhass/web_server.py b/src/emhass/web_server.py index 61615757..6509dfcf 100644 --- a/src/emhass/web_server.py +++ b/src/emhass/web_server.py @@ -105,7 +105,7 @@ def build_params(params, options, addon): # The params dict params['params_secrets'] = params_secrets params['passed_data'] = {'pv_power_forecast':None,'load_power_forecast':None,'load_cost_forecast':None,'prod_price_forecast':None, - 'prediction_horizon':None,'soc_init':None,'soc_final':None,'def_total_hours':None} + 'prediction_horizon':None,'soc_init':None,'soc_final':None,'def_total_hours':None,'alpha':None,'beta':None} return params @app.route('/') diff --git a/tests/test_forecast.py b/tests/test_forecast.py index fc9e4f80..9595cf68 100644 --- a/tests/test_forecast.py +++ b/tests/test_forecast.py @@ -49,7 +49,7 @@ def setUp(self): self.df_input_data_dayahead = pd.concat([self.P_PV_forecast, self.P_load_forecast], axis=1) self.df_input_data_dayahead.columns = ['P_PV_forecast', 'P_load_forecast'] self.opt = optimization(retrieve_hass_conf, optim_conf, plant_conf, - self.fcst.var_load_cost, self.fcst.var_prod_price, self.days_list, + self.fcst.var_load_cost, self.fcst.var_prod_price, 'profit', root, logger) self.input_data_dict = { 'root': root,