ok Iāve uninstalled and reinstalled EMHASS.
Reconfigured with the same settings.
Checked the original template output is valid JSON.
Set up in node-red the more recent template that Mark suggested and also checked its output is valid.
Added this template as a rest_command in configfuration.yaml
So I have three different MPC templates, two in node-red and one in configuration.yaml
They all cause a NOTRUN error.
These are the three:
Original or what I was running yesterday without issue until I rebooted the system after installing browser-mod (which I havenāt removed):
{"load_cost_forecast":{{(([states('sensor.cecil_st_general_price')|float(0)]+state_attr('sensor.cecil_st_general_forecast', 'forecasts') |map(attribute='per_kwh')|list)[:48])
}},"prod_price_forecast":{{(([states('sensor.cecil_st_feed_in_price')|float(0)]+state_attr('sensor.cecil_st_feed_in_forecast', 'forecasts')|map(attribute='per_kwh')|list)[:48])
}},"pv_power_forecast":{{([states('sensor.sonnenbatterie_84324_production_w')|int(0)]+state_attr('sensor.forecast_today', 'detailedForecast')|selectattr('period_start','gt',utcnow()) | map(attribute='pv_estimate')|map('multiply',2000)|map('int')|list+state_attr('sensor.forecast_tomorrow', 'detailedForecast')|selectattr('period_start','gt',utcnow()) | map(attribute='pv_estimate')|map('multiply',2000)|map('int')|list)|tojson
}},"prediction_horizon":{{min(48, (state_attr('sensor.cecil_st_feed_in_forecast', 'forecasts')|map(attribute='per_kwh')|list|length)+1)
}},"soc_init":{{(states('sensor.sonnenbatterie_84324_state_charge_user')|int(0))/100
}},"soc_final":0.1,"def_total_hours":[2,2],"num_def_loads":2,"P_deferrable_nom":[1300,7360],"treat_def_as_semi_cont":[1, 0]}
New format which is much easier to read:
{
"prod_price_forecast": {{
([states('sensor.cecil_st_feed_in_price')|float(0)] +
(state_attr('sensor.cecil_st_feed_in_forecast', 'forecasts')|map(attribute='per_kwh')|list))
| tojson
}},
"load_cost_forecast": {{
([states('sensor.cecil_st_general_price')|float(0)] +
state_attr('sensor.cecil_st_general_forecast', 'forecasts') |map(attribute='per_kwh')|list)
| tojson
}},
"pv_power_forecast": {{
([states('sensor.sonnenbatterie_84324_production_w')|int(0)] +
state_attr('sensor.forecast_today', 'detailedForecast')|selectattr('period_start','gt',utcnow()) | map(attribute='pv_estimate')|map('multiply',2000)|map('int')|list +
state_attr('sensor.forecast_tomorrow', 'detailedForecast')|selectattr('period_start','gt',utcnow()) | map(attribute='pv_estimate')|map('multiply',2000)|map('int')|list
)| tojson
}},
"prediction_horizon": {{
min(48, (state_attr('sensor.cecil_st_feed_in_forecast', 'forecasts')|map(attribute='per_kwh')|list|length)+1)
}},
"num_def_loads": 2,
"def_total_hours": [2,2],
"P_deferrable_nom": [1300, 7360],
"treat_def_as_semi_cont": [1, 0],
"set_def_constant": [0, 0],
"soc_init": {{ (states('sensor.sonnenbatterie_84324_state_charge_user')|int(0))/100 }},
"soc_final": 0.0
}
And the rest_command:
rest_command:
naive_mpc_optim:
url: http://localhost:5000/action/naive-mpc-optim
method: POST
content_type: 'application/json'
payload: >-
{
"prod_price_forecast": {{
([states('sensor.cecil_st_feed_in_price')|float(0)] +
(state_attr('sensor.cecil_st_feed_in_forecast', 'forecasts')|map(attribute='per_kwh')|list))
| tojson
}},
"load_cost_forecast": {{
([states('sensor.cecil_st_general_price')|float(0)] +
state_attr('sensor.cecil_st_general_forecast', 'forecasts') |map(attribute='per_kwh')|list)
| tojson
}},
"pv_power_forecast": {{
([states('sensor.sonnenbatterie_84324_production_w')|int(0)] +
state_attr('sensor.forecast_today', 'detailedForecast')|selectattr('period_start','gt',utcnow()) | map(attribute='pv_estimate')|map('multiply',2000)|map('int')|list +
state_attr('sensor.forecast_tomorrow', 'detailedForecast')|selectattr('period_start','gt',utcnow()) | map(attribute='pv_estimate')|map('multiply',2000)|map('int')|list
)| tojson
}},
"prediction_horizon": {{
min(48, (state_attr('sensor.cecil_st_feed_in_forecast', 'forecasts')|map(attribute='per_kwh')|list|length)+1)
}},
"num_def_loads": 2,
"def_total_hours": [2,2],
"P_deferrable_nom": [1300, 7360],
"treat_def_as_semi_cont": [1, 0],
"set_def_constant": [0, 0],
"soc_init": {{(states('sensor.sonnenbatterie_84324_state_charge_user')|int(0))/100 }},
"soc_final": 0.1
}
They all produce something like this valid JSON output:
{
"prod_price_forecast": [0.34, 0.33, 0.34, 0.45, 0.57, 0.57, 0.54, 0.45, 0.26, 0.21, 0.15, 0.11, 0.12, 0.16, 0.16, 0.13, 0.13, 0.1, 0.09, 0.09, 0.09, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.09, 0.11, 0.15, 0.09, 0.12, 0.18, 0.09, 0.07, 0.05, 0.05, 0.03, 0.02, 0.02, 0.02, 0.02, 0.02, 0.3, 0.31, 0.31, 0.3, 0.33],
"load_cost_forecast": [0.43, 0.42, 0.43, 0.55, 0.69, 0.69, 0.65, 0.55, 0.38, 0.33, 0.25, 0.21, 0.23, 0.27, 0.27, 0.23, 0.23, 0.2, 0.19, 0.2, 0.19, 0.17, 0.16, 0.16, 0.16, 0.16, 0.17, 0.16, 0.19, 0.21, 0.25, 0.19, 0.22, 0.29, 0.19, 0.17, 0.16, 0.16, 0.15, 0.13, 0.13, 0.13, 0.13, 0.14, 0.39, 0.4, 0.4, 0.39, 0.42],
"pv_power_forecast": [540, 739, 102, 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, 59, 387, 891, 1389, 1837, 2300, 2725, 3011, 3247, 3441, 3600, 3646, 3539, 3351, 3043, 2650, 2239, 1808, 1337, 831, 305, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"prediction_horizon": 48,
"num_def_loads": 2,
"def_total_hours": [2, 2],
"P_deferrable_nom": [1300, 7360],
"treat_def_as_semi_cont": [1, 0],
"set_def_constant": [0, 0],
"soc_init": 1.0,
"soc_final": 0.0
}
If I take this output and send it via curl command such as this:
curl -i -H "Content-Type: application/json" -X POST -d '{ "prod_price_forecast": [0.35, 0.34, 0.34, 0.45, 0.57, 0.57, 0.54, 0.45, 0.26, 0.21, 0.15, 0.11, 0.12, 0.16, 0.16, 0.13, 0.13, 0.1, 0.09, 0.09, 0.09, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.09, 0.11, 0.15, 0.09, 0.12, 0.18, 0.09, 0.07, 0.05, 0.05, 0.03, 0.02, 0.02, 0.02, 0.02, 0.02, 0.3, 0.31, 0.31, 0.3, 0.33], "load_cost_forecast": [0.44, 0.43, 0.43, 0.55, 0.69, 0.69, 0.65, 0.55, 0.38, 0.33, 0.25, 0.21, 0.23, 0.27, 0.27, 0.23, 0.23, 0.2, 0.19, 0.2, 0.19, 0.17, 0.16, 0.16, 0.16, 0.16, 0.17, 0.16, 0.19, 0.21, 0.25, 0.19, 0.22, 0.29, 0.19, 0.17, 0.16, 0.16, 0.15, 0.13, 0.13, 0.13, 0.13, 0.14, 0.39, 0.4, 0.4, 0.39, 0.42], "pv_power_forecast": [504, 739, 102, 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, 59, 387, 891, 1389, 1837, 2300, 2725, 3011, 3247, 3441, 3600, 3646, 3539, 3351, 3043, 2650, 2239, 1808, 1337, 831, 305, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "prediction_horizon": 48, "num_def_loads": 2, "def_total_hours": [2,2], "P_deferrable_nom": [1300, 7360], "treat_def_as_semi_cont": [1, 0], "set_def_constant": [0, 0], "soc_init": 1.0, "soc_final": 0.0}' http://192.168.99.17:5000/action/naive-mpc-optim
I get this:
<!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 logs like this from all methods of posting:
2023-08-21 16:20:08,398 - web_server - INFO - Setting up needed data
2023-08-21 16:20:08,401 - web_server - INFO - Retrieve hass get data method initiated...
2023-08-21 16:20:08,957 - 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 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 110, 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 140, in get_data
df_tp = df_raw.copy()[['state']].replace(
File "/usr/local/lib/python3.9/dist-packages/pandas/core/generic.py", line 5920, in astype
new_data = self._mgr.astype(dtype=dtype, copy=copy, errors=errors)
File "/usr/local/lib/python3.9/dist-packages/pandas/core/internals/managers.py", line 419, in astype
return self.apply("astype", dtype=dtype, copy=copy, errors=errors)
File "/usr/local/lib/python3.9/dist-packages/pandas/core/internals/managers.py", line 304, in apply
applied = getattr(b, f)(**kwargs)
File "/usr/local/lib/python3.9/dist-packages/pandas/core/internals/blocks.py", line 580, in astype
new_values = astype_array_safe(values, dtype, copy=copy, errors=errors)
File "/usr/local/lib/python3.9/dist-packages/pandas/core/dtypes/cast.py", line 1292, in astype_array_safe
new_values = astype_array(values, dtype, copy=copy)
File "/usr/local/lib/python3.9/dist-packages/pandas/core/dtypes/cast.py", line 1237, in astype_array
values = astype_nansafe(values, dtype, copy=copy)
File "/usr/local/lib/python3.9/dist-packages/pandas/core/dtypes/cast.py", line 1098, in astype_nansafe
result = astype_nansafe(flat, dtype, copy=copy, skipna=skipna)
File "/usr/local/lib/python3.9/dist-packages/pandas/core/dtypes/cast.py", line 1181, in astype_nansafe
return arr.astype(dtype, copy=True)
ValueError: could not convert string to float: 'NOTRUN'
@davidusb when I uninstall EMHASS is there a directory I should delete to clean up?
The way this system goes off the rails makes me think that its something external from the EMHASS system itself. Some data irregularities that may clear up after 2 days like the home power consumption less deferrables which has some issues due to Telsa data not being as timely as it should. I was getting negative values for a few minutes when ever the car stopped charging. Then the sensor from the telsta integration catches up and it goes back above the zero line again. Iāve rewritted the template to ignore the tesla consumption if the calculation goes negative (hence the gap in the data).
Iām thinking this may need its own HA server to separate from the 5 year old VM its running on now. A lot of stuff running in the current HA Server.
Thanks for patience