EMHASS: An Energy Management for Home Assistant

Any chance of more details from your supervisor logs?

          File "/tmp/pip-install-2gih2rmj/numpy_1441dd882a91498892b69d0ea99d79cc/setup.py", line 443, in <module>
            setup_package()
          File "/tmp/pip-install-2gih2rmj/numpy_1441dd882a91498892b69d0ea99d79cc/setup.py", line 435, in setup_package
            setup(**metadata)
          File "/tmp/pip-install-2gih2rmj/numpy_1441dd882a91498892b69d0ea99d79cc/numpy/distutils/core.py", line 171, in setup
            return old_setup(**new_attr)
          File "/usr/local/lib/python3.8/site-packages/setuptools/__init__.py", line 153, in setup
            return distutils.core.setup(**attrs)
          File "/usr/local/lib/python3.8/distutils/core.py", line 148, in setup
            dist.run_commands()
          File "/usr/local/lib/python3.8/distutils/dist.py", line 966, in run_commands
            self.run_command(cmd)
          File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
            cmd_obj.run()
          File "/tmp/pip-install-2gih2rmj/numpy_1441dd882a91498892b69d0ea99d79cc/numpy/distutils/command/install.py", line 62, in run
            r = self.setuptools_run()
          File "/tmp/pip-install-2gih2rmj/numpy_1441dd882a91498892b69d0ea99d79cc/numpy/distutils/command/install.py", line 36, in setuptools_run
            return distutils_install.run(self)
          File "/usr/local/lib/python3.8/distutils/command/install.py", line 545, in run
            self.run_command('build')
          File "/usr/local/lib/python3.8/distutils/cmd.py", line 313, in run_command
            self.distribution.run_command(command)
          File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
            cmd_obj.run()
          File "/tmp/pip-install-2gih2rmj/numpy_1441dd882a91498892b69d0ea99d79cc/numpy/distutils/command/build.py", line 47, in run
            old_build.run(self)
          File "/usr/local/lib/python3.8/distutils/command/build.py", line 135, in run
            self.run_command(cmd_name)
          File "/usr/local/lib/python3.8/distutils/cmd.py", line 313, in run_command
            self.distribution.run_command(command)
          File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
            cmd_obj.run()
          File "/tmp/pip-install-2gih2rmj/numpy_1441dd882a91498892b69d0ea99d79cc/numpy/distutils/command/build_src.py", line 142, in run
            self.build_sources()
          File "/tmp/pip-install-2gih2rmj/numpy_1441dd882a91498892b69d0ea99d79cc/numpy/distutils/command/build_src.py", line 153, in build_sources
            self.build_library_sources(*libname_info)
          File "/tmp/pip-install-2gih2rmj/numpy_1441dd882a91498892b69d0ea99d79cc/numpy/distutils/command/build_src.py", line 286, in build_library_sources
            sources = self.generate_sources(sources, (lib_name, build_info))
          File "/tmp/pip-install-2gih2rmj/numpy_1441dd882a91498892b69d0ea99d79cc/numpy/distutils/command/build_src.py", line 369, in generate_sources
            source = func(extension, build_dir)
          File "numpy/core/setup.py", line 669, in get_mathlib_info
            raise RuntimeError("Broken toolchain: cannot link a simple C program")
        RuntimeError: Broken toolchain: cannot link a simple C program
        [end of output]
  
    note: This error originates from a subprocess, and is likely not a problem with pip.
  error: legacy-install-failure
  
  × Encountered error while trying to install package.
  ╰─> numpy
  
  note: This is an issue with the package mentioned above, not pip.
  hint: See above for output from the failure.
  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.

error: subprocess-exited-with-error
× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
– See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.

Removing intermediate container 89876dbb4803

Same error here:

The command '/bin/sh -c apt-get update && apt-get install -y --no-install-recommends git && pip3 install --no-cache-dir -r requirements.txt' returned a non-zero code: 1

Running:
|core-2022.3.5|
|Home Assistant Supervised|

On a PI4

Ok, trying to solve this right now. I didn’t tested it on arm archs, just amd64 and it worked fine… I will try now to create a Dockerfile for multiple architectures, including PI4 arm’s…

Right. Could you please try now? I just pushed a new version with a quick fix that will hopefully overcome that Numpy installation problem. If the problem persists I will later switch to official hass docker images for each arch.

Fantastic project and I look forward to getting things running.

Version 0.1.16 loaded correctly on my odroid n2+, which is the same hardware as HA Blue so that is a start.

I am not currently on my local network, and access HA via Nabu Casa, so I presume I cannot access EMHASS, which makes control difficult outside of LAN. Interesting other Add-On’s can still access localhost, so there maybe a way around that I haven’t identifed.

I have multiple inverters with multiple strings pointing in different directions, which doesn’t seem to be supported in the EMHASS configuration setup. I am also interested in the use of pvlib within EMHASS given the HA energy dashboard already has good support for solar forecasting though either the Solcast or Forecast.Solar integrations, which in my case are already setup.

EMHASS assumes that the solar compensation, TOU pricing and timings are constant, but there are other cases. I have forecast and actual feed in and general tariff pricing available in 30 minute blocks vi the Amber Electric Integration. That is OK, I can make a steady state approximation as to my TOU windows and pricing, but something to consider for the future, and something that would really benefit from the LP, although I suspect the calculations may need to occur more than once a day as my forecast pricing is updated every 30 minutes.

EMHASS assumes that the deferable loads needs to run for a fixed number of hours but there are other cases. My EV/ Home Battery charging time is an inverse function with its state of charge, the Power draw for EV charging can also be modulated to self consume excess solar, my Pool Heating time is a function of the temperature difference with the desired set point. My HVAC running time is a bizzare function of the temperature difference with the desired set point with an allowance for pre heating/ cooling before electricity price peak windows.

So looking forward to seeing how far we can push EMHASS.

1 Like

Great project ! I am really interested as I have to ideally maximize the usage of my solar production to minimize my electricity bill but also minimize the price for installing batteries in the future… EMHASS combined with the recording of the power consummed by some of my equipments (a total of 22), the battery simulator (battery_sim) and the energy dashboard, will allow me to meet my objectives I think.

Tried just now on 0.1.16


but getting an error:

Hi thanks for the feedback!

Version 0.1.16 loaded correctly on my odroid n2+, which is the same hardware as HA Blue so that is a start.

You will need to rebuild as I have just updated EMHASS (the module not the add-on)

I am not currently on my local network, and access HA via Nabu Casa, so I presume I cannot access EMHASS, which makes control difficult outside of LAN. Interesting other Add-On’s can still access localhost, so there maybe a way around that I haven’t identifed.

Ok so in version 0.1.16 (the latest) I’m using directly communication with the supervisor. So EMHASS should be able to communicate directly with your hass core instance. Have you tested the connection?

I have multiple inverters with multiple strings pointing in different directions, which doesn’t seem to be supported in the EMHASS configuration setup. I am also interested in the use of pvlib within EMHASS given the HA energy dashboard already has good support for solar forecasting though either the Solcast or Forecast.Solar integrations, which in my case are already setup.

Ok this is a very nice use case, I will definitely update the code in the near future to support multiple inverters. The core code is actually ready for this as everything is in lists, so you we could have a list of inverters with no problem. But I will need to work a little bit further on the add-on.

For you to use PVLib inside EMHASS you will have to provide and pass the irradiance and temperature forecasts provided by whatever service you want. As you said this is already implemented in HA, so it will be nice to retrieve these forecasts directly. This is already possible using your own CSV files with my EMHASS Python module but not the Add-on. I will also update the add-on for you to be able to import directly the variables from those forecasting services you mentioned. I will work on it.

EMHASS assumes that the solar compensation, TOU pricing and timings are constant, but there are other cases. I have forecast and actual feed in and general tariff pricing available in 30 minute blocks vi the Amber Electric Integration. That is OK, I can make a steady state approximation as to my TOU windows and pricing, but something to consider for the future, and something that would really benefit from the LP, although I suspect the calculations may need to occur more than once a day as my forecast pricing is updated every 30 minutes.

Again this is actually already implemented in the EMHASS Python module but still not in the add-on. I was trying to figure out how to possible import variable pricings. The Amber Electric integration is just for AU users, so I will need to find a more generalized solution. How to feed a forecast variable to EMHASS?

EMHASS assumes that the deferable loads needs to run for a fixed number of hours but there are other cases. My EV/ Home Battery charging time is an inverse function with its state of charge, the Power draw for EV charging can also be modulated to self consume excess solar, my Pool Heating time is a function of the temperature difference with the desired set point. My HVAC running time is a bizzare function of the temperature difference with the desired set point with an allowance for pre heating/ cooling before electricity price peak windows.

There are definitely a lot of using cases to take care of. For now an answer to the EV case. You can consider adding a battery to EMHASS and fix a discharging power to zero and a target SOC to whatever SOC you want the EV to be at the end of the day.

1 Like

Yes, that’s exactly the goal of this package. Looking to see what it can do for you. :+1:

Please post your supervisor logs to be able to see what’s the actual problem.

I’m also aware of the Octopus Agile integration for UK users, which also has variable pricing. In both cases I think the generic use case is a sensor for current price, a sensor for forecast price and then attributes listing subsequent prices. A generic approach for forecast data would be useful across HA.

I can start/ stop EMHASS from the Addon tab, so yes they are connected, but I cannot access the Web UI though the http://xyzz.ui.nabu.casa:5000 address, it will be a few days before I can access my LAN directly, and then I anticipate I will be able to use the http://homeassistant.local:5000 address for the Web UI.

By comparison the File Editor, Studio Code Server. Terminal & SSH Addon does allow me access though the nabu.casa proxy:
https://xxyyy.ui.nabu.casa/hassio/ingress/core_ssh

Interesting to note I can telnet to localhost port 5000 from within the Telnet & SSH addon, but I presume EMHASS does not have a CLI available.

It looks like these other add on’s work remotely as they bind to the hassio/ingress file system space, rather than presenting on a different port (5000 in EMHASS case).

22-03-29 14:01:37 INFO (MainThread) [supervisor.store.git] Cloning add-on https://github.com/davidusb-geek/emhass-add-on repository
22-03-29 14:01:39 WARNING (SyncWorker_5) [supervisor.addons.validate] Add-on config 'auto_uart' is deprecated, use 'uart'. Please report this to the maintainer of deCONZ
22-03-29 14:01:39 INFO (MainThread) [supervisor.store] Loading add-ons from store: 67 all - 1 new - 0 remove
22-03-29 14:01:39 INFO (MainThread) [supervisor.resolution.evaluate] Starting system evaluation with state CoreState.RUNNING
22-03-29 14:01:39 INFO (MainThread) [supervisor.resolution.evaluate] System evaluation complete
22-03-29 14:01:45 INFO (MainThread) [supervisor.addons] Creating Home Assistant add-on data folder /data/addons/data/5b918bf2_emhass
22-03-29 14:01:45 INFO (SyncWorker_3) [supervisor.docker.addon] Starting build for 5b918bf2/armv7-addon-emhass:0.1.16
22-03-29 14:01:50 ERROR (SyncWorker_3) [supervisor.docker.addon] Can't build 5b918bf2/armv7-addon-emhass:0.1.16: The command '/bin/bash -o pipefail -c apt-get update     && apt-get install -y --no-install-recommends         libffi-dev         python3         python3-pip         python3-dev         git         build-essential     && pip3 install --no-cache-dir -U setuptools wheel     && pip3 install --no-cache-dir -r requirements.txt     && apt-get purge -y --auto-remove         git         build-essential         python3-dev     && rm -rf /var/lib/apt/lists/*' returned a non-zero code: 100
22-03-29 14:01:50 ERROR (SyncWorker_3) [supervisor.docker.addon] Build log: 
Step 1/19 : ARG BUILD_FROM


Step 2/19 : FROM ${BUILD_FROM}


 ---> 4227b8cc9f8d

Step 3/19 : WORKDIR /usr/src


 ---> Using cache

 ---> e953a1313722

Step 4/19 : COPY ./requirements.txt /usr/src/requirements.txt


 ---> Using cache

 ---> 81662027936f

Step 5/19 : RUN apt-get update     && apt-get install -y --no-install-recommends         libffi-dev         python3         python3-pip         python3-dev         git         build-essential     && pip3 install --no-cache-dir -U setuptools wheel     && pip3 install --no-cache-dir -r requirements.txt     && apt-get purge -y --auto-remove         git         build-essential         python3-dev     && rm -rf /var/lib/apt/lists/*


 ---> Running in ced58ef1a383

Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]

Get:2 http://security.debian.org/debian-security bullseye-security InRelease [44.1 kB]

Get:3 http://deb.debian.org/debian bullseye-updates InRelease [39.4 kB]

Err:2 http://security.debian.org/debian-security bullseye-security InRelease
  At least one invalid signature was encountered.

Err:1 http://deb.debian.org/debian bullseye InRelease
  At least one invalid signature was encountered.

Err:3 http://deb.debian.org/debian bullseye-updates InRelease
  At least one invalid signature was encountered.

Reading package lists...


W: GPG error: http://security.debian.org/debian-security bullseye-security InRelease: At least one invalid signature was encountered.
E: The repository 'http://security.debian.org/debian-security bullseye-security InRelease' is not signed.
W: GPG error: http://deb.debian.org/debian bullseye InRelease: At least one invalid signature was encountered.
E: The repository 'http://deb.debian.org/debian bullseye InRelease' is not signed.
W: GPG error: http://deb.debian.org/debian bullseye-updates InRelease: At least one invalid signature was encountered.
E: The repository 'http://deb.debian.org/debian bullseye-updates InRelease' is not signed.

Removing intermediate container ced58ef1a383

A generic approach for forecast will be much appreciated. For now manually feeding that data in json format could be an option, but it will be specific to each integration.

Oh yes I see! The webui is bound by default to localhost (host=‘0.0.0.0’).
Maybe a current solution can be to access your LAN using VPN.
What I may do is let the user to choose its desired host from the configuration pane. In your case: https://xxyyy.ui.nabu.casa/

Maybe related to not enough space on your system. For now it is just a guess.
See: docker - At least one invalid signature was encountered - Stack Overflow

Be careful applying any docker image volume or builder prune commands, as they can be destructive. But I’m not sure how can you perform this in HA OS

Some hints here?: Disk almost full - #38 by WTFoX74

1 Like

Just elaborating a little bit more on this. Right out the box EMHASS can be used for loads that are deferrable. This means that these loads can be “moved” around the day with “ideally” no impact on our everyday life. Good examples of these are: dishwasher, washing machine, etc. At my place I also considered as deferrable the water heater and the pool pump. For the water heater the time constant is quite slow, so as long as I respect a total number of working hours I know that I will have hot water all time regardless on the times that the water heater was on. For the pool pump is the same for me, I’m just looking to fixed total operating hours objective. I’m maybe taking a different approach with this. Of course that what you’re doing with the pool heating and the HVAC is totally valid as they need to be a function of temperatures and maybe other variables. These type of loads that are a function of other variables could be introduced and modeled in the LP formulation, as long as the relationship remains fairly linear. I may be introducing these different types of loads en the LP problem in the future.

For EV’s you’ll need to test as I said using the battery option and a discharging power. I’m guessing that this can work as the SOC evolution is well implemented in the LP formulation. I may test this myself in the near future as I’m waiting for my EV to be delivered :smiley:

Hello, I tried to add : GitHub - davidusb-geek/emhass-add-on: The Home Assistant Add-on for EMHASS: Energy Management Optimization for Home Assistant

but I got the message “Invalid Add-on repository !”

Any suggestions ?

Updated: After a few attemps, it worked… So discard this message… :slight_smile:

I have access to my LAN now and get an impressive set of optimization results, but not quite sure what I am looking at and how to best use the system.

I presume it would be good to start simply and then build complexity into the model, that seems to work best for me with HA.

Do you have a worked example for a simple model?

Maybe sensors for production, excess-production, prices and a switch for one deferable load?