Hi this looks exact as my setup.
Can you share your config ?
Hello,
I am trying to run EMHASS in docker but cannot get it to connect to home assistant.
Home assistant is also running in its own docker container and working well.
I get EMHASS running but when I try to do a day ahead optimization I get the error message: ⢠ERROR - web_server - Unable to access Home Assistance instance, check URL.
What I have done this far:
- I have created a section for emhass in my docker compose file in which home assistant is also defined.
- I have added and modified the config_emhass.yaml and secrets_emhass.yaml files.
- I have a very long token from HA that I have inserted in the sercrets_emhass.yaml file.
- In the EMHASS volume DATA-folder there is a actionLogs.txt which writes out that it tries to connect to HA at the same adress written in the secrets file so it seems to read the file at least.
The docker compose configuration looks like:
emhass:
image: davidusb/emhass-docker-standalone
container_name: emhass
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Stockholm
- LOCAL_COSTFUN="profit"
volumes:
- /localshare/emhass/config_emhass.yaml:/app/config_emhass.yaml
- /localshare/emhass/secrets_emhass.yaml:/app/secrets_emhass.yaml
- /localshare/emhass/data:/app/data
- /localshare/emhass/config.json:/share/config.json
ports:
- 5000:5000
I canât find any example of how the docker compose configuration should look but have tried following the EMHASS documentation.
The secrets_emhass.yaml looks like:
hass_url: http://192.168.1.100:8123
long_lived_token: *VERY LONG STRING OF CHARACTERS*
time_zone: Europe/Paris
lat: 45.83
lon: 6.86
alt: 4807.8
solcast_api_key: yoursecretsolcastapikey
solcast_rooftop_id: yourrooftopid
solar_forecast_kwp: 5
Have any of you tried running the same configuration that I am doing and know what I am doing wrong?
Typically in your case properly defining these should be enough.
Try going inside the emhass docker container while running and try to ping your HA URL from there. If you are able to ping then there could a problem with the token.
Do you have EMHASS setup already?
Yes, but not sure about the config.
can you share your config.json ?
I canât get any further with the MPC optimization. Day Ahead is running⌠Does anyone have any ideas?
web_server INFO Obtaining parameters from config.json:
web_server DEBUG Obtaining secrets from Home Assistant Supervisor API
2024-11-06 09:54:54,083 - web_server - INFO - Launching the emhass webserver at: http://0.0.0.0:5000
2024-11-06 09:54:54,083 - web_server - INFO - Home Assistant data fetch will be performed using url: http://supervisor/core/api
2024-11-06 09:54:54,083 - web_server - INFO - The data path is: /share
2024-11-06 09:54:54,083 - web_server - INFO - The logging is: DEBUG
2024-11-06 09:54:54,085 - web_server - INFO - Using core emhass version: 0.11.2
waitress INFO Serving on http://0.0.0.0:5000
2024-11-06 09:55:14,367 - web_server - INFO - EMHASS server online, serving index.html...
2024-11-06 09:55:14,372 - web_server - INFO - The data container dictionary is empty... Please launch an optimization task
2024-11-06 09:55:16,703 - web_server - INFO - Passed runtime parameters: {}
2024-11-06 09:55:16,703 - web_server - INFO - >> Setting input data dict
2024-11-06 09:55:16,703 - web_server - INFO - Setting up needed data
2024-11-06 09:55:16,726 - web_server - INFO - Retrieving weather forecast data using method = scrapper
2024-11-06 09:55:17,923 - web_server - INFO - Retrieving data from hass for load forecast using method = naive
2024-11-06 09:55:17,924 - web_server - INFO - Retrieve hass get data method initiated...
2024-11-06 09:55:17,934 - web_server - DEBUG - sensor:sensor.s10x_leistung_11 retrieved Dataframe count: 7, on day: 2024-11-03 08:00:00+00:00. This is less than freq value passed: 0 days 00:30:00
2024-11-06 09:55:17,953 - web_server - DEBUG - sensor:sensor.s10x_leistung_11 retrieved Dataframe count: 1, on day: 2024-11-04 08:00:00+00:00. This is less than freq value passed: 0 days 00:30:00
2024-11-06 09:55:18,508 - web_server - INFO - >> Performing dayahead optimization...
2024-11-06 09:55:18,508 - web_server - INFO - Performing day-ahead forecast optimization
2024-11-06 09:55:18,510 - web_server - INFO - Perform optimization for the day-ahead
2024-11-06 09:55:18,563 - web_server - DEBUG - Deferrable load 0: Proposed optimization window: 0 --> 0
2024-11-06 09:55:18,563 - web_server - DEBUG - Deferrable load 0: Validated optimization window: 0 --> 0
2024-11-06 09:55:18,635 - web_server - INFO - Status: Infeasible
2024-11-06 09:55:18,636 - web_server - INFO - Total value of the Cost function = -5745.65
2024-11-06 09:55:18,996 - web_server - INFO - >> Sending rendered template table data
2024-11-06 09:55:26,299 - web_server - INFO - serving configuration.html...
2024-11-06 09:55:26,418 - web_server - DEBUG - Obtaining current saved parameters as config
2024-11-06 09:55:26,418 - web_server - INFO - Obtaining parameters from config.json:
2024-11-06 09:55:26,419 - web_server - DEBUG - Converting param to config
2024-11-06 09:55:30,609 - web_server - INFO - EMHASS server online, serving index.html...
2024-11-06 09:55:35,512 - web_server - INFO - Passed runtime parameters: {}
2024-11-06 09:55:35,512 - web_server - INFO - >> Setting input data dict
2024-11-06 09:55:35,512 - web_server - INFO - Setting up needed data
2024-11-06 09:55:35,516 - web_server - INFO - Retrieve hass get data method initiated...
2024-11-06 09:55:35,989 - web_server - ERROR - Exception on /action/naive-mpc-optim [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 1473, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 880, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/emhass/web_server.py", line 325, in action_call
input_data_dict = set_input_data_dict(emhass_conf, costfun,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/emhass/command_line.py", line 155, in set_input_data_dict
if not rh.prepare_data(retrieve_hass_conf['sensor_power_load_no_var_loads'],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/emhass/retrieve_hass.py", line 285, in prepare_data
self.df_final[new_var_replace_zero] = self.df_final[
^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/pandas/core/frame.py", line 3767, in __getitem__
indexer = self.columns._get_indexer_strict(key, "columns")[1]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/pandas/core/indexes/base.py", line 5877, in _get_indexer_strict
self._raise_if_missing(keyarr, indexer, axis_name)
File "/usr/local/lib/python3.11/dist-packages/pandas/core/indexes/base.py", line 5938, in _raise_if_missing
raise KeyError(f"None of [{key}] are in the [{axis_name}]")
KeyError: "None of [Index([''], dtype='object')] are in the [columns]"
Hi, have installed v0.11.2, when I change costfun to profit, the optimization calculation returns still cost_fun_selfcon, so if you change the setting in the config from self-consumption to profit, it does reflect in the config but not in the optimization calculation.
I just integrate EMHASS to OpenHEMS. EMHASS give the optimization plan, and OpenHEMS apply it throw Home-Assistant.
Looks like the result from your Dayahead is already Infeasible. I donât see any runtime parameters passed either.
Edit: Looks like my HA Supervisor was just updated and now Iâm unable to check the add-on log, the error is:
Failed to get 5b918bf2_emhass logs, e.callApiRaw is not a function
It looks like it affects all add-on. Upgrading to the new HA Core (Beta) should fix it.
Add-on logs can also be viewed via Settings â System â Logs > EMHASS
Updated today by accident and thought wth Iâll try. Problems are encountered immediately when I run my MPC. Havenât read everything about the upgrade but is there anything that needs to be changed in my MPC call?
post_naive_mpc_shell_nocar: >
curl -i -H "Content-Type: application/json" -X POST -d '{
"load_cost_forecast":{{((state_attr("sensor.nordpool_tibber", "raw_today") | map(attribute="value") | list + state_attr("sensor.nordpool_tibber", "raw_tomorrow") | map(attribute="value") | list))[now().hour:][:24] }},
"prod_price_forecast":{{((state_attr("sensor.nordpool_tibber", "raw_today") | map(attribute="value") | list + state_attr("sensor.nordpool_tibber", "raw_tomorrow") | map(attribute="value") | list))[now().hour:][:24] }},
"prediction_horizon":{{min(24, (((state_attr("sensor.nordpool_tibber", "raw_today")|map(attribute="value")|list + state_attr("sensor.nordpool_tibber", "raw_tomorrow") | map(attribute="value")| list)[now().hour:][:24]|list|length)))}},
"pv_power_forecast":{{([states("sensor.inverter_input_power")|int(0)] + state_attr("sensor.solcast_pv_forecast_forecast_today", "detailedHourly")|selectattr("period_start","gt",utcnow()) | map(attribute="pv_estimate")|map("multiply",1000)|map("int")|list + state_attr("sensor.solcast_pv_forecast_forecast_tomorrow", "detailedHourly")|selectattr("period_start","gt",utcnow()) | map(attribute="pv_estimate")|map("multiply",1000)|map("int")|list)| tojson}},
"load_power_forecast":{{[states('sensor.power_load_novar_loads')|int] +(states('input_text.fifo_buffer').split(',')|map('int')|list)[1:]}},
"soc_init":{{ max(0,states("sensor.battery_state_of_capacity")|int(0))/100 }},
"soc_final":{{ max(100,states("number.battery_end_of_discharge_soc")|int(0))/100 }},
"delta_forecast":2,
"alpha": 1,
"beta": 0,
"def_total_hours":[0, 0],
"def_end_timestep":[0, 0]
}' http://localhost:5000/action/naive-mpc-optim
I get this error in the log.
2024-11-07 08:11:32,606 - web_server - INFO - Passed runtime parameters: {'load_cost_forecast': [1.56, 1.31, 1.23, 1.2, 1.22, 1.19, 1.14, 1.49, 1.89, 2.77, 1.79, 1.62, 1.26, 1.18, 0.81, 0.71], 'prod_price_forecast': [1.56, 1.31, 1.23, 1.2, 1.22, 1.19, 1.14, 1.49, 1.89, 2.77, 1.79, 1.62, 1.26, 1.18, 0.81, 0.71], 'prediction_horizon': 16, 'pv_power_forecast': [198, 1271, 2156, 2883, 3248, 3643, 2835, 817, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 350, 1261, 2142, 2797, 3060, 2724, 2358, 522, 0, 0, 0, 0, 0, 0, 0, 0], 'load_power_forecast': [1311, 451, 824, 2670, 2349, 3070, 3956, 2976, 1939, 1292, 854, 2389, 730, 1162, 1354, 1122, 1418, 616, 1859, 1110, 1027, 1395, 763, 3006, 1168, 1970, 798, 1399, 1037, 1359, 1140, 914, 965, 1313, 1062, 947, 2476, 1638, 1203, 1677, 1272, 699, 1444, 1489, 775, 1549, 1216, 684], 'soc_init': 0.97, 'soc_final': 1.0, 'delta_forecast': 2, 'alpha': 1, 'beta': 0, 'def_total_hours': [0, 0], 'def_end_timestep': [0, 0]}
2024-11-07 08:11:32,607 - web_server - INFO - >> Setting input data dict
2024-11-07 08:11:32,607 - web_server - INFO - Setting up needed data
2024-11-07 08:11:32,609 - web_server - INFO - Retrieve hass get data method initiated...
2024-11-07 08:11:33,860 - web_server - ERROR - Exception on /action/naive-mpc-optim [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 1473, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 880, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/emhass/web_server.py", line 325, in action_call
input_data_dict = set_input_data_dict(emhass_conf, costfun,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/emhass/command_line.py", line 155, in set_input_data_dict
if not rh.prepare_data(retrieve_hass_conf['sensor_power_load_no_var_loads'],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/emhass/retrieve_hass.py", line 285, in prepare_data
self.df_final[new_var_replace_zero] = self.df_final[
^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/pandas/core/frame.py", line 3767, in __getitem__
indexer = self.columns._get_indexer_strict(key, "columns")[1]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/pandas/core/indexes/base.py", line 5877, in _get_indexer_strict
self._raise_if_missing(keyarr, indexer, axis_name)
File "/usr/local/lib/python3.11/dist-packages/pandas/core/indexes/base.py", line 5938, in _raise_if_missing
raise KeyError(f"None of [{key}] are in the [{axis_name}]")
KeyError: "None of [Index(['sensor.power_photovoltaics'], dtype='object')] are in the [columns]"
2024-11-07 08:11:35,882 - web_server - INFO - Passed runtime parameters: {}
2024-11-07 08:11:35,882 - web_server - INFO - >> Setting input data dict
2024-11-07 08:11:35,882 - web_server - INFO - Setting up needed data
2024-11-07 08:11:35,884 - web_server - INFO - >> Publishing data...
2024-11-07 08:11:35,884 - web_server - INFO - Publishing data to HASS instance
2024-11-07 08:11:35,894 - web_server - INFO - Successfully posted to sensor.p_pv_forecast = 162
2024-11-07 08:11:35,900 - web_server - INFO - Successfully posted to sensor.p_load_forecast = 2511.38
2024-11-07 08:11:35,906 - web_server - INFO - Successfully posted to sensor.p_hybrid_inverter = 2511.38
2024-11-07 08:11:35,912 - web_server - INFO - Successfully posted to sensor.p_deferrable0 = 0.0
2024-11-07 08:11:35,918 - web_server - INFO - Successfully posted to sensor.p_deferrable1 = 0.0
2024-11-07 08:11:35,924 - web_server - INFO - Successfully posted to sensor.p_batt_forecast = 2349.38
2024-11-07 08:11:35,930 - web_server - INFO - Successfully posted to sensor.soc_batt_forecast = 35.27
2024-11-07 08:11:35,936 - web_server - INFO - Successfully posted to sensor.p_grid_forecast = 0.0
2024-11-07 08:11:35,941 - web_server - INFO - Successfully posted to sensor.total_cost_fun_value = -2.97
2024-11-07 08:11:35,946 - web_server - INFO - Successfully posted to sensor.optim_status = Optimal
2024-11-07 08:11:35,952 - web_server - INFO - Successfully posted to sensor.unit_load_cost = 0.1907
2024-11-07 08:11:35,958 - web_server - INFO - Successfully posted to sensor.unit_prod_price = 0.065
@markpurcell did you find a (easy) way to get the Amber Advanced Price, whilst we wait for the native integration to be updated?
Yes, a breaking change, but not more difficult than properly filling those missing sensor names. Your shell command remains unchanged
I had to do excactly the same to make it work
Can someone give me an example of how to define a thermal load in the addon version. So how to write that in my configuration.yaml
It can not be written in a configuration.yaml
, you need to define the thermal load at runtime inside the shell command used to trigger the optimization.
A complete exemple is given here: https://emhass.readthedocs.io/en/latest/thermal_model.html#implementing-the-model
Be awared that this is a new and experimental feature, there is an open discussion here: https://github.com/davidusb-geek/emhass/discussions/340
Hi, maybe a stupid question, how to save the sensor.soc_batt_forecast from the day ahead optimisation to say dh_sensor.soc_batt_forecast? I can create a helper just to do this, but it would be overwritten each time when running MPC optimisation after the day ahead optimisation.
When you publish use the prefix functionality to save the computation results to a separate sensor.
But my shell command is in configuration.yaml. Isnât that correct?
Whatâs the right way to do it?
Your shell_command only prepares Home Assistant to make an API call to EMHASS. EMHASS requires triggering from a periodic automation of some kind to run and process data passed to it within the RESTfull API POST. immediately after processing the data passed to it you then have to POST a publish API call so that the result is passed back into Home Assistant as sensors. In the dayahead process you run it once in the morning and then repeatedly run the publish command to update the sensor in Home Assistant.
You can use shell_command (as you have done) or rest_command to set up these commands ready to use in an automation. But you will have to call the commands from an automation periodically to trigger EMHASS to do the calculation and then publish back into HA.
You can even use the curl command from the command line of another computer on your network. This is one way to test your system. Open a command prompt on Windows or a terminal session on a Mac or Linux system can try POSTing to the EMHASS IP address with the data dictionary structures.