Storage · Dynamic tariff
Controlling a home battery with Home Assistant
The optimiser's main use case – and the question of which devices permit it at all.
Read the article →Technical article · Optimisation
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.
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.
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.
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.
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:
sensor_power_photovoltaics and
sensor_power_load_no_var_loads – PV output and house load, where the load must
not include the controllable loads. Without separate metering, you have to build it
first.number_of_deferrable_loads,
nominal_power_of_deferrable_loads,
operating_hours_of_each_deferrable_load – for every load its power and the
hours it needs.battery_nominal_energy_capacity,
battery_charge_efficiency and battery_discharge_efficiency,
battery_charge_power_max and battery_discharge_power_max, plus
state-of-charge limits. The efficiencies are where datasheet values make the result look
systematically too good – see
battery arbitrage.pv_module_model, pv_inverter_model,
surface_tilt, surface_azimuth, string layout – the array is
modelled, not merely entered as a rating.weather_forecast_method, load_forecast_method.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.
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.
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.
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.
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.