Technical article · Optimisation

Setting up EMHASS

Once several loads compete for the same cheap hour and each has its own deadline, a rule is the wrong tool. An optimiser computes the schedule – and delivers exactly the result its objective function describes, not the one you hoped for. The real obstacle, though, sits before the mathematics: at setup.

Method
Linear programming over forecasts for price, generation and consumption
Key concept
deferrable load: an amount of energy plus a window
Modes
day-ahead optimisation or MPC with a shrinking horizon
Belongs to
the hub „controlling a home battery with Home Assistant“
Status
September 2026 · primary source below, with the date checked
Author
Julian Haag, state-certified electrical engineering technician

What an optimiser solves that an automation does not

An automation rule decides locally: if the hour is cheap, the device runs. It cannot weigh options, because it knows one quantity and drives one load. As soon as several loads compete for the same cheap hour and each has its own deadline, it is no longer the right shape of tool.

EMHASS starts there: it describes the installation as an optimisation problem and solves it with linear programming – forecasts for generation, consumption and price as input, a schedule for the controllable loads as output. Loads that can be moved in time are described as deferrable loads: an amount of energy they need, and a window in which they must get it.

The difference in one sentence: an automation answers „should I switch now?“, an optimiser answers „when do I switch what so the total at the end of the day is smallest?“ – and recalculates it every time.

Prerequisites

The optimiser is only as good as its inputs, and that is not a platitude but the reason most installations disappoint.

Without that data, measure first. How to build it in the board is covered in energy metering in the distribution board.

Setup and operating modes

The sequence is the same in every installation: describe the plant, connect the data sources, run the optimisation, return the result to Home Assistant and translate it into switching commands there.

Two operating modes matter. Day-ahead optimisation computes once for the coming period and delivers a schedule. MPC operation recomputes continuously, using current measurements and a shrinking horizon: the further the day advances, the smaller the window left for a load to receive its energy.

For heat there is a dedicated model: a hot water cylinder or the building mass can be described as thermal storage, letting the optimiser carry heat forward instead of merely switching devices. That is the point at which the method becomes superior to a rule base.

An honest status: in the installation this series refers to, EMHASS is not currently running. The attempt failed at setup, not at the method – it was too much work for what would have come out of it. That is not an isolated case, and it is why this article treats setup in more depth than optimisation.

Where setup fails

The reason is not an error message but the sheer scope: the configuration spans over a hundred parameters across three groups – data retrieval from Home Assistant, the optimisation problem, and the description of the installation. Most have usable defaults, and that is exactly the trap: defaults get you to a run that computes, not to one that is right.

What genuinely has to come from your own installation can be read off the parameter names:

So the obstacle is not the mathematics but the model of the house. EMHASS asks for one, and a model is only as good as the measurements behind it. Anyone who does not yet have the measurement is not configuring an optimiser but building a metering point – and discovers that mid-configuration. That is where most attempts end, and it is a sensible stop rather than a failure.

The sensible order is therefore the reverse: measure first, control with a rule second, and optimise only once the rule demonstrably reaches its limit. How to build the measurement is covered in energy metering in the distribution board; the rule that suffices for most houses is in price-signal automation.

Understanding the objective function

The optimiser minimises whatever is described to it as cost – not what the operator considers sensible. That distinction is the source of nearly every disappointment: if only the import price appears in the objective, the result will cycle the battery to exhaustion, because wear does not appear in it. Not modelling cycle cost means optimising for a profit the battery pays for – see battery arbitrage: the calculation.

Likewise comfort: it only exists if formulated as a constraint. A minimum temperature belongs in the model as a condition, not as an override bolted on afterwards.

What the result is worth

The benefit of an optimiser over a good rule grows with the number of controllable loads and with the spread of prices. With a single shiftable load and a narrow price band the difference is small – and the effort of maintaining the model remains.

Limits

Read on: what the optimiser is mainly needed for – the choice between self-consumption and arbitrage at the battery – is covered in the hub controlling a home battery with Home Assistant.

Sources

Statements about the method come from the project documentation. The project is under active development – configuration keys and features can differ between versions.

EMHASS's configuration and feature set change between versions. What counts is the documentation for the version you run.

Several controllable loads, and tired of having them fight each other? Write to me – the first conversation is free.