I am having problem to uppdate from emhass 10.6 to the last version. In version 10.6 evrything is working fine. I don’t know what I am missing. can some one help me out.
Here are some loggs
[2025-04-01 18:19:48 +0300] [21] [INFO] Passed runtime parameters: {'prediction_horizon': 24, 'soc_init': 1.0, 'soc_final': 1, 'num_def_loads': 6, 'def_total_hours': [3, 1, 1, 1, 1, 1], 'P_deferrable_nom': [2000, 1000, 1100, 1500, 500, 500], 'treat_def_as_semi_cont': [True, True, True, True, False, False], 'def_start_timestep': [0, 0, 0, 0, 0, 0], 'def_end_timestep': [12, 12, 12, 12, 6, 6], 'set_def_constant': [False, False, False, False, True, True], 'load_cost_forecast': [0.1023, 0.09354, 0.08046, 0.07961, 0.0773, 0.07717, 0.07675, 0.07478, 0.07429, 0.07415, 0.07461, 0.07474, 0.07616, 0.07717, 0.0774, 0.07917, 0.07982, 0.08083, 0.07867, 0.07715, 0.07675, 0.07682, 0.07715, 0.08004], 'prod_price_forecast': [0.0154, 0.00842, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'pv_power_forecast': [1007, 405, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 405, 842, 1500, 3364, 5342, 6187, 6737, 6857, 6256, 5390, 4207], 'alpha': 0.2, 'beta': 0.8}
[2025-04-01 18:19:48 +0300] [21] [INFO] >> Setting input data dict
[2025-04-01 18:19:48 +0300] [21] [INFO] Setting up needed data
[2025-04-01 18:19:48 +0300] [21] [INFO] Retrieve hass get data method initiated...
[2025-04-01 18:19:49 +0300] [21] [ERROR] Exception on /action/naive-mpc-optim [POST]
Traceback (most recent call last):
File "/app/.venv/lib/python3.12/site-packages/flask/app.py", line 1511, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/flask/app.py", line 919, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/src/emhass/web_server.py", line 414, in action_call
input_data_dict = set_input_data_dict(
^^^^^^^^^^^^^^^^^^^^
File "/app/src/emhass/command_line.py", line 284, in set_input_data_dict
if not rh.prepare_data(
^^^^^^^^^^^^^^^^
File "/app/src/emhass/retrieve_hass.py", line 401, in prepare_data
self.df_final[new_var_interp] = self.df_final[new_var_interp].interpolate(
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/pandas/core/frame.py", line 4108, in __getitem__
indexer = self.columns._get_indexer_strict(key, "columns")[1]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 6200, in _get_indexer_strict
self._raise_if_missing(keyarr, indexer, axis_name)
File "/app/.venv/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 6252, in _raise_if_missing
raise KeyError(f"{not_found} not in index")
KeyError: "['sensor.total_dc_power'] not in index"
[2025-04-01 18:20:04 +0300] [21] [INFO] >> Obtaining params:
[2025-04-01 18:20:04 +0300] [21] [INFO] Passed runtime parameters: {}
[2025-04-01 18:20:04 +0300] [21] [INFO] >> Setting input data dict
[2025-04-01 18:20:04 +0300] [21] [INFO] Setting up needed data
[2025-04-01 18:20:04 +0300] [21] [INFO] Continual publish thread service started
[2025-04-01 18:20:04 +0300] [21] [INFO] >> Publishing data...
[2025-04-01 18:20:04 +0300] [21] [INFO] Publishing data to HASS instance
[2025-04-01 18:20:04 +0300] [21] [INFO] Successfully posted to sensor.p_pv_forecast = 3033.43
[2025-04-01 18:20:04 +0300] [21] [INFO] Successfully posted to sensor.p_load_forecast = 891.16
[2025-04-01 18:20:04 +0300] [21] [INFO] Successfully posted to sensor.p_hybrid_inverter = 3891.16
[2025-04-01 18:20:04 +0300] [21] [INFO] Successfully posted to sensor.p_deferrable0 = 2000.0
[2025-04-01 18:20:04 +0300] [21] [INFO] Successfully posted to sensor.p_deferrable1 = 0.0
[2025-04-01 18:20:04 +0300] [21] [INFO] Successfully posted to sensor.p_deferrable2 = 0.0
[2025-04-01 18:20:04 +0300] [21] [INFO] Successfully posted to sensor.p_deferrable3 = 0.0
[2025-04-01 18:20:04 +0300] [21] [INFO] Successfully posted to sensor.p_deferrable4 = 500.0
[2025-04-01 18:20:04 +0300] [21] [INFO] Successfully posted to sensor.p_batt_forecast = 857.73
[2025-04-01 18:20:04 +0300] [21] [INFO] Successfully posted to sensor.soc_batt_forecast = 90.6
[2025-04-01 18:20:04 +0300] [21] [INFO] Successfully posted to sensor.p_grid_forecast = 0.0
[2025-04-01 18:20:04 +0300] [21] [INFO] Successfully posted to sensor.total_cost_fun_value = -0.7
[2025-04-01 18:20:04 +0300] [21] [INFO] Successfully posted to sensor.optim_status = Optimal
[2025-04-01 18:20:04 +0300] [21] [INFO] Successfully posted to sensor.unit_load_cost = 0.1023
[2025-04-01 18:20:04 +0300] [21] [INFO] Successfully posted to sensor.unit_prod_price = 0.0154
my config:
{
"battery_charge_efficiency": 0.95,
"battery_charge_power_max": 5000,
"battery_discharge_efficiency": 0.95,
"battery_discharge_power_max": 5000,
"battery_dynamic_max": 0.9,
"battery_dynamic_min": -0.9,
"battery_maximum_state_of_charge": 1,
"battery_minimum_state_of_charge": 0,
"battery_nominal_energy_capacity": 9500,
"battery_target_state_of_charge": 1,
"compute_curtailment": false,
"continual_publish": true,
"costfun": "profit",
"delta_forecast_daily": 1,
"end_timesteps_of_each_deferrable_load": [
0,
0,
0,
0,
0
],
"historic_days_to_retrieve": 2,
"inverter_is_hybrid": true,
"load_cost_forecast_method": "csv",
"load_forecast_method": "naive",
"load_negative": false,
"load_offpeak_hours_cost": 0.1419,
"load_peak_hour_periods": {
"period_hp_1": [
{
"start": "02:54"
},
{
"end": "15:24"
}
],
"period_hp_2": [
{
"start": "17:24"
},
{
"end": "20:24"
}
]
},
"load_peak_hours_cost": 0.1907,
"logging_level": "INFO",
"lp_solver": "default",
"lp_solver_path": "empty",
"maximum_power_from_grid": 9000,
"maximum_power_to_grid": 9000,
"method_ts_round": "nearest",
"modules_per_string": [
16
],
"nominal_power_of_deferrable_loads": [
2000,
1000,
1000,
1000,
1000
],
"number_of_deferrable_loads": 5,
"operating_hours_of_each_deferrable_load": [
2,
1,
1,
1,
2
],
"optimization_time_step": 60,
"photovoltaic_production_sell_price": 0.1419,
"production_price_forecast_method": "csv",
"pv_inverter_model": [
"Fronius_International_GmbH__Fronius_Primo_5_0_1_208_240__240V_"
],
"pv_module_model": [
"CSUN_Eurasia_Energy_Systems_Industry_and_Trade_CSUN295_60M"
],
"sensor_linear_interp": [
"sensor.total_dc_power",
"sensor.power_load_no_var_loads"
],
"sensor_power_load_no_var_loads": "sensor.power_load_no_var_loads",
"sensor_power_photovoltaics": "sensor.total_dc_power",
"sensor_replace_zero": [
"sensor.total_dc_power"
],
"set_battery_dynamic": true,
"set_deferrable_load_single_constant": [
false,
false,
false,
false,
false
],
"set_deferrable_startup_penalty": [
0,
0,
0,
0,
0
],
"set_nocharge_from_grid": false,
"set_nodischarge_to_grid": true,
"set_total_pv_sell": false,
"set_use_battery": true,
"set_use_pv": false,
"set_zero_min": true,
"start_timesteps_of_each_deferrable_load": [
0,
0,
0,
0,
0
],
"strings_per_inverter": [
1
],
"surface_azimuth": [
205
],
"surface_tilt": [
30
],
"treat_deferrable_load_as_semi_cont": [
true,
true,
true,
true,
false
],
"weather_forecast_method": "csv",
"weight_battery_charge": 1,
"weight_battery_discharge": 1
}
In config I am using the these rest commands
# run by script
emhass_naive_mpc_optim_script:
url: http://localhost:5000/action/naive-mpc-optim
method: POST
content_type: "application/json"
payload: >
{ {{json}} }
# publish data via Rest command
publish_data2:
url: http://localhost:5000/action/publish-data
method: POST
content_type: "application/json"
payload: "{}"
The script that I am using:
alias: EMHASS Naive MPC optim call
mode: single
variables:
json_string: >
{%- set nordpool=((state_attr('sensor.nordpool_kwh_fi_eur_6_10_0',
'raw_today') | map(attribute='value') | list+
state_attr('sensor.nordpool_kwh_fi_eur_6_10_0', 'raw_tomorrow') |
map(attribute='value') | list))[now().hour:][:24] %} {%- set nordpool_sell =
namespace(values=[]) %} {%- set nordpool_buy = namespace(values=[]) %} {%-
for i in nordpool %} {%- set
nordpool_sell.values=nordpool_sell.values+[(((i)-(states('input_number.export_margnial')|float*0.01))
|round(5),0)|max]%} {%- set
nordpool_buy.values=nordpool_buy.values+[(i*((states('input_number.moms_skatt')|float/100)+1)+(states('input_number.import_marginal')|float*0.01)+(states('input_number.overforings_avgift_import')|float*0.01)+(states('input_number.elskatt')|float)*0.01)|round(5)]%}
{%- endfor %} {%- set
solcast=((state_attr('sensor.solcast_pv_forecast_forecast_today','detailedHourly')
| map(attribute='pv_estimate') | map('multiply',1000) | map('int') | list +
state_attr('sensor.solcast_pv_forecast_forecast_tomorrow', 'detailedHourly')
| map(attribute='pv_estimate') | map('multiply',1000) | map('int') |
list))[now().hour:][:24] %} {%- set soc_init =
min(max((states('sensor.battery_level')|float(0)/100)|round(2),0.1),1)%}
{%-set horizon = [nordpool_sell.values|length,
nordpool_buy.values|length,solcast|length]|min %} "prediction_horizon": {{
horizon }}, "soc_init":{{soc_init }} , "soc_final": 1, "num_def_loads":
6, "def_total_hours":[3,1,1,1,1,1], "P_deferrable_nom":
[2000,1000,1100,1500,500,500],
"treat_def_as_semi_cont":[true,true,true,true,false,false],
"def_start_timestep":[0,0,0,0,0,0], "def_end_timestep":[12,12,12,12,6,6],
"set_def_constant": [false,false,false,false,true,true],
"load_cost_forecast":{{nordpool_buy.values}}, "prod_price_forecast":
{{nordpool_sell.values}}, "pv_power_forecast":{{solcast}}, "alpha": 0.2,
"beta": 0.8
sequence:
- data:
json: "{{ json_string }}"
action: rest_command.emhass_naive_mpc_optim_script
And some automation to run everything:
alias: EMHASS mpc optim script
description: ""
triggers:
- minutes: /5
trigger: time_pattern
- event: start
trigger: homeassistant
conditions: []
actions:
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- action: script.1694970038100
data: {}
- delay:
hours: 0
minutes: 0
seconds: 15
milliseconds: 0
- data: {}
action: rest_command.publish_data2
mode: single
And as I said before. In 10.6 everything is working fine… But not in 12.8