EMHASS: An Energy Management for Home Assistant

Hi again

reinstalled every thing on a Generic x86-64
Managed to see webpage with some graphs.

Changed to 60 min.

but i still get errors when trying day a head and publishing the results.
final try if somebody could help me or i´ll ditch this project.

  - name: "power_photovoltaics"
    device_class: power
    state_class: measurement
    unit_of_measurement: "W"
    state: "{{ states('sensor.accumulated_production_siden')|float(0) * 1000 }}"
  
  - name: power_load_no_var_loads
    unit_of_measurement: W
    device_class: "power"
    value_template: >-
      {{states('sensor.accumulated_consumption_siden')|float(0)*1000}}
     #- states('sensor.pool_heatpump_power')|int(0)
     #- states('sensor.pool_pumps_power')|int(0) 
     #- states('sensor.hvac_power')|int(0)
     #- states('sensor.hws_power_2')|int(0)
     #- states('sensor.hpwc_power')|int(0)
  • binary_sensor:
    - name: “Luna2000”
    state: >-
    {{(states(‘sensor.power_photovoltaics’)|float(0)
    - states(‘sensor.power_load_no_var_loads’)|float(0))
    >= 5000 }}

shell_command:
publish_data: “curl -i -H “Content-Type:application/json” -X POST -d ‘{}’ http://localhost:5000/action/publish-data
trigger_nordpool_forecast: “curl -i -H “Content-Type: application/json” -X POST -d ‘{“load_cost_forecast”:{{((state_attr(‘sensor.nordpool_kwh_se4_sek_3_10_025’, ‘raw_today’) | map(attribute=‘value’) | list + state_attr(‘sensor.nordpool_kwh_se4_sek_3_10_025’, ‘raw_tomorrow’) | map(attribute=‘value’) | list))[now().hour:][:24] }},“prod_price_forecast”:{{((state_attr(‘sensor.nordpool_kwh_se4_sek_3_10_025’, ‘raw_today’) | map(attribute=‘value’) | list + state_attr(‘sensor.nordpool_kwh_se4_sek_3_10_025’, ‘raw_tomorrow’) | map(attribute=‘value’) | list))[now().hour:][:24]}}}’ http://localhost:5000/action/dayahead-optim


s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun emhass (no readiness notification)
s6-rc: info: service legacy-services successfully started
2023-03-11 16:47:20,194 - web_server - INFO - Launching the emhass webserver at: http://0.0.0.0:5000
2023-03-11 16:47:20,195 - web_server - INFO - Home Assistant data fetch will be performed using url: http://supervisor/core/api
2023-03-11 16:47:20,197 - web_server - INFO - The data path is: /share
2023-03-11 16:47:20,245 - web_server - INFO - Using core emhass version: 0.4.5
waitress INFO Serving on http://0.0.0.0:5000
2023-03-11 16:47:27,290 - web_server - INFO - EMHASS server online, serving index.html…
2023-03-11 16:47:41,429 - web_server - INFO - Setting up needed data
2023-03-11 16:47:41,984 - web_server - INFO - Retrieving weather forecast data using method = scrapper
2023-03-11 16:47:51,631 - web_server - INFO - Retrieving data from hass for load forecast using method = naive
2023-03-11 16:47:51,895 - web_server - INFO - Retrieve hass get data method initiated…
2023-03-11 16:48:25,153 - web_server - ERROR - Exception on /action/dayahead-optim [POST]
Traceback (most recent call last):
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 2528, in wsgi_app
response = self.full_dispatch_request()
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 1825, in full_dispatch_request
rv = self.handle_user_exception(e)
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 1823, in full_dispatch_request
rv = self.dispatch_request()
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 1799, 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 170, 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 91, in set_input_data_dict
P_load_forecast = fcst.get_load_forecast(method=optim_conf[‘load_forecast_method’])
File “/usr/local/lib/python3.9/dist-packages/emhass/forecast.py”, line 585, in get_load_forecast
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: “16512.0 - states(‘sensor.battery_charge_discharge_power’)|float(0)}}”
2023-03-11 16:48:51,392 - web_server - INFO - Setting up needed data
2023-03-11 16:48:51,409 - web_server - INFO - >> Publishing data…
2023-03-11 16:48:51,410 - web_server - INFO - Publishing data to HASS instance
2023-03-11 16:48:51,466 - web_server - ERROR - Exception on /action/publish-data [POST]
Traceback (most recent call last):
File “/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/datetimelike.py”, line 962, in _validate_frequency
raise ValueError
ValueError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 2528, in wsgi_app
response = self.full_dispatch_request()
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 1825, in full_dispatch_request
rv = self.handle_user_exception(e)
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 1823, in full_dispatch_request
rv = self.dispatch_request()
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 1799, 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
_ = publish_data(input_data_dict, app.logger)
File “/usr/local/lib/python3.9/dist-packages/emhass/command_line.py”, line 453, in publish_data
opt_res_latest.index.freq = input_data_dict[‘retrieve_hass_conf’][‘freq’]
File “/usr/local/lib/python3.9/dist-packages/pandas/core/indexes/extension.py”, line 78, in fset
setattr(self._data, name, value)
File “/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/datetimelike.py”, line 891, in freq
self._validate_frequency(self, value)
File “/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/datetimelike.py”, line 973, in _validate_frequency
raise ValueError(
ValueError: Inferred frequency 30T from passed values does not conform to passed frequency H

@nixtagangsta, I do not know if this helps but I want to share my emhass config which works for me:

I use this template for the “Power load no var loads” sensor. I see from your post you maybe have wrong template for your sensor.

      - name: "Power load no var loads"
        unique_id: fbfeef21-1aa3-4a54-b781-426f46fef597
        unit_of_measurement: "W"
        device_class: "power"
        state: >
          {% set powerload = states('sensor.power_adresse_xx') | float(default=0) %}
          {% set vvb = states('sensor.bryter_varmvannsbereder_electric_consumption_w') | float(default=0) %}
          {% set varmekabler = states('sensor.power_varmekabler') | float(default=0) %}
          {% set value = ( powerload - vvb - varmekabler) | round(1,default=0) %}
          {{ value }}

The shell_command I use for Nordpool is the same as the emhass documentation has:

shell_command:
  publish_data: "curl -i -H \"Content-Type: application/json\" -X POST -d '{}' http://localhost:5000/action/publish-data"

  trigger_nordpool_forecast: "curl -i -H \"Content-Type: application/json\" -X POST -d '{\"load_cost_forecast\":{{((state_attr('sensor.nordpool', 'raw_today') | map(attribute='value') | list  + state_attr('sensor.nordpool', 'raw_tomorrow') | map(attribute='value') | list))[now().hour:][:24] }},\"prod_price_forecast\":{{((state_attr('sensor.nordpool', 'raw_today') | map(attribute='value') | list  + state_attr('sensor.nordpool', 'raw_tomorrow') | map(attribute='value') | list))[now().hour:][:24]}}}' http://localhost:5000/action/dayahead-optim"

  trigger_nordpool_mpc: "curl -i -H \"Content-Type: application/json\" -X POST -d '{\"load_cost_forecast\":{{((state_attr('sensor.nordpool', 'raw_today') | map(attribute='value') | list + state_attr('sensor.nordpool', 'raw_tomorrow') | map(attribute='value') | list))[now().hour:][:24] }},\"prod_price_forecast\":{{((state_attr('sensor.nordpool', 'raw_today') | map(attribute='value') | list  + state_attr('sensor.nordpool', 'raw_tomorrow') | map(attribute='value') | list))[now().hour:][:24]}}, \"prediction_horizon\":6, \"def_total_hours\":[2,3,3,3,3,3,3,3]}' http://localhost:5000/action/naive-mpc-optim"

  trigger_entsoe_mpc: "curl -i -H \"Content-Type: application/json\" -X POST -d '{\"load_cost_forecast\":{{((state_attr('sensor.entsoe_average_electricity_price_today', 'prices_today') | map(attribute='price') | list + state_attr('sensor.entsoe_average_electricity_price_today', 'prices_tomorrow') | map(attribute='price') | list))[now().hour:][:24] }},\"prod_price_forecast\":{{((state_attr('sensor.entsoe_average_electricity_price_today', 'prices_today') | map(attribute='price') | list  + state_attr('sensor.entsoe_average_electricity_price_today', 'prices_tomorrow') | map(attribute='price') | list))[now().hour:][:24]}}, \"prediction_horizon\":6, \"def_total_hours\":[2,3,3,3,3,3,3,3]}' http://localhost:5000/action/naive-mpc-optim"

“Power load no var loads” must have more than two days with data. When importing the Nordpool prices it is best to do that before midnight. Nordpool has 24 hours with prices so the time to resample retrieved data from hass must be 60 in the config.
image

David helped my a lot with an error a few weeks ago. I documented my setup here in this github issue: Timed out running command when passing forecast data · Issue #37 · davidusb-geek/emhass-add-on · GitHub
Maybe it helps.

You get an error in the emhass log about a battery sensor sensor which report wrong data format. Maybe try without battery setting in emhass:

Thx. Yes i noticed the battery sensor but I did remove it from my configuration file but still shows up? Any idea why?

Sorry I do not now. If you uninstall emhass addon and install it again you should have a new fresh config.
The default emhass addon config is here: emhass-add-on/config.yml at e59fcc140bc8deb1d4e90bfbb685dfbf676b1767 · davidusb-geek/emhass-add-on · GitHub and here: emhass-add-on/config_emhass.yaml at e59fcc140bc8deb1d4e90bfbb685dfbf676b1767 · davidusb-geek/emhass-add-on · GitHub

I’ll reinstall once again.

Where do I find emhass config.yaml and config_emhass.yaml in home assistant?

The files are in the emhass docker. It is used when emhass addon is started up for the first time. It is overwritten when you use your own setting in the webinterface. I mention it because you maybe want to see the default emhass setting.

When you start up emhass for the first time change the sensor for PV power production and name of the sensor for load power without the deferreable load.
image

Change the time step to 60.
image

Save and take a restart of emhass addon. Do you get any errors in the emhass log now?

yes same errors as before
used yours shell command

dont know why i still get the sensor battery error, removed that line from config and deleted and
reinstalled emhass

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun emhass (no readiness notification)
s6-rc: info: service legacy-services successfully started
2023-03-11 23:21:47,492 - web_server - INFO - Launching the emhass webserver at: http://0.0.0.0:5000
2023-03-11 23:21:47,493 - web_server - INFO - Home Assistant data fetch will be performed using url: http://supervisor/core/api
2023-03-11 23:21:47,494 - web_server - INFO - The data path is: /share
2023-03-11 23:21:47,506 - web_server - INFO - Using core emhass version: 0.4.5
waitress INFO Serving on http://0.0.0.0:5000
2023-03-11 23:22:10,492 - web_server - INFO - Setting up needed data
2023-03-11 23:22:10,681 - web_server - INFO - Retrieving weather forecast data using method = scrapper
2023-03-11 23:22:16,261 - web_server - INFO - Retrieving data from hass for load forecast using method = naive
2023-03-11 23:22:16,264 - web_server - INFO - Retrieve hass get data method initiated…
2023-03-11 23:22:37,357 - web_server - ERROR - Exception on /action/dayahead-optim [POST]
Traceback (most recent call last):
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 2528, in wsgi_app
response = self.full_dispatch_request()
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 1825, in full_dispatch_request
rv = self.handle_user_exception(e)
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 1823, in full_dispatch_request
rv = self.dispatch_request()
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 1799, 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 170, 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 91, in set_input_data_dict
P_load_forecast = fcst.get_load_forecast(method=optim_conf[‘load_forecast_method’])
File “/usr/local/lib/python3.9/dist-packages/emhass/forecast.py”, line 585, in get_load_forecast
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: “16512.0 - states(‘sensor.battery_charge_discharge_power’)|float(0)}}”

Do not use the shell command for doing dayahead-optim. Keep it simple first. Only start up emhass. Do you get any errors in the emhass log now?

If you do not get any errors in the emhass error the problem is maybe in the shell_command.
The log says: 2023-03-11 23:22:37,357 - web_server - ERROR - Exception on /action/dayahead-optim [POST]
Can you post your shell_command?

1 Like

Hi. No errors when I start emhass

Using you shell command

You can access emhass webpage like this: http://<your_ip_for_hassos>:5000/
In the webpage you can push the button for Day-Ahead optimization

Do you get any error in the emhass log now?

Yes I get errors when I press day a head. No shell commands in configuration.yaml
Weird thing is that battery sensor is still showing even after I removed it from my template sensor

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun emhass (no readiness notification)
s6-rc: info: service legacy-services successfully started
2023-03-12 10:19:10,672 - web_server - INFO - Launching the emhass webserver at: http://0.0.0.0:5000
2023-03-12 10:19:10,673 - web_server - INFO - Home Assistant data fetch will be performed using url: http://supervisor/core/api
2023-03-12 10:19:10,674 - web_server - INFO - The data path is: /share
2023-03-12 10:19:10,706 - web_server - INFO - Using core emhass version: 0.4.5
waitress INFO Serving on http://0.0.0.0:5000
2023-03-12 10:26:50,475 - web_server - INFO - EMHASS server online, serving index.html…
2023-03-12 10:26:56,722 - web_server - INFO - Setting up needed data
2023-03-12 10:26:57,051 - web_server - INFO - Retrieving weather forecast data using method = scrapper
2023-03-12 10:27:04,393 - web_server - INFO - Retrieving data from hass for load forecast using method = naive
2023-03-12 10:27:04,412 - web_server - INFO - Retrieve hass get data method initiated…
2023-03-12 10:27:05,265 - web_server - ERROR - Exception on /action/dayahead-optim [POST]
Traceback (most recent call last):
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 2528, in wsgi_app
response = self.full_dispatch_request()
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 1825, in full_dispatch_request
rv = self.handle_user_exception(e)
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 1823, in full_dispatch_request
rv = self.dispatch_request()
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 1799, 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 170, 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 91, in set_input_data_dict
P_load_forecast = fcst.get_load_forecast(method=optim_conf[‘load_forecast_method’])
File “/usr/local/lib/python3.9/dist-packages/emhass/forecast.py”, line 585, in get_load_forecast
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: “16512.0 - states(‘sensor.battery_charge_discharge_power’)|float(0)}}”

Hi @davidusb

Thanks for the ML-functionality, I’ll dig into it.

Since 0.4 I get really high P_grid_pos and _neg values.
Also, the system does not start my deferrable load during the night which would be the cheapest option.

I don’t if this correlates between each other but could you tell my why that is?


Thanks!

Those p_grid_pos and p_grid_neg seems like there is a problem somewhere. Please recall me your config, what options are you using? What cost function are you using?

There is a constraint to forbidden grid injection and consumption at the same time. Check the logs, is your optimization status unfeasible?

Otherwise with your deferrable load I don’t see a problem. Your load cost seems more expensive during the night. So your deferrable is being activated when you get solar and at the beginning of the night when cost is low.

Sorry @nixtagangsta, but I’m out of suggestions for solutions to your problem. I hope you figure out your problem.

Ok Thx for your input.
I can run the publish shell command without error but I think I need to clear the cache or something because it’s complains about the battery sensor that I removed

I’m running it in docker on Synology DSM.

My config:

# Configuration file for EMHASS

retrieve_hass_conf:
  - freq: 30 # The time step to resample retrieved data from hass in minutes
  - days_to_retrieve: 5 # We will retrieve data from now and up to days_to_retrieve days
  - var_PV: 'sensor.power_ac_fronius_inverter_1_http_192_168_0_140' # Photovoltaic produced power sensor in Watts
  - var_load: 'sensor.power_load_without_variable_loads' # Household power consumption sensor in Watts (deferrable loads should be substracted)
  - load_negative: False # Set to True if the retrived load variable is negative by convention
  - set_zero_min: True # A special treatment for a minimum value saturation to zero. Values below zero are replaced by nans
  - var_replace_zero: # A list of retrived variables that we would want  to replace nans with zeros
    - 'sensor.power_ac_fronius_inverter_1_http_192_168_0_140'
  - var_interp: # A list of retrived variables that we would want to interpolate nan values using linear interpolation
    - 'sensor.power_ac_fronius_inverter_1_http_192_168_0_140'
    - 'sensor.power_load_without_variable_loads'
  - method_ts_round: 'first' # Set the method for timestamp rounding, options are: first, last and nearest

optim_conf:
  - set_use_battery: False # consider a battery storage
  - delta_forecast: 1 # days
  - num_def_loads: 1
  - P_deferrable_nom: # Watts
    - 643.0
  - def_total_hours: # hours
    - 5
  - treat_def_as_semi_cont: # treat this variable as semi continuous 
    - True
  - set_def_constant: # set as a constant fixed value variable with just one startup for each 24h
    - False
  - weather_forecast_method: 'scrapper' # options are 'scrapper' and 'csv'
  - load_forecast_method: 'naive' # options are 'csv' to load a custom load forecast from a CSV file or 'naive' for a persistance model
  - load_cost_forecast_method: 'hp_hc_periods' # options are 'hp_hc_periods' for peak and non-peak hours contracts and 'csv' to load custom cost from CSV file 
  - list_hp_periods: # list of different tariff periods (only needed if load_cost_forecast_method='hp_hc_periods')
    - period_hp_1:
      - start: '00:00'
      - end: '23:59'
  - load_cost_hp: 0.3 # peak hours load cost in €/kWh (only needed if load_cost_forecast_method='hp_hc_periods')
  - load_cost_hc: 0.3 # non-peak hours load cost in €/kWh (only needed if load_cost_forecast_method='hp_hc_periods')
  - prod_price_forecast_method: 'constant' # options are 'constant' for constant fixed value or 'csv' to load custom price forecast from a CSV file
  - prod_sell_price: 0.25 # power production selling price in €/kWh (only needed if prod_price_forecast_method='constant')
  - set_total_pv_sell: False # consider that all PV power is injected to the grid (self-consumption with total sell)
  - lp_solver: 'PULP_CBC_CMD' # set the name of the linear programming solver that will be used
#  - lp_solver_path: '/usr/bin/cbc' # set the path to the LP solver

plant_conf:
  - P_grid_max: 15000 # The maximum power that can be supplied by the utility grid in Watts
  - module_model: 'CSUN_Eurasia_Energy_Systems_Industry_and_Trade_CSUN295_60M' # The PV module model
  - inverter_model: 'Fronius_International_GmbH__Fronius_Primo_5_0_1_208_240__240V_' # The PV inverter model
  - surface_tilt: 45 # The tilt angle of your solar panels
  - surface_azimuth: 180 # The azimuth angle of your PV installation
  - modules_per_string: 8 # The number of modules per string
  - strings_per_inverter: 2 # The number of used strings per inverter
  - Pd_max: 1000 # If your system has a battery (set_use_battery=True), the maximum discharge power in Watts
  - Pc_max: 1000 # If your system has a battery (set_use_battery=True), the maximum charge power in Watts
  - eta_disch: 0.95 # If your system has a battery (set_use_battery=True), the discharge efficiency
  - eta_ch: 0.95 # If your system has a battery (set_use_battery=True), the charge efficiency
  - Enom: 5000 # If your system has a battery (set_use_battery=True), the total capacity of the battery stack in Wh
  - SOCmin: 0.3 # If your system has a battery (set_use_battery=True), the minimun allowable battery state of charge
  - SOCmax: 0.9 # If your system has a battery (set_use_battery=True), the minimun allowable battery state of charge
  - SOCtarget: 0.6 # If your system has a battery (set_use_battery=True), the desired battery state of charge at the end of each optimization cycle

The mps call is done via Node-Red and looks for example like this:

{"pv_power_forecast":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.55,25.05,75.14999999999999,203.45,355,496.25,659.4499999999999,898.85,1088,1173.2,1190.1,1094.75], "prod_price_forecast":[0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836,0.26836], "load_cost_forecast":[0.228821,0.228821,0.214594,0.214594,0.205337,0.205337,0.207314,0.207314,0.183818,0.183818,0.141967,0.141967,0.154512,0.154512,0.203038,0.203038,0.260054,0.260054,0.268966,0.268966,0.270968,0.270968,0.265221,0.265221,0.257211,0.257211,0.219687,0.219687,0.205843,0.205843], "prediction_horizon":30, "def_total_hours":[2.51], "alpha":1, "beta":0}

EDIT regarding the deferrable load: in my opinion it is starting deferrable loads when it is better to put all pv power back to grid. For example: prod_price at 0.26836 and load_cost at 0.205843

Thanks!

if i change to 60 min in emhass settings i get
2023-03-13 11:13:55,020 - web_server - INFO - EMHASS server online, serving index.html…
2023-03-13 11:15:00,430 - web_server - INFO - Setting up needed data
2023-03-13 11:15:00,632 - web_server - INFO - >> Publishing data…
2023-03-13 11:15:00,632 - web_server - INFO - Publishing data to HASS instance
2023-03-13 11:15:00,661 - web_server - ERROR - Exception on /action/publish-data [POST]
Traceback (most recent call last):
File “/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/datetimelike.py”, line 962, in _validate_frequency
raise ValueError
ValueError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 2528, in wsgi_app
response = self.full_dispatch_request()
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 1825, in full_dispatch_request
rv = self.handle_user_exception(e)
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 1823, in full_dispatch_request
rv = self.dispatch_request()
File “/usr/local/lib/python3.9/dist-packages/flask/app.py”, line 1799, 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
_ = publish_data(input_data_dict, app.logger)
File “/usr/local/lib/python3.9/dist-packages/emhass/command_line.py”, line 453, in publish_data
opt_res_latest.index.freq = input_data_dict[‘retrieve_hass_conf’][‘freq’]
File “/usr/local/lib/python3.9/dist-packages/pandas/core/indexes/extension.py”, line 78, in fset
setattr(self._data, name, value)
File “/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/datetimelike.py”, line 891, in freq
self._validate_frequency(self, value)
File “/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/datetimelike.py”, line 973, in _validate_frequency
raise ValueError(
ValueError: Inferred frequency 30T from passed values does not conform to passed frequency H