EMHASS stands for "Energy Management for Home Assistant" and is an open-source tool that plans a household's power flow in advance: from electricity prices, a solar forecast, a load forecast and the battery, it uses linear optimisation to work out when the battery should charge or discharge and when deferrable loads should run. It writes the plan back to Home Assistant as sensors, where automations carry it out.
I don't use EMHASS myself. For my own energy management in Home Assistant I deliberately chose a simple heuristic. That is exactly why it is worth looking at what EMHASS does differently and when it is the better choice. Everything below comes from the project's documentation, linked at the end.
Short answer
- What it is: an optimiser that computes a schedule for the battery, grid import and deferrable loads. Written by David Hernandez Torres, MIT licence.
- How it calculates: linear programming with the Python library CVXPY; the default solver is HiGHS. On/off devices add mixed-integer optimisation.
- When it pays off: when electricity prices change by the hour, there is a battery, and loads such as a wallbox, hot water or a heat pump can be shifted.
- Installation: as an app (formerly add-on) for Home Assistant OS and Supervised, as a Docker container, or via pip.
How EMHASS calculates
EMHASS describes a household's energy flow over the coming hours as an optimisation problem. The inputs are forecasts for solar generation and base load, prices for import and export, the battery's characteristics, and a list of deferrable loads with their power and run time. The output is the schedule that best meets the objective.
There are three objectives: profit (the default) maximises export revenue minus import cost, cost only minimises cost, and self-consumption maximises the share of solar power used at home. For devices that can only be on or off, EMHASS uses mixed-integer optimisation (MILP); otherwise linear programming is enough.
Besides batteries and switchable loads, EMHASS has thermal models for hot water tanks and heat pumps. For the load forecast it can train a machine learning model based on scikit-learn.
The three optimisation runs
- Perfect optimisation: calculates backwards with the actual values from the Home Assistant database. That is the theoretical best case, useful as a benchmark but not something you can run your house on.
- Day-ahead: plans the next 24 hours from forecasts. This is the everyday run, usually started once a day.
- Model predictive control (
naive-mpc-optim): replans over a shorter horizon again and again, every five minutes for example, and applies only the first step each time. That is how EMHASS absorbs the gap between forecast and reality.
Getting EMHASS into Home Assistant
The documentation lists three ways:
- Home Assistant app: for Home Assistant OS and Supervised, described in the docs as the most user-friendly way. Add the emhass-add-on repository to Home Assistant's app store and install the app. Supported architectures are amd64 and aarch64.
- Docker: the image
ghcr.io/davidusb-geek/emhass. The docs advise pinning a version tag rather than using:latest. - pip:
python3 -m pip install emhassinstalls the older command-line version without a web server.
As an app or in Docker, EMHASS runs a web server on port 5000. An optimisation is started with a POST request, for example to /action/dayahead-optim or /action/naive-mpc-optim, and /action/publish-data writes the result to Home Assistant as sensors. The API requires a bearer token. In Home Assistant you call these endpoints with a rest_command from an automation, the day-ahead run about once a day.
EMHASS or a simple rule?
EMHASS shows its strength wherever there is something to weigh up: dynamic electricity tariffs, a battery that can be charged cheaply at night, and loads with some freedom in when they run. There an optimiser finds schedules that a handful of automations won't.
With a fixed electricity price and the goal of using as much of your own solar power as possible, the sums are simpler. For that case I built my own energy manager that works with rules you can explain. If you are on a dynamic tariff, on the other hand, EMHASS is worth trying. How I run solar and storage with changing prices is covered in Solar, storage and dynamic prices.
FAQ
What does EMHASS stand for? "Energy Management for Home Assistant", an optimisation tool for residential households.
Is EMHASS free? Yes. EMHASS is open source under the MIT licence.
Which installation is the easiest? On Home Assistant OS and Supervised, the app from the emhass-add-on repository. If you run Home Assistant as a container, use the Docker image.
Does EMHASS need a dynamic electricity tariff? No. With the self-consumption objective it optimises for self-consumption. It brings the most, though, when prices vary and loads can be shifted.
Does EMHASS control my devices itself? No. EMHASS publishes the plan as sensors in Home Assistant. Automations that read those sensors do the switching.
Sources
- EMHASS on GitHub: description, licence, author
- EMHASS documentation: CVXPY, HiGHS, thermal models, forecasts
- Installation methods: app, Docker, pip
- Mathematical model: optimisation runs, MILP, objectives
- Usage guide: API endpoints, objectives
Further reading
Energy management with rules instead of an optimiser → An Energy Manager That Starts by Just Watching