EMHASS: An Energy Management for Home Assistant

Running normally:


Interesting behaviour overnight? Have to disable EMHASS control over the battery and manage manually for the day until it recovers. Battery has gone to 0% as well which is unusual.

Is there a problem with def_total_hours or P_deferrable_nom being 0?
I’m disabling deferable loads by zeroing these variables.

{
  "prod_price_forecast": {{
    ([states('sensor.cecil_st_feed_in_price')|float(0)] +
    (state_attr('sensor.cecil_st_feed_in_forecast', 'forecasts')|map(attribute='per_kwh')|list))
    | tojson 
  }},
  "load_cost_forecast": {{
    ([states('sensor.cecil_st_general_price')|float(0)] + 
    state_attr('sensor.cecil_st_general_forecast', 'forecasts') |map(attribute='per_kwh')|list) 
    | tojson 
  }},
  "pv_power_forecast": {{
    ([states('sensor.sonnenbatterie_84324_production_w')|int(0)] +
    state_attr('sensor.solcast_pv_forecast_forecast_today', 'detailedForecast')|selectattr('period_start','gt',utcnow()) | map(attribute='pv_estimate')|map('multiply',1000)|map('int')|list +
    state_attr('sensor.solcast_pv_forecast_forecast_tomorrow', 'detailedForecast')|selectattr('period_start','gt',utcnow()) | map(attribute='pv_estimate')|map('multiply',1000)|map('int')|list
    )| tojson
  }},
  "prediction_horizon": {{
    min(48, (state_attr('sensor.cecil_st_feed_in_forecast', 'forecasts')|map(attribute='per_kwh')|list|length)+1)
  }},
  "num_def_loads": 2,
  "def_total_hours": [
    {%- if states('sensor.cecil_st_feed_in_price') | float(0) > 0 -%}
      0
    {%- elif is_state('sensor.season', 'winter') -%}
      2
    {%- elif is_state('sensor.season', 'summer') -%}
      4
    {%- else -%}
      3
    {%- endif -%},
    {%- if is_state('device_tracker.ynot_location_tracker', ['home']) -%}
      {%- if is_state('binary_sensor.ynot_charger', ['on']) -%}
        {{ ((90-(states('sensor.ynot_battery')|int(0)))/30*3)|int(0) }}
      {%- else -%} 
        0
      {%- endif -%}
    {%- else -%} 
      0
    {%- endif -%}
    ],
  "P_deferrable_nom": [1150, {{ (states('input_number.ev_amps') | int(0) * 230)|int(0) }}],
  "treat_def_as_semi_cont": [1, 0],
  "set_def_constant": [0, 0],
  "soc_init": {{ (states('sensor.sonnenbatterie_84324_state_charge_user')|int(0))/100 }},
  "soc_final": 0.03,
  "alpha": 0.25,
  "beta": 0.75
}
{
  "prod_price_forecast": [0.04, 0.1, 0.01, -0.03, -0.03, -0.03, -0.04, -0.03, 0.04, 0.32, 0.32, 0.32, 0.33, 0.22, 0.22, 0.27, 0.27, 0.3, 0.34, 0.35, 0.43, 0.18, 0.18, 0.15, 0.15, 0.15, 0.12, 0.09, 0.09, 0.09, 0.11, 0.09, 0.09, 0.09, 0.09, 0.08, 0.08, 0.09, 0.09],
  "load_cost_forecast": [0.14, 0.23, 0.13, 0.08, 0.08, 0.08, 0.07, 0.08, 0.15, 0.41, 0.41, 0.4, 0.42, 0.3, 0.3, 0.35, 0.36, 0.39, 0.43, 0.44, 0.53, 0.29, 0.29, 0.26, 0.25, 0.26, 0.23, 0.2, 0.2, 0.2, 0.21, 0.2, 0.2, 0.2, 0.19, 0.18, 0.18, 0.19, 0.19],
  "pv_power_forecast": [1161, 2692, 2765, 2683, 2461, 2322, 2186, 2236, 2380, 2455, 2504, 2513, 2517, 2393, 2145, 1782, 1345, 933, 529, 171, 41, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 73, 278, 567, 875, 1182, 1465, 1721, 1935, 2139, 2356, 2538, 2653, 2783, 2923, 3065, 3124, 3089, 3042, 2936, 2730, 2553, 2386, 1971, 1413, 944, 517, 172, 36, 0, 0, 0, 0, 0, 0, 0, 0],
  "prediction_horizon": 39,
  "num_def_loads": 2,
  "def_total_hours": [0,0],
  "P_deferrable_nom": [1150, 7360],
  "treat_def_as_semi_cont": [1, 0],
  "set_def_constant": [0, 0],
  "soc_init": 0.08,
  "soc_final": 0.03,
  "alpha": 0.25,
  "beta": 0.75
})

Hi, I don’t understand what went wrong there. But definetly it is not a problem to set some of those def_total_hours to zero, I do this everyday. However did you set them all to zero at some point? That may be problematic.

Both def_total_hours for the two deferable loads can be zero at the same time and P_deferrable_nom for the second load (EV charging) can be zero at the same time. But the first P_deferrable_nom (static pool pump load) is always 1150W.

Also they can vary throughout the day depending on weather and tariff and if the car is at home or not.

"def_total_hours": [0,0],
"P_deferrable_nom": [1150, 0],
"def_total_hours": [
    {%- if states('sensor.cecil_st_feed_in_price') | float(0) > 0 -%}
      0
    {%- elif is_state('sensor.season', 'winter') -%}
      2
    {%- elif is_state('sensor.season', 'summer') -%}
      4
    {%- else -%}
      3
    {%- endif -%},
    {%- if is_state('device_tracker.ynot_location_tracker', ['home']) -%}
      {%- if is_state('binary_sensor.ynot_charger', ['on']) -%}
        {{ ((90-(states('sensor.ynot_battery')|int(0)))/30*3)|int(0) }}
      {%- else -%} 
        0
      {%- endif -%}
    {%- else -%} 
      0
    {%- endif -%}
    ],
  "P_deferrable_nom": [1150, {{ (states('input_number.ev_amps') | int(0) * 230)|int(0) }}]

It’s functioning correctly now. This has happened once before. I just manage manually or switch to dayahead.

I’ve just published a new add-on version v0.5.0 with a bunch of nice improvements and fixes.

Most notably we are now able to get the optimization status as a sensor in: sensor.optim_status

See the complete list of improvements and fixes in the CHANGELOG.

:partying_face:

4 Likes

I get Permission denied with Emhass addon 0.5.0.
Hassos 2023.12.3
Supervisor 2023.11.6
Home Assistant Yellow

Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.9/dist-packages/emhass/web_server.py", line 15, in <module>
    from emhass.command_line import set_input_data_dict
  File "/usr/local/lib/python3.9/dist-packages/emhass/command_line.py", line 20, in <module>
    from emhass.forecast import forecast
  File "/usr/local/lib/python3.9/dist-packages/emhass/forecast.py", line 15, in <module>
    import pvlib
  File "/usr/local/lib/python3.9/dist-packages/pvlib/__init__.py", line 3, in <module>
    from pvlib import (  # noqa: F401
  File "/usr/local/lib/python3.9/dist-packages/pvlib/clearsky.py", line 14, in <module>
    import h5py
  File "/usr/lib/python3/dist-packages/h5py/__init__.py", line 21, in <module>
    from . import _debian_h5py_serial as _h5py
  File "/usr/lib/python3/dist-packages/h5py/_debian_h5py_serial/__init__.py", line 46, in <module>
    from ._conv import register_converters as _register_converters
  File "h5py/_debian_h5py_serial/_conv.pyx", line 1, in init h5py._debian_h5py_serial._conv
  File "h5py/_debian_h5py_serial/h5t.pyx", line 293, in init h5py._debian_h5py_serial.h5t
  File "/usr/local/lib/python3.9/dist-packages/numpy/__init__.py", line 333, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'typeDict'
s6-supervise emhass: warning: unable to spawn ./finish: Permission denied
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.9/dist-packages/emhass/web_server.py", line 15, in <module>
    from emhass.command_line import set_input_data_dict
  File "/usr/local/lib/python3.9/dist-packages/emhass/command_line.py", line 20, in <module>
    from emhass.forecast import forecast
  File "/usr/local/lib/python3.9/dist-packages/emhass/forecast.py", line 15, in <module>
    import pvlib
  File "/usr/local/lib/python3.9/dist-packages/pvlib/__init__.py", line 3, in <module>
    from pvlib import (  # noqa: F401
  File "/usr/local/lib/python3.9/dist-packages/pvlib/clearsky.py", line 14, in <module>
    import h5py
  File "/usr/lib/python3/dist-packages/h5py/__init__.py", line 21, in <module>
    from . import _debian_h5py_serial as _h5py
  File "/usr/lib/python3/dist-packages/h5py/_debian_h5py_serial/__init__.py", line 46, in <module>
    from ._conv import register_converters as _register_converters
  File "h5py/_debian_h5py_serial/_conv.pyx", line 1, in init h5py._debian_h5py_serial._conv
  File "h5py/_debian_h5py_serial/h5t.pyx", line 293, in init h5py._debian_h5py_serial.h5t
  File "/usr/local/lib/python3.9/dist-packages/numpy/__init__.py", line 333, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'typeDict'
s6-supervise emhass: warning: unable to spawn ./finish: Permission denied
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.9/dist-packages/emhass/web_server.py", line 15, in <module>
    from emhass.command_line import set_input_data_dict
  File "/usr/local/lib/python3.9/dist-packages/emhass/command_line.py", line 20, in <module>
    from emhass.forecast import forecast
  File "/usr/local/lib/python3.9/dist-packages/emhass/forecast.py", line 15, in <module>
    import pvlib
  File "/usr/local/lib/python3.9/dist-packages/pvlib/__init__.py", line 3, in <module>
    from pvlib import (  # noqa: F401
  File "/usr/local/lib/python3.9/dist-packages/pvlib/clearsky.py", line 14, in <module>
    import h5py
  File "/usr/lib/python3/dist-packages/h5py/__init__.py", line 21, in <module>
    from . import _debian_h5py_serial as _h5py
  File "/usr/lib/python3/dist-packages/h5py/_debian_h5py_serial/__init__.py", line 46, in <module>
    from ._conv import register_converters as _register_converters
  File "h5py/_debian_h5py_serial/_conv.pyx", line 1, in init h5py._debian_h5py_serial._conv
  File "h5py/_debian_h5py_serial/h5t.pyx", line 293, in init h5py._debian_h5py_serial.h5t
  File "/usr/local/lib/python3.9/dist-packages/numpy/__init__.py", line 333, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'typeDict'
s6-supervise emhass: warning: unable to spawn ./finish: Permission denied
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.9/dist-packages/emhass/web_server.py", line 15, in <module>
    from emhass.command_line import set_input_data_dict
  File "/usr/local/lib/python3.9/dist-packages/emhass/command_line.py", line 20, in <module>
    from emhass.forecast import forecast
  File "/usr/local/lib/python3.9/dist-packages/emhass/forecast.py", line 15, in <module>
    import pvlib
  File "/usr/local/lib/python3.9/dist-packages/pvlib/__init__.py", line 3, in <module>
    from pvlib import (  # noqa: F401
  File "/usr/local/lib/python3.9/dist-packages/pvlib/clearsky.py", line 14, in <module>
    import h5py
  File "/usr/lib/python3/dist-packages/h5py/__init__.py", line 21, in <module>
    from . import _debian_h5py_serial as _h5py
  File "/usr/lib/python3/dist-packages/h5py/_debian_h5py_serial/__init__.py", line 46, in <module>
    from ._conv import register_converters as _register_converters
  File "h5py/_debian_h5py_serial/_conv.pyx", line 1, in init h5py._debian_h5py_serial._conv
  File "h5py/_debian_h5py_serial/h5t.pyx", line 293, in init h5py._debian_h5py_serial.h5t
  File "/usr/local/lib/python3.9/dist-packages/numpy/__init__.py", line 333, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'typeDict'
s6-supervise emhass: warning: unable to spawn ./finish: Permission denied
1 Like

Same here.

Somehow the tests did not catched this. It will be fixed soon.

1 Like

Same here, but I’m sure there will be a quick fix by David.
Many thanks for all your effort in this project. It works like a charm even with a small failure now and then!!

1 Like

Same issue.

  • Core 2023.12.3
  • Supervisor 2023.11.6
  • Operating System11.2
  • Frontend 20231208.2

Hardware Generic x86-64

AttributeError: module ‘numpy’ has no attribute ‘typeDict’
s6-supervise emhass: warning: unable to spawn ./finish: Permission denied

Too soon… It’s again not functioning. Really frustrating. Used Emhass without any problems for months and suddenly it seems my load sensor is acting up.

Did you ever find out what caused the issue on your end @rcruikshank ? You simply purged the database or did you build a new template sensor?

@RT1080 I ended up deleting my recorder database altogether. I had to wait two days before I could run a nieve calculation again.

This got rid of the issue I had with rebooting the system where the nieve method would not work for two days after a reboot.

It quickly built up to 2.5Gb again so I’ve started filtering it with an include configuration. At least I can reboot the system without having to change to a dayahead method.

The problems should be normally solved, upgrade to add-on v0.5.2 when it is available.

2 Likes

Upgrade successful (using the add-on). Thanks.

I performed a few tests:

  • I ran MPC and it’s working ok.
  • I ran ML model_fit and strangely I got an error on the passed data history. A few days ago I discovered I could pass no more than 20 days, even if the recorder was previously set to 21. I increased the recorder retention to 22. Today I was trying again with 20 but got an error. I’ve discovered that as of today the threshold has become 14. I’m wondering if this is related to some similar situations reported by others before (they had to wait 2 days or so)
2023-12-18 09:52:54,486 - web_server - INFO - Setting up needed data
2023-12-18 09:52:54,488 - web_server - INFO - Retrieve hass get data method initiated...
2023-12-18 09:52:54,501 - web_server - ERROR - The retrieved JSON is empty, check that correct day or variable names are passed
2023-12-18 09:52:54,501 - web_server - ERROR - Either the names of the passed variables are not correct or days_to_retrieve is larger than the recorded history of your sensor (check your recorder settings)
2023-12-18 09:52:54,501 - web_server - ERROR - Exception on /action/forecast-model-fit [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 1455, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 869, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 867, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 852, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/emhass/web_server.py", line 179, in action_call
    input_data_dict = set_input_data_dict(config_path, str(data_path), costfun,
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/emhass/command_line.py", line 146, in set_input_data_dict
    rh.get_data(days_list, var_list)
  File "/usr/local/lib/python3.11/dist-packages/emhass/retrieve_hass.py", line 150, in get_data
    self.df_final = pd.concat([self.df_final, df_day], axis=0)
                                              ^^^^^^
UnboundLocalError: cannot access local variable 'df_day' where it is not associated with a value
  • I tried ML model_tune using 14 days and it worked
  • I tried day_ahead and it worked

I seem to have the same error. How can I change that value for the ML model? I’ve just started with Emhass last weekend and still am figuring things out.

In your command you can declare how many days of data should be used: days_to_retrieve parameter

I can’t get ML to work, same error as above. Naive does work. Can it be something with the sensor? I waited two days like I found on the forum but maybe the time has to be longer for ML?

How many days of data do you retain in your recorder? How many days are you telling EMHASS to use for ML?

And now, a new day, after midnight, the threshold is 15 (with 16 I get the error). Yesterday it was 14. Recorder always set to 22 days of retention.

I am trying to set two days because the sensor is working since saturday evening.