EMHASS: An Energy Management for Home Assistant

They are service calls from the inverter integration, but before you try and automate see if you can do the steps by hand.

Go to DeveloperTools:Services and see if you have the inverter calls there, take a screen shot and upload here.

Try and set your SOC to 50% and see if your battery charges/ discharges, take a screen shot and upload here.

Ok.

1 Like

did this

service: huawei_solar.forcible_charge_soc
data:
  device_id: 211cc84b558327339aaf5be3398b95ae
  target_soc: 50
  power: "2500"

call service button gets green, wohoo

but wonā€™t discharge, soc 85%

Edit: used charge and not dischargeā€¦ changed and it starts to discharge

1 Like

alias: Battery SOC Forecast
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.soc_batt_forecast
condition: []
action:
  - service: huawei_solar.forcible_charge_soc
    data:
      value: "{{states('sensor.soc_batt_forecast')|int(0)}}"
    target:
      target_soc: 50
      power: 1000
      device_id: 211cc84b558327339aaf5be3398b95ae
mode: single

Gives me:

alias: Battery SOC Forecast
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.soc_batt_forecast
condition: []
action:
  - service: huawei_solar.forcible_charge_soc
    data:
      value: "127"
    target:
      target_soc: 50
      power: 1000
      device_id: 211cc84b558327339aaf5be3398b95ae
mode: single

And in Emhass value is 1.27

What does it mean?

Something is wrong with with your EMHASS values, your SOC forecast should be between 0-100.

Ok. Any idea where to start searching

Changed:

battery_minimum_state_of_charge: 0.1
battery_maximum_state_of_charge: 0.9

And got better soc but lost correct price
Will wait until tomorrow.

index P_PV P_Load P_deferrable0 P_grid_pos P_grid_neg P_grid P_batt SOC_opt unit_load_cost unit_prod_price cost_profit cost_fun_profit
2023-03-22 13:00:00+01:00 2237.953041 165.384615 0.0 0.00000 -2310.0684 -2310.06840 2.375000e+02 0.125 0.1907 0.065 0.118616 0.118616
2023-03-22 14:00:00+01:00 1999.001719 885.426087 0.0 3886.42440 0.0000 3886.42440 -5.000000e+03 0.600 0.1907 0.065 -0.168851 -0.168851
2023-03-22 15:00:00+01:00 1578.184188 664.651757 0.0 0.00000 -5663.5324 -5663.53240 4.750000e+03 0.100 0.1907 0.065 0.241381 0.241381
2023-03-22 16:00:00+01:00 1054.522182 4406.311953 0.0 8351.78980 0.0000 8351.78980 -5.000000e+03 0.575 0.1907 0.065 -0.840284 -0.840284
2023-03-22 17:00:00+01:00 465.808912 4129.830028 0.0 6558.75800 0.0000 6558.75800 -2.894737e+03 0.850 0.1907 0.065 -0.787559 -0.787559
2023-03-22 18:00:00+01:00 -37.039621 3118.666667 0.0 3155.70630 0.0000 3155.70630 -1.419222e-12 0.850 0.1907 0.065 -0.594730 -0.594730
2023-03-22 19:00:00+01:00 -3.000000 782.391304 0.0 0.00000 -3964.6087 -3964.60870 4.750000e+03 0.350 0.1907 0.065 0.108498 0.108498
2023-03-22 20:00:00+01:00 -3.000000 773.727273 0.0 5776.72730 0.0000 5776.72730 -5.000000e+03 0.825 0.1907 0.065 -0.147550 -0.147550
2023-03-22 21:00:00+01:00 -3.000000 767.620915 0.0 0.00000 -3979.3791 -3979.37910 4.750000e+03 0.325 0.1907 0.065 0.112274 0.112274
2023-03-22 22:00:00+01:00 -3.000000 785.449180 0.0 5788.44920 0.0000 5788.44920 -5.000000e+03 0.800 0.1907 0.065 -0.149785 -0.149785
2023-03-22 23:00:00+01:00 -3.000000 616.267123 0.0 0.00000 -4130.7329 -4130.73290 4.750000e+03 0.300 0.1907 0.065 0.150975 0.150975
2023-03-23 00:00:00+01:00 -3.000000 608.050000 0.0 5611.05000 0.0000 5611.05000 -5.000000e+03 0.775 0.1419 0.065 -0.086282 -0.086282
2023-03-23 01:00:00+01:00 -3.000000 601.036667 0.0 0.00000 -4145.9633 -4145.96330 4.750000e+03 0.275 0.1419 0.065 0.184201 0.184201
2023-03-23 02:00:00+01:00 -3.000000 1196.520000 0.0 6199.52000 0.0000 6199.52000 -5.000000e+03 0.750 0.1419 0.065 -0.169786 -0.169786
2023-03-23 03:00:00+01:00 -3.000000 620.220395 0.0 0.00000 -4126.7796 -4126.77960 4.750000e+03 0.250 0.1419 0.065 0.180231 0.180231
2023-03-23 04:00:00+01:00 -3.000000 575.281022 0.0 5578.28100 0.0000 5578.28100 -5.000000e+03 0.725 0.1419 0.065 -0.081632 -0.081632
2023-03-23 05:00:00+01:00 -3.000000 516.179661 0.0 0.00000 -4230.8203 -4230.82030 4.750000e+03 0.225 0.1419 0.065 0.201757 0.201757
2023-03-23 06:00:00+01:00 -3.000000 427.864865 0.0 5430.86490 0.0000 5430.86490 -5.000000e+03 0.700 0.1419 0.065 -0.060714 -0.060714
2023-03-23 07:00:00+01:00 193.269461 1033.854545 0.0 0.00000 -3909.4149 -3909.41490 4.750000e+03 0.200 0.1419 0.065 0.107408 0.107408
2023-03-23 08:00:00+01:00 790.878291 2034.093750 0.0 6243.21550 0.0000 6243.21550 -5.000000e+03 0.675 0.1419 0.065 -0.288638 -0.288638
2023-03-23 09:00:00+01:00 1349.363262 1121.258621 0.0 0.00000 -4978.1046 -4978.10460 4.750000e+03 0.175 0.1419 0.065 0.164470 0.164470
2023-03-23 10:00:00+01:00 1836.789840 2571.065527 0.0 734.27569 0.0000 734.27569 -1.596625e-12 0.175 0.1419 0.065 -0.364834 -0.364834
2023-03-23 11:00:00+01:00 2162.660019 3852.681690 0.0 6690.02170 0.0000 6690.02170 -5.000000e+03 0.650 0.1419 0.065 -0.546696 -0.546696
2023-03-23 12:00:00+01:00 2295.267132 3852.681690 0.0 0.00000 -3192.5854 -3192.58540 4.750000e+03 0.150 0.1907 0.065 -0.527188 -0.527188

Cost totals for latest optimization results

index Cost Totals
cost_profit -3.244718
cost_fun_profit -3.244718
1 Like

Trying to run optimization task but getting some errors I donā€™t know what they mean?

2023-03-23 00:10:57,646 - web_server - INFO - Setting up needed data
2023-03-23 00:10:57,857 - web_server - INFO - Retrieving weather forecast data using method = scrapper
2023-03-23 00:11:20,647 - 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 89, in set_input_data_dict
    df_weather = fcst.get_weather_forecast(method=optim_conf['weather_forecast_method'])
  File "/usr/local/lib/python3.9/dist-packages/emhass/forecast.py", line 195, in get_weather_forecast
    table = soup.find_all(id='day_0')[0]
IndexError: list index out of range

Having the same issue, no solution yet

Ok.
So if I run the optimization via webpage Iā€™ll lose the nordpool price but soc will be correct. Next time Iā€™ll run it via automation Iā€™ll lose soc but Nordpool will be correct

Reading through the most reason posts it looks like you are trying to call a service to set the target soc of your battery? Am I correct? Does your battery / inverter support this? I have a SolaX battery and inverter, and it doesnā€™t allow me to set a target or maximum- only what the minimum SoC should be.

Iā€™ve only started looking at EMHASS this morning so sorry if asking questions that may already have been answered.

Hi - running latest version of Emhass (0.3.7).
I am suddenly getting all sort of errors since midday today. Any idea what could be wrong?
Nothing got changed and data provided to Emhass looks good (only data I cannot see is the load forecast data).

Thanks


2023-03-25 22:15:05,407 - web_server - INFO - Setting up needed data
2023-03-25 22:15:05,413 - 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 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 64, in set_input_data_dict
    fcst = forecast(retrieve_hass_conf, optim_conf, plant_conf,
  File "/usr/local/lib/python3.9/dist-packages/emhass/forecast.py", line 160, in __init__
    self.forecast_dates = pd.date_range(start=self.start_forecast,
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/indexes/extension.py", line 95, in method
    result = attr(self._data, *args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/datetimelike.py", line 1775, in round
    return self._round(freq, RoundTo.NEAREST_HALF_EVEN, ambiguous, nonexistent)
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/datetimelike.py", line 1761, in _round
    return result.tz_localize(
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/_mixins.py", line 84, in method
    return meth(self, *args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/datetimes.py", line 1043, in tz_localize
    new_dates = tzconversion.tz_localize_to_utc(
  File "pandas/_libs/tslibs/tzconversion.pyx", line 328, in pandas._libs.tslibs.tzconversion.tz_localize_to_utc
pytz.exceptions.NonExistentTimeError: 2023-03-26 02:00:00
2023-03-25 22:15:25,391 - web_server - INFO - Setting up needed data
2023-03-25 22:15:25,397 - web_server - ERROR - Exception on /action/publish-data [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 64, in set_input_data_dict
    fcst = forecast(retrieve_hass_conf, optim_conf, plant_conf,
  File "/usr/local/lib/python3.9/dist-packages/emhass/forecast.py", line 160, in __init__
    self.forecast_dates = pd.date_range(start=self.start_forecast,
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/indexes/extension.py", line 95, in method
    result = attr(self._data, *args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/datetimelike.py", line 1775, in round
    return self._round(freq, RoundTo.NEAREST_HALF_EVEN, ambiguous, nonexistent)
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/datetimelike.py", line 1761, in _round
    return result.tz_localize(
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/_mixins.py", line 84, in method
    return meth(self, *args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/pandas/core/arrays/datetimes.py", line 1043, in tz_localize
    new_dates = tzconversion.tz_localize_to_utc(
  File "pandas/_libs/tslibs/tzconversion.pyx", line 328, in pandas._libs.tslibs.tzconversion.tz_localize_to_utc
pytz.exceptions.NonExistentTimeError: 2023-03-26 02:00:00

I am realizing that this is a daylight saving time problem. We will change hours tonight, so 2023-03-26 02:00:00 doesnā€™t exists. I do not deal with this in the code so it is normal that it fails. This will just happen one time a year because for the other time change in october the date will exist but duplicated, so no problem. But still Iā€™ll need to find a solution to this. Iā€™ll add it to the to do list.
So no solution for this for now, that MPC call will hopefully work as expected after 2 am.

Hi David,

I am running 0.3.7 of the addon.

I have spent some time trying to the get the load forecast ML working. I am seeing the following trace when running the ā€œfitā€ step. Maybe I donā€™t have enough historical data in the power load sensor? I have lowered the number of days to retrieve to match the amount of data.

Here is the shell commandā€¦

forecast_model_fit: 'curl -i -H ''Content-Type:application/json'' -X POST -d ''{"var_model": "sensor.load_with_no_var_loads", "days_to_retrieve": 3}'' http://localhost:5000/action/forecast-model-fit'

error in the log fileā€¦

2023-03-26 13:45:32,190 - web_server - INFO - Setting up needed data
2023-03-26 13:45:32,192 - web_server - INFO - Retrieve hass get data method initiated...
2023-03-26 13:45:32,463 - web_server - INFO -  >> Performing a machine learning forecast model fit...
2023-03-26 13:45:32,464 - web_server - INFO - Performing a forecast model fit for load_forecast
2023-03-26 13:45:32,468 - web_server - INFO - Training a KNeighborsRegressor model
2023-03-26 13:45:32,473 - web_server - ERROR - Exception on /action/forecast-model-fit [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 203, in action_call
    df_fit_pred, _, mlf = forecast_model_fit(input_data_dict, app.logger)
  File "/usr/local/lib/python3.9/dist-packages/emhass/command_line.py", line 311, in forecast_model_fit
    df_pred, df_pred_backtest = mlf.fit(split_date_delta=split_date_delta,
  File "/usr/local/lib/python3.9/dist-packages/emhass/machine_learning_forecaster.py", line 142, in fit
    self.forecaster.fit(y=self.data_train[self.var_model],
  File "/usr/local/lib/python3.9/dist-packages/skforecast/ForecasterAutoreg/ForecasterAutoreg.py", line 492, in fit
    residuals = y_train - self.regressor.predict(X_train)
  File "/usr/local/lib/python3.9/dist-packages/sklearn/neighbors/_regression.py", line 229, in predict
    neigh_ind = self.kneighbors(X, return_distance=False)
  File "/usr/local/lib/python3.9/dist-packages/sklearn/neighbors/_base.py", line 749, in kneighbors
    raise ValueError(
ValueError: Expected n_neighbors <= n_samples,  but n_samples = 4, n_neighbors = 5

Thanks. It is working again :slight_smile:

Great! :+1:
Still what a mess with the DST

The minimum number of days is hard coded to 15. So that canā€™t possibly work. The error message needs to be more explicit here. Iā€™ll work on that.
Change your recorder setting in Home Assistant and provide at least 15 days of data. But try to provide more for better accuracy.

1 Like

Default recorder is 10 days so EMHASS will have the problem on an ongoing basis with almost every new install.

Iā€™m just building my history out now to try. Will long term statistics be sufficient?

I recommend setting the default in EMHASS to 7 days, to cover most users and then include instructions on how to extend once it is working with 7 days.

1 Like

Ok for now I just placed a warning message in the docs here: The machine learning forecaster ā€” emhass 0.4.8 documentation
But yes it can be changed to default to 7 days.

1 Like

@davidusb So I just found out that I only get the status ā€œinfeasibleā€ and those unusaually high numbers for P_grid_pos and -_neg if I set a value for the deferrable load which is higher then 0.

Is something about ā€œdef_total_hoursā€:[0.59] wrong?

Thanks