Hi again,
Sorry about not being clear in my first post. I believe that I’ve followed the instruction now, but I still think that the fact that Nordpool publish 24 values and solcast publish 48 values cause a problem. Please bear with me.
After stumbling a bit on the syntax in Studio Code Server I now have the following shell commands:
dayahead_optim:
'curl -i -H ''Content-Type: application/json'' -X POST -d ''{"load_cost_forecast":{{(
(state_attr(''sensor.nordpool_kwh_se3_sek_3_10_025'', ''raw_tomorrow'')|map(attribute=''value'')|list)[:24])
}},"prod_price_forecast":{{(
(state_attr(''sensor.nordpool_kwh_se3_sek_3_10_025'', ''raw_tomorrow'')|map(attribute=''value'')|list)[:24])}}}'' http://localhost:5000/action/dayahead-optim'
mpc_optim:
'curl -i -H "Content-Type: application/json" -X POST -d ''{"load_cost_forecast":{{(
(state_attr(''sensor.nordpool_kwh_se3_sek_3_10_025'', ''raw_tomorrow'')|map(attribute=''value'')|list)[:24])
}}, "prod_price_forecast":{{(
(state_attr(''sensor.nordpool_kwh_se3_sek_3_10_025'', ''raw_tomorrow'')|map(attribute=''value'')|list)[:24])
}}, "pv_power_forecast":{{states(''sensor.solcast_24hrs_forecast'')
}}, "prediction_horizon":48,"soc_init":{{(states(''sensor.r2_d2_battery_level'')|float(0))/100
}},"soc_final":0.05,"def_total_hours":[2]}'' http://localhost:5000/action/naive-mpc-optim'
publish_data: "curl -i -H 'Content-Type:application/json' -X POST -d '{}' http://localhost:5000/action/publish-data"
dayahead_optim and publish_data both execute sucessfully, but mpc_optim generate the following log trace in the EMHASS add-on:
[2022-09-12 22:57:35,264] INFO in command_line: Setting up needed data
[2022-09-12 22:57:35,272] INFO in retrieve_hass: Retrieve hass get data method initiated...
[2022-09-12 22:57:36,221] INFO in forecast: Retrieving weather forecast data using method = list
[2022-09-12 22:57:36,231] INFO in forecast: Retrieving data from hass for load forecast using method = naive
[2022-09-12 22:57:36,233] INFO in retrieve_hass: Retrieve hass get data method initiated...
[2022-09-12 22:57:39,148] ERROR in app: Exception on /action/naive-mpc-optim [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 2525, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1822, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1820, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1796, 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 134, in action_call
input_data_dict = set_input_data_dict(config_path, str(config_path.parent), costfun,
File "/usr/local/lib/python3.9/dist-packages/emhass/command_line.py", line 112, in set_input_data_dict
df_input_data_dayahead = copy.deepcopy(df_input_data_dayahead)[df_input_data_dayahead.index[0]:df_input_data_dayahead.index[prediction_horizon-1]]
File "/usr/local/lib/python3.9/dist-packages/pandas/core/indexes/base.py", line 5039, in __getitem__
return getitem(key)
File "/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/datetimelike.py", line 341, in __getitem__
"Union[DatetimeLikeArrayT, DTScalarOrNaT]", super().__getitem__(key)
File "/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/_mixins.py", line 272, in __getitem__
result = self._ndarray[key]
IndexError: index 47 is out of bounds for axis 0 with size 24
- Is there a way to use MPC together with data from Nordpool? Should I be using a different service for pv_power_forecast with 60 minute intervals?
- Is it sufficient to only use dayahead_optim once a day and then publish every 5 minutes?
- Does anybody have good example how to control battery based on sensor.p_batt_forecast?
Cheers, Per Takman