I’m struggling to get the machine learning forecaster to work.
Can someone give me some advice?
My addon config
hass_url: empty
long_lived_token: empty
costfun: profit
logging_level: INFO
optimization_time_step: 30
historic_days_to_retrieve: 6
method_ts_round: nearest
set_total_pv_sell: false
lp_solver: COIN_CMD
lp_solver_path: /usr/bin/cbc
set_nocharge_from_grid: false
set_nodischarge_to_grid: false
set_battery_dynamic: false
battery_dynamic_max: 0.9
battery_dynamic_min: -0.9
load_forecast_method: naive
sensor_power_photovoltaics: sensor.huidige_opbrengst
sensor_power_load_no_var_loads: sensor.huidig_verbruik_zonder_wp
number_of_deferrable_loads: 4
list_nominal_power_of_deferrable_loads:
- nominal_power_of_deferrable_loads: 2000
- nominal_power_of_deferrable_loads: 2000
- nominal_power_of_deferrable_loads: 1700
- nominal_power_of_deferrable_loads: 1100
list_operating_hours_of_each_deferrable_load:
- operating_hours_of_each_deferrable_load: 2
- operating_hours_of_each_deferrable_load: 2
- operating_hours_of_each_deferrable_load: 2.5
- operating_hours_of_each_deferrable_load: 1
list_peak_hours_periods_start_hours:
- peak_hours_periods_start_hours: "12:00"
list_peak_hours_periods_end_hours:
- peak_hours_periods_end_hours: "17:24"
list_treat_deferrable_load_as_semi_cont:
- treat_deferrable_load_as_semi_cont: false
- treat_deferrable_load_as_semi_cont: false
- treat_deferrable_load_as_semi_cont: false
- treat_deferrable_load_as_semi_cont: false
load_peak_hours_cost: 0.1784
load_offpeak_hours_cost: 0.1684
photovoltaic_production_sell_price: 0
maximum_power_from_grid: 14000
list_pv_module_model:
- pv_module_model: CSUN_Eurasia_Energy_Systems_Industry_and_Trade_CSUN295_60M
list_pv_inverter_model:
- pv_inverter_model: Fronius_International_GmbH__Fronius_Primo_5_0_1_208_240__240V_
list_surface_tilt:
- surface_tilt: 30
list_surface_azimuth:
- surface_azimuth: 205
list_modules_per_string:
- modules_per_string: 16
list_strings_per_inverter:
- strings_per_inverter: 1
set_use_battery: false
battery_discharge_power_max: 1000
battery_charge_power_max: 1000
battery_discharge_efficiency: 0.95
battery_charge_efficiency: 0.95
battery_nominal_energy_capacity: 5000
battery_minimum_state_of_charge: 0.3
battery_maximum_state_of_charge: 0.9
battery_target_state_of_charge: 0.6
method: solcast
And this are my shell commands
forecast_model_fit_load_zonder_wp: >-
curl -i -H 'Content-Type: application/json' -X POST -d '{
"days_to_retrieve": 15,
"model_type": "load_zonder_wp_forecast",
"var_model": "sensor.huidig_verbruik_zonder_wp",
"sklearn_model": "KNeighborsRegressor",
"num_lags": 48,
"split_date_delta": "48h",
"perform_backtest": "True"
}' http://localhost:5001/action/forecast-model-fit
forecast_model_predict_load_zonder_wp: >-
curl -i -H 'Content-Type: application/json' -X POST -d '{
"model_type": "load_zonder_wp_forecast",
"model_predict_publish": "True",
"model_predict_entity_id": "sensor.p_load_zonder_wp_custom_model",
"model_predict_unit_of_measurement": "W",
"model_predict_friendly_name": "Warmtepompboiler custom model"
}' http://localhost:5001/action/forecast-model-predict
When I do the first in a terminal this file is created load_zonder_wp_forecast_mlf.pkl
When I do the second
❯ curl -i -H 'Content-Type: application/json' -X POST -d '{
"model_type": "load_zonder_wp_forecast",
"model_predict_publish": "True",
"model_predict_entity_id": "sensor.p_load_zonder_wp_custom_model",
"model_predict_unit_of_measurement": "W",
"model_predict_friendly_name": "Warmtepompboiler custom model"
}' http://192.168.79.54:5001/action/forecast-model-predict
HTTP/1.1 500 INTERNAL SERVER ERROR
Content-Length: 265
Content-Type: text/html; charset=utf-8
Date: Wed, 07 Jun 2023 22:49:59 GMT
Server: waitress
<!doctype html>
<html lang=en>
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>
And this are the logs for the addon
2023-06-08 00:49:31,692 - web_server - INFO - Performing a forecast model fit for load_zonder_wp_forecast
2023-06-08 00:49:31,701 - web_server - INFO - Training a KNeighborsRegressor model
2023-06-08 00:49:31,818 - web_server - INFO - Elapsed time for model fit: 0.11742901802062988
2023-06-08 00:49:31,930 - web_server - INFO - Prediction R2 score of fitted model on test data: -0.09174206116291761
2023-06-08 00:49:31,933 - web_server - INFO - Performing simple backtesting of fitted model
0%| | 0/13 [00:00<?, ?it/s]
15%|█▌ | 2/13 [00:00<00:00, 19.13it/s]
31%|███ | 4/13 [00:00<00:00, 19.06it/s]
46%|████▌ | 6/13 [00:00<00:00, 18.76it/s]
62%|██████▏ | 8/13 [00:00<00:00, 18.88it/s]
77%|███████▋ | 10/13 [00:00<00:00, 18.84it/s]
92%|█████████▏| 12/13 [00:00<00:00, 19.07it/s]
100%|██████████| 13/13 [00:00<00:00, 20.34it/s]
2023-06-08 00:49:32,577 - web_server - INFO - Elapsed backtesting time: 0.6434693336486816
2023-06-08 00:49:32,577 - web_server - INFO - Backtest R2 score: 0.1965843955066804
2023-06-08 00:49:59,873 - web_server - INFO - Setting up needed data
2023-06-08 00:49:59,880 - web_server - INFO - Retrieve hass get data method initiated...
2023-06-08 00:49:59,907 - web_server - ERROR - The retrieved JSON is empty, check that correct day or variable names are passed
2023-06-08 00:49:59,908 - web_server - ERROR - Either the names of the passed variables are not correct or days_to_retrieve is larger than the recorded history of your sensor (check your recorder settings)
2023-06-08 00:49:59,908 - web_server - ERROR - Exception on /action/forecast-model-predict [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/usr/local/lib/python3.9/dist-packages/emhass/web_server.py", line 174, in action_call
input_data_dict = set_input_data_dict(config_path, str(data_path), costfun,
File "/usr/local/lib/python3.9/dist-packages/emhass/command_line.py", line 146, in set_input_data_dict
rh.get_data(days_list, var_list)
File "/usr/local/lib/python3.9/dist-packages/emhass/retrieve_hass.py", line 147, in get_data
self.df_final = pd.concat([self.df_final, df_day], axis=0)
UnboundLocalError: local variable 'df_day' referenced before assignment
In recorder.yaml
I have purge_keep_days: 15
When I use the buttons in the webui I get the same errors in the log.