EMHASS add-on: An energy management optimization add-on for Home Assistant OS and supervised

I don’t think I have direct access to the config_emhass.yaml through the add-on (or at least I don’t know how to retrieve it), anyway this is my configuration (as I was experiencing troubles I let it to defaults and just changed the PV and load sensors; I wanted to see it running first and then make the changes little by little).
Thanks







What I can add, if useful, is that the add-on seems not to crash during the execution (I disabled the watchdog and after the execution of the command it is still running).
But right after I get the Empty reply message in the Terminal, if I try to reload the UI this is unavailable. It works again some moments later (but still the data container is recognized as empty).

Just click the three dots at the top and select “Edit in YAML”
image

you have two sensors configured. sensor.production_pv_w and sensor.consumption_w.
If you enter these two sensors, one at a time, into the “Filter entities” field under STATES in the Developer Tools screen what is displayed?

The sensor I have configured for the first (sensor_power_photovoltaics: sensor.sonnenbatterie_XXXXX_production_w) shows 0 because there is no PV production at present:


Do you get something similar?

And for the second I have sensor_power_load_no_var_loads: sensor.house_power_consumption_less_deferrables which shows his:

I don’t think EMHASS is crashing, I just think you’re not passing any data to it. I’m not sure how to pass data to it the way you want to so I’m just hunting for misconfigurations. I could be wrong.

Ah you are right. This was an easy one.

hass_url: empty
long_lived_token: empty
costfun: profit
logging_level: INFO
optimization_time_step: 30
historic_days_to_retrieve: 2
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.production_pv_w
sensor_power_load_no_var_loads: sensor.consumption_w
number_of_deferrable_loads: 2
list_nominal_power_of_deferrable_loads:
  - nominal_power_of_deferrable_loads: 3000
  - nominal_power_of_deferrable_loads: 750
list_operating_hours_of_each_deferrable_load:
  - operating_hours_of_each_deferrable_load: 5
  - operating_hours_of_each_deferrable_load: 8
list_peak_hours_periods_start_hours:
  - peak_hours_periods_start_hours: "02:54"
  - peak_hours_periods_start_hours: "17:24"
list_peak_hours_periods_end_hours:
  - peak_hours_periods_end_hours: "15:24"
  - peak_hours_periods_end_hours: "20:24"
list_treat_deferrable_load_as_semi_cont:
  - treat_deferrable_load_as_semi_cont: true
  - treat_deferrable_load_as_semi_cont: true
load_peak_hours_cost: 0.1907
load_offpeak_hours_cost: 0.1419
photovoltaic_production_sell_price: 0.065
maximum_power_from_grid: 9000
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

About the sensors:


My recorder settings are:

  purge_keep_days: 8
  commit_interval: 30

which is above the 2 days of data required for this configuration of the add-on.

Thanks for the time you are spending on my problem!

1 Like

Nope, no idea. I jumped over all those methods and implemented MPC. Perhaps try feeding some data manually to see if it responds to MPC optim?

Thanks anyway.
Just a question: on which platform are you running HA/the add-on?
I’m on a Pi3b+ but I could try on a Pi4.

I’m on an intel NUC running proxmox. The NUC is running a couple of other servers as well like Teslamate.

In the meantime I tried with a Pi4 and it worked with some “fake” sensors.
I start to think the problem may be related to (my) Pi3b+.
Anybody else using a Pi3b+?

@davidusb any comments on this? Any additional minimum hardware requirements?
Thanks

Hold on!
I had an idea and tried to pass different fake sensors on my Pi3b+.
This time it worked. Maybe my problem is related to the amount of data passed to the solver.
My sensors have a 2 seconds resolutions (I know, it’s high… but I had some troubles with my battery system which is providing all the measurements I need and I was trying to be as close as possible to real time data) and maybe this is too much for the hardware/solver. @rcruikshank may I ask you what your sensors resolution is?
What do you think @davidusb ? What would be your suggestion on data data resolution? Did you perform any tests?

In the meantime I will try to create some lower resolution sensors and see what happens.

Looks like its about 11 seconds.

1 Like

These architectures are supported: amd64 , armv7 (for old RPi’s 2 and 3) , armhf ( for RPi’s 3 and zeros) and aarch64 (for the newer RPi4).

These 4 architectures should be sufficient to cover most of the systems out there. In terms of memory the RPi’s 3 should be able to run this add-on just fine.

Data resolution should not be a problem. We are retrieving just small amounts of data. For a day-ahead optimization we will need to retrieve 48h of data, even at a 1 second resolution that’s not a lot of data and is handled quite well using the very efficient Home Assistant API.
You seem to have isolated your issue to those input sensors that you are using but for me the resolution is not the issue. This is hard to debug I have not seen something like this before, usually the logger lead us to the problem but it is not your case.
Try erasing the .pkl file located in the \share folder to reset the add-on results.

I tried to erase all the files in the share folder, but using the right sensors still the same issue.

If useful, I think I’m narrowing the issue.
I did some tests:

sensor_power_photovoltaics: sensor.production_pv_w
sensor_power_load_no_var_loads: sensor.consumption_w

=> Not working (we already knew this)

sensor_power_photovoltaics: sensor.production_pv_w
sensor_power_load_no_var_loads: sensor.fake_working_data

=> Working

sensor_power_photovoltaics: sensor.fake_working_data
sensor_power_load_no_var_loads: sensor.consumption_w

=> Not working

sensor_power_photovoltaics: sensor.consumption_w
sensor_power_load_no_var_loads: sensor.fake_working_data

=> Working

sensor_power_photovoltaics: sensor.fake_working_data
sensor_power_load_no_var_loads: sensor.production_pv_w

=> Not working

It seems to me it’s something not sensor-specific (I mean, it’s something related to the way the sensor is built/created but the problem is not in a specific sensor) and linked to the way the sensor_power_load_no_var_loads data is loaded and passed to the solver.
Anything different in the way sensor_power_photovoltaics and sensor_power_load_no_var_loads data is pulled/treated?

For what it’s worth. My CPU utilisation calling naive-mpc-optim.

I seem to get an error on the half hour calling this process every 60 seconds.

["2023-08-03T22:30:03.049Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-04T22:30:00.017Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-05T19:30:00.308Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-05T20:00:00.395Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-05T20:30:00.116Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-05T21:00:00.542Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-05T21:30:00.072Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-05T22:30:00.093Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-05T23:00:00.575Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-05T23:30:00.741Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-06T00:00:00.031Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-06T00:30:00.514Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-06T01:00:00.088Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-06T02:00:00.662Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-06T02:30:00.213Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-06T19:00:00.341Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-06T19:30:00.896Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-06T20:00:00.450Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-06T20:30:00.884Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-06T21:00:00.514Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-06T21:30:00.589Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]
["2023-08-06T22:00:00.643Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n"]

Error:

2023-08-07 11:30:01,232 - web_server - INFO -  >> Performing naive MPC optimization...
2023-08-07 11:30:01,233 - web_server - INFO - Performing naive MPC optimization
2023-08-07 11:30:01,237 - web_server - ERROR - Exception on /action/naive-mpc-optim [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 199, in action_call
    opt_res = naive_mpc_optim(input_data_dict, app.logger)
  File "/usr/local/lib/python3.9/dist-packages/emhass/command_line.py", line 265, in naive_mpc_optim
    df_input_data_dayahead = input_data_dict['fcst'].get_load_cost_forecast(
  File "/usr/local/lib/python3.9/dist-packages/emhass/forecast.py", line 705, in get_load_cost_forecast
    forecast_out = self.get_forecast_out_from_csv(
  File "/usr/local/lib/python3.9/dist-packages/emhass/forecast.py", line 522, in get_forecast_out_from_csv
    forecast_out = pd.DataFrame(
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/frame.py", line 694, in __init__
    mgr = ndarray_to_mgr(
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/internals/construction.py", line 351, in ndarray_to_mgr
    _check_values_indices_shape_match(values, index, columns)
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/internals/construction.py", line 422, in _check_values_indices_shape_match
    raise ValueError(f"Shape of passed values is {passed}, indices imply {implied}")
ValueError: Shape of passed values is (25, 1), indices imply (26, 1)
2023-08-07 11:30:01,268 - web_server - INFO - Setting up needed data
2023-08-07 11:30:01,271 - web_server - INFO -  >> Publishing data...
2023-08-07 11:30:01,271 - web_server - INFO - Publishing data to HASS instance
2023-08-07 11:30:01,284 - web_server - INFO - Successfully posted to sensor.p_pv_forecast = 1957
2023-08-07 11:30:01,297 - web_server - INFO - Successfully posted to sensor.p_load_forecast = 431.72
2023-08-07 11:30:01,308 - web_server - INFO - Successfully posted to sensor.p_deferrable0 = 1300.0
2023-08-07 11:30:01,320 - web_server - INFO - Successfully posted to sensor.p_batt_forecast = -225.28
2023-08-07 11:30:01,335 - web_server - INFO - Successfully posted to sensor.soc_batt_forecast = 49.01
2023-08-07 11:30:01,348 - web_server - INFO - Successfully posted to sensor.p_grid_forecast = 0.0
2023-08-07 11:30:01,357 - web_server - INFO - Successfully posted to sensor.total_cost_fun_value = 3.68
2023-08-07 11:30:01,366 - web_server - INFO - Successfully posted to sensor.unit_load_cost = 0.16
2023-08-07 11:30:01,378 - web_server - INFO - Successfully posted to sensor.unit_prod_price = 0.04

Looks like amber is changing the data shape and dropping one data point at the half hour.

Maybe reduce the prediction horizon by one to match.

1 Like

Looks like it needs to be more than 1 some of the time. I captured the list in the error logs and the amber data is as little as 37 long. But its not very often.

["2023-08-07T19:00:00.052Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n","{\"load_cost_forecast\":[0.17, 0.2, 0.21, 0.26, 0.43, 0.21, 0.19, 0.17, 0.13, 0.14, 0.13, 0.13, 0.15, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.39, 0.42, 0.4, 0.39, 0.42, 0.51, 0.7, 1.73, 13.38, 4.87, 1.16, 0.68, 0.44, 0.44, 0.44, 0.26, 0.22, 0.23, 0.2, 0.19, 0.19, 0.17, 0.19, 0.17, 0.16, 0.16, 0.16, 0.16],\"prod_price_forecast\":[0.07, 0.1, 0.11, 0.15, 0.31, 0.1, 0.09, 0.07, 0.04, 0.04, 0.04, 0.02, 0.03, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.3, 0.33, 0.31, 0.3, 0.33, 0.42, 0.59, 1.52, 12.12, 4.38, 1.0, 0.56, 0.32, 0.32, 0.32, 0.15, 0.12, 0.12, 0.09, 0.09, 0.09, 0.08, 0.09, 0.07, 0.07, 0.07, 0.07, 0.07],\"pv_power_forecast\":[0, 0, 0, 0, 5, 110, 489, 984, 1407, 1784, 2133, 2439, 2738, 2949, 3117, 3210, 3204, 3127, 2983, 2655, 2219, 1765, 1301, 773, 234, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 297, 795, 1334, 1846, 2281, 2670, 2969, 3215, 3384, 3483, 3493, 3450, 3327, 3136, 2844, 2501, 2106, 1652, 1099, 536, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\"prediction_horizon\":47,\"soc_init\":0.41,\"soc_final\":0.05,\"def_total_hours\":[2]}"]
["2023-08-07T20:00:00.818Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n","{\"load_cost_forecast\":[0.22, 0.31, 0.43, 0.2, 0.17, 0.18, 0.13, 0.14, 0.13, 0.13, 0.15, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.39, 0.42, 0.41, 0.39, 0.42, 0.51, 0.7, 1.74, 13.38, 2.61, 1.0, 0.68, 0.44, 0.44, 0.44, 0.26, 0.22, 0.23, 0.2, 0.19, 0.19, 0.17, 0.19, 0.17, 0.16, 0.16, 0.16, 0.16],\"prod_price_forecast\":[0.11, 0.2, 0.3, 0.09, 0.07, 0.08, 0.04, 0.04, 0.04, 0.02, 0.03, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.3, 0.33, 0.32, 0.3, 0.33, 0.42, 0.59, 1.53, 12.11, 2.33, 0.86, 0.57, 0.32, 0.32, 0.32, 0.15, 0.12, 0.12, 0.09, 0.09, 0.09, 0.08, 0.09, 0.07, 0.07, 0.07, 0.07, 0.07],\"pv_power_forecast\":[0, 0, 5, 110, 489, 984, 1407, 1784, 2133, 2439, 2738, 2949, 3117, 3210, 3204, 3127, 2983, 2655, 2219, 1765, 1301, 773, 234, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 297, 795, 1334, 1846, 2281, 2670, 2969, 3215, 3384, 3483, 3493, 3450, 3327, 3136, 2844, 2501, 2106, 1652, 1099, 536, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\"prediction_horizon\":45,\"soc_init\":0.4,\"soc_final\":0.05,\"def_total_hours\":[2]}"]
["2023-08-07T23:30:00.283Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n","{\"load_cost_forecast\":[0.13, 0.15, 0.15, 0.15, 0.13, 0.11, 0.11, 0.11, 0.11, 0.13, 0.39, 0.4, 0.39, 0.39, 0.41, 0.49, 0.7, 1.51, 1.86, 1.76, 0.77, 0.68, 0.44, 0.44, 0.26, 0.26, 0.22, 0.22, 0.2, 0.19, 0.19, 0.17, 0.17, 0.17, 0.16, 0.16, 0.16, 0.16],\"prod_price_forecast\":[0.03, 0.05, 0.04, 0.03, 0.02, 0.0, 0.0, 0.0, 0.0, 0.02, 0.3, 0.32, 0.3, 0.3, 0.33, 0.39, 0.59, 1.32, 1.64, 1.55, 0.65, 0.57, 0.32, 0.32, 0.15, 0.15, 0.12, 0.12, 0.09, 0.09, 0.09, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07],\"pv_power_forecast\":[689, 1749, 1883, 2330, 2689, 2860, 2887, 2846, 2744, 2616, 2399, 2107, 1737, 1332, 833, 279, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 365, 891, 1429, 1940, 2375, 2761, 3058, 3287, 3457, 3542, 3562, 3487, 3364, 3165, 2884, 2546, 2163, 1709, 1166, 599, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\"prediction_horizon\":38,\"soc_init\":0.1,\"soc_final\":0.05,\"def_total_hours\":[2]}"]
["2023-08-08T00:00:00.198Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n","{\"load_cost_forecast\":[0.13, 0.15, 0.15, 0.13, 0.13, 0.11, 0.11, 0.11, 0.12, 0.39, 0.4, 0.39, 0.39, 0.41, 0.48, 0.7, 1.25, 1.86, 1.16, 0.6, 0.65, 0.44, 0.41, 0.26, 0.26, 0.22, 0.22, 0.2, 0.19, 0.18, 0.17, 0.17, 0.17, 0.16, 0.16, 0.16, 0.16],\"prod_price_forecast\":[0.04, 0.03, 0.03, 0.02, 0.02, 0.0, 0.0, 0.0, 0.01, 0.3, 0.32, 0.3, 0.3, 0.33, 0.38, 0.59, 1.08, 1.64, 1.0, 0.5, 0.54, 0.32, 0.29, 0.15, 0.15, 0.12, 0.12, 0.09, 0.09, 0.08, 0.08, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07],\"pv_power_forecast\":[599, 1883, 2330, 2689, 2860, 2887, 2846, 2744, 2616, 2399, 2107, 1737, 1332, 833, 279, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 365, 891, 1429, 1940, 2375, 2761, 3058, 3287, 3457, 3542, 3562, 3487, 3364, 3165, 2884, 2546, 2163, 1709, 1166, 599, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\"prediction_horizon\":37,\"soc_init\":0.1,\"soc_final\":0.05,\"def_total_hours\":[2]}"]
["2023-08-08T00:30:00.328Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n","{\"load_cost_forecast\":[0.13, 0.13, 0.13, 0.13, 0.13, 0.11, 0.11, 0.12, 0.39, 0.41, 0.39, 0.39, 0.41, 0.48, 0.7, 1.25, 1.86, 1.18, 0.62, 0.59, 0.41, 0.36, 0.26, 0.25, 0.22, 0.22, 0.2, 0.19, 0.18, 0.17, 0.19, 0.16, 0.16, 0.16, 0.16, 0.16],\"prod_price_forecast\":[0.02, 0.02, 0.02, 0.02, 0.01, 0.0, 0.0, 0.01, 0.3, 0.32, 0.3, 0.3, 0.33, 0.38, 0.59, 1.08, 1.64, 1.02, 0.51, 0.49, 0.29, 0.25, 0.15, 0.14, 0.12, 0.12, 0.09, 0.09, 0.08, 0.08, 0.09, 0.07, 0.07, 0.07, 0.07, 0.07],\"pv_power_forecast\":[1144, 2330, 2689, 2860, 2887, 2846, 2744, 2616, 2399, 2107, 1737, 1332, 833, 279, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 365, 891, 1429, 1940, 2375, 2761, 3058, 3287, 3457, 3542, 3562, 3487, 3364, 3165, 2884, 2546, 2163, 1709, 1166, 599, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\"prediction_horizon\":36,\"soc_init\":0.1,\"soc_final\":0.05,\"def_total_hours\":[2]}"]
["2023-08-08T01:00:00.228Z",500,"http://192.168.99.17:5000/action/naive-mpc-optim","<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<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>\n","{\"load_cost_forecast\":[0.11, 0.13, 0.13, 0.13, 0.12, 0.12, 0.12, 0.39, 0.4, 0.39, 0.39, 0.41, 0.48, 0.7, 1.25, 1.87, 1.04, 0.59, 0.6, 0.41, 0.36, 0.26, 0.25, 0.22, 0.22, 0.2, 0.19, 0.17, 0.17, 0.17, 0.17, 0.16, 0.16, 0.16, 0.16],\"prod_price_forecast\":[-0.01, 0.02, 0.02, 0.02, 0.0, 0.0, 0.01, 0.3, 0.31, 0.3, 0.3, 0.33, 0.38, 0.59, 1.08, 1.65, 0.89, 0.48, 0.49, 0.29, 0.25, 0.15, 0.14, 0.12, 0.12, 0.09, 0.09, 0.08, 0.08, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07],\"pv_power_forecast\":[1111, 2689, 2860, 2887, 2846, 2744, 2616, 2399, 2107, 1737, 1332, 833, 279, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 365, 891, 1429, 1940, 2375, 2761, 3058, 3287, 3457, 3542, 3562, 3487, 3364, 3165, 2884, 2546, 2163, 1709, 1166, 599, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\"prediction_horizon\":35,\"soc_init\":0.2,\"soc_final\":0.05,\"def_total_hours\":[2]}"]

It can get down to 33 around 12pm before the next day forecasts are published.

You should set prediction horizon dynamically based on the number of forecasts available.

Prediction horizon based on the length of pv_power_forecast

post_mpc_optim: >-
  curl -i -H 'Content-Type: application/json' -X POST -d '{
    "def_total_hours":[
      {{  states('sensor.wasmachien_uren')  }},
      {{  states('sensor.droogkast_uren')  }},
      {{  states('sensor.afwasmachien_uren')  }},
      {{  states('sensor.warmtepompboiler_uren')  }},
      {{  states('sensor.warmtepomp_uren')}}],
    "set_def_constant":[true, true, true, true, true],
    "pv_power_forecast":{{ state_attr('sensor.pv_power_forecast_list', 'list')  }},
    "prod_price_forecast":{{ state_attr('sensor.prod_price_forecast_list', 'list')  }},
    "load_cost_forecast":{{ state_attr('sensor.cost_forecast_list', 'list')  }},
    "prediction_horizon":{{ state_attr('sensor.pv_power_forecast_list', 'list')| length }}
    }' http://localhost:5001/action/naive-mpc-optim
2 Likes