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

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

As promised I created a low res sensor (5 seconds sampling) and fed it to the add-on.
This time it worked (if I go back to the higher res sensor it still fails).
This is the code for the low resolution sensor:

- trigger:
    - platform: time_pattern
      seconds: "/5"
  sensor:
    - name: "consumption_low_res_w"
      unique_id: consumption_low_res_w
      unit_of_measurement: W
      device_class: power
      state: "{{ states('sensor.consumption_w') }}"
      state_class: measurement

@davidusb if you are interested I can perform some more tests (for example trying to sample at different rates - even the same) and let you know.

Ok so there is a limit on the sensors resolution after all.

Yes for future reference and users having these type of issue it could be useful to known what is the limit, but I guess that it will be related to the specific hardware you’re using right?

In the end it seems it’s something related to how the data is recorded/stored and not the amount and/or frequency.
I passed a sensor that is sampling with 1 second frequency from my real sensor (which is pulling data every 2 seconds) and it worked.
Maybe it’s something related to the fact that my real sensor is a RESFTUL one and sometimes the pull frequency is too high and HA can’t keep the pace; so maybe the data point are not equally spaced while in the sampled one this is automatically fixed by HA… who knows…
But for sure the problem is happening only with sensor_power_load_no_var_loads so I would say that maybe, by chance HA, can manage this situation while this add-on can’t for this specific input.
Anyway thanks for the patience and support.

I believe this ends my tests for this specific problem and provides a workaround is somebody else experiences the same.

1 Like

Hi,

Getting this issue when trying to install on an RPI4

23-08-15 08:21:42 WARNING (SyncWorker_7) [supervisor.addons.validate] Add-on have full device access, and selective device access in the configuration. Please report this to the maintainer of DeskPi Pro Active Cooling

As I don’t have DeskPi Pro Active Cooling installed I’m at a bit of a loss …

Sorted it.

1 Like

So what was it? Just for future reference for other people facing these warning messages.

I had a repo with that in it - removed it and problem went away.

Hello,
I have a question: how can I feed the add-on with dynamic peak hours/energy costs?
In my country peak hours change depending on the day (Sunday/bank holidays) and the costs are potentially updated on a monthly basis (unless your contract has a fixed cost).
I previously created some helpers (input_datetime) containing the start/end time but when I tried to use them

list_peak_hours_periods_start_hours:
  - peak_hours_periods_start_hours: input_datetime.peak_energy_start
list_peak_hours_periods_end_hours:
  - peak_hours_periods_end_hours: input_datetime.peak_energy_end

I received the error below (I assume the same would happen with dynamic costs).
Thanks!

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 191, in action_call
    opt_res = dayahead_forecast_optim(input_data_dict, app.logger)
  File "/usr/local/lib/python3.9/dist-packages/emhass/command_line.py", line 228, in dayahead_forecast_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 685, in get_load_cost_forecast
    list_df_hp.append(df_final[self.var_load_cost].between_time(
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/generic.py", line 7890, in between_time
    indexer = index.indexer_between_time(
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/indexes/datetimes.py", line 852, in indexer_between_time
    start_time = to_time(start_time)
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/tools/times.py", line 118, in to_time
    return _convert_listlike(np.array([arg]), format)[0]
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/tools/times.py", line 98, in _convert_listlike
    raise ValueError(f"Cannot convert arg {arg} to a time")
ValueError: Cannot convert arg ['input_datetime.peak_energy_start'] to a time
1 Like

Any Idea why if I use forecast.solar PV prediction, with a Wp = 8.000 the chart shows a prediction (P_PV) up to 10.000 Wp while the service forecast itself is below 6.000 Wp? Am I misreading the chart?


curl -i -H "Content-Type:application/json" -X POST -d '{"solar_forecast_kwp":8}' http://localhost:5000/action/dayahead-optim

You are misreading the charts. The top chart has units of instant power in W while the low chart has units of energy in kWh. So not the same units but still it is odd that the prediction goes over 8 kW when you specified this as your peak power.
what is your configuration?

You are right about the units.
Here it is my configuration.
…unless it is something related to my previous problem (“Empty server reply”… You know what? In the end I think it was related to my limited hardware Pi3b+ 1GB RAM… as sometimes it was failing with a resampled sensor, sometimes was not… I think I’ve temporarily solved the problem by increasing the system swap file - a good guy created an add-on for that. Now it takes a while to process a couple of days but it works in almost any situation).

Edit: FYI if I use the scrapper forecast method the P_PV maximum doesn’t exceed 6 kW.

hass_url: empty
long_lived_token: empty
costfun: self-consumption
logging_level: DEBUG
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: true
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: 1
list_nominal_power_of_deferrable_loads:
  - nominal_power_of_deferrable_loads: 0
list_operating_hours_of_each_deferrable_load:
  - operating_hours_of_each_deferrable_load: 0
list_peak_hours_periods_start_hours:
  - peak_hours_periods_start_hours: "02:54"
list_peak_hours_periods_end_hours:
  - peak_hours_periods_end_hours: "15:24"
list_treat_deferrable_load_as_semi_cont:
  - 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: 6000
list_pv_module_model:
  - pv_module_model: SunPower_SPR_E20_327
  - pv_module_model: SunPower_SPR_P19_395_COM
list_pv_inverter_model:
  - pv_inverter_model: SMA_America__SB3000TL_US_22__240V_
  - pv_inverter_model: SMA_America__STP50_US_40__480V_
list_surface_tilt:
  - surface_tilt: 17
  - surface_tilt: 17
list_surface_azimuth:
  - surface_azimuth: 225
  - surface_azimuth: 225
list_modules_per_string:
  - modules_per_string: 9
  - modules_per_string: 14
list_strings_per_inverter:
  - strings_per_inverter: 1
  - strings_per_inverter: 1
set_use_battery: true
battery_discharge_power_max: 7100
battery_charge_power_max: 7100
battery_discharge_efficiency: 0.95
battery_charge_efficiency: 0.95
battery_nominal_energy_capacity: 27000
battery_minimum_state_of_charge: 0.3
battery_maximum_state_of_charge: 0.9
battery_target_state_of_charge: 0.6

About this question:
is it possible to pass the peak start/end hours and related prices via the curl command instead of loading them from config?
Or the only allowed way is to pass the list using load_cost_forecast as I see in some examples?