Skip to content

Hot Water Tank

Jan Brandsma edited this page Dec 4, 2026 · 1 revision

Hot water tank

ZenMaster knows three water stores. Two are planned inside the linear program (LP) of the planner with a simple RC model; the hot water heat pump has its own layered tank model and is planned outside the LP.

Consumer type Model Defaults
boiler_electric RC model in the LP band 40 to 60 °C, tau 110 h
pool_heat_pump RC model in the LP band 26 to 30 °C, tau 40 h
boiler_heat_pump ten-layer tank, daily fill outside the LP minimum 38 °C, maximum 60 °C, tau 110 h

The RC model (electric boiler and pool)

An RC model (resistance and capacitance, like an electrical circuit) treats the store as one temperature that is charged by power and leaks to its surroundings. Per quarter of an hour:

T[t+1] = (1 - B) * T[t] + A * P[t] + B * T_ambient + A * icept
A = 0.25 / (tau * slope)      °C per kW-quarter
B = 0.25 / tau                share lost per quarter
  • tau is the cooling time constant in hours.
  • slope is °C of rise per kW of input in steady state (the loss coefficient over the COP).
  • icept is a free-gain offset in kW.
  • T_ambient is the fixed ambient temperature of the room or air around the store.

The band [t_min, t_max] is hard. The first quarter is pinned to the live temperature; if that is outside the band, the bounds start there so the LP stays solvable. When the tank volume (litres) is filled in, the slope follows from physics: slope = volume / (857 * tau), with 857 = 3600 / 4.2 litre-kelvin per kWh of water. A resistive element turns every kWh into heat, so that is exact.

fit_store

Every 7 days fit_store tries to fit the RC model from 90 days of hourly means in the Recorder:

  1. Energy signature. Per day the mean power against the mean of T - T_ambient. Days with more than 0.1 kW and more than 3 K above ambient count as active; at least 20 are needed. A straight line through them gives slope and icept. The fit is kept only with a positive slope and R² (coefficient of determination) above 0.5.
  2. Night cooling. Stretches of at least 6 hours with power under 0.05 kW. Within them, the night hours (22:00 to 06:00) with the store more than 0.5 K above ambient; with at least 5 such hours the logarithm of T - T_ambient is fitted against time, and its slope gives tau. The median over all stretches is clamped to 10 to 120 hours.

With a known volume the slope is recomputed from the new tau, as above.

Hot water heat pump

The hot water heat pump is not in the LP. Once a day it is filled in the block where a kWh of heat costs least, and only when the tank would otherwise not hold its minimum until the next fill. ZenMaster writes the target as the unit's setpoint, rounded up to the entity's step, watches the tank, and parks the setpoint at the entity minimum when the target is reached. A volume is required for the model and the daily fill.

flowchart TD
    A[Every run: energy in, model follows the tank] --> B{Hour 0, first time today?}
    B -->|yes| C[fill_at = cheapest block of today]
    C --> D{fill_at reached?}
    B -->|no| D
    D -->|yes| E[fill_to: heat needed so the top holds t_min until tomorrow's block]
    E -->|no heat needed| F[No fill today]
    E -->|heat needed| G[Write setpoint, watch the tank]
    G --> H{Sensor at target?}
    H -->|yes| I[Park setpoint at minimum]
Loading

The layered tank

The tank is ten layers from bottom to top. The heat of each step goes into the bottom layer (where the coil is) and mix() lets it rise: whenever a layer is warmer than the one above it, the two merge into their average until the column is stable, keeping the total heat. Every layer then loses to the room at its own time constant. The room is the ambient_entity sensor, or the fixed ambient value.

The tank sensor sits at one of three heights (sensor_height): 0.15, 0.5 or 0.85 of the tank. Optional bottom_entity (at 0.15) and top_entity (at 0.85) sensors pull the layers between them and the main sensor towards their readings while the unit is off. The minimum t_min is held at 0.85 of the height, the top of the tank.

Tap detection

With the unit off (under 100 W), when the model at the sensor height is more than one sensor step (0.5 °C) warmer than the sensor, hot water has been drawn. The model then removes a litre at a time from the top and lets mains water at 15 °C in at the bottom, until it matches the sensor. The heat that disappears beyond the model's own loss is counted as what the house drew. At each fill the daily draw is updated as a running mean (weight 0.25 for the new day; default 2.0 kWh).

COP from a curve

The COP is taken from a standard curve, scaled by a level learned on this unit: COP = max(1, level * curve(outdoor, water)). The curve interpolates along the outdoor air at water 35 °C and 55 °C, then linearly along the water temperature:

Outdoor °C -7 0 7 15 21
COP at water 35 °C 3.05 3.59 4.13 4.60 4.99
COP at water 55 °C 2.22 2.62 3.01 3.35 3.63

The level is learned per run. A run of at least half an hour mixes the tank, so its rise plus the heat that leaked away during it, against the heat the standard curve promised for the measured energy, gives one sample. The level is the median of the last 10 samples (default 1.0). After such a run the model is reset to a mixed tank at the sensor reading.

Cheapest fill block

fill_quarters is the number of quarters a fill for a day takes: the heat the model needs, divided by what one quarter at max_power adds at the current COP (at least one). block_at slides a window of that length over the prices and picks the start with the lowest sum of price / COP, with the COP at the forecast outdoor temperature of each quarter. See Price model.

In the first hour of the day the fill is planned at the cheapest block of the rest of the day. When that quarter arrives:

  • fill_to heats the model at the bottom, 0.1 kWh at a time with mixing, until the top (after the loss up to the cheapest block of the next day and one day of draw taken from the top) still holds t_min, or the sensor height reaches t_max. The target is the sensor temperature at that point.
  • If no heat is needed, there is no fill that day.
  • A fill the unit does not start within a quarter is dropped and never run later: the unit's own thermostat did not want it.
  • After a restart during a running fill, the fill continues at the level the model now gives.

The planned block is shown in the plan at max_power and reserved on the unit's phase, so the LP keeps room for it. A manual Start action plans the fill in the current quarter.

Legionella disinfection

With legionella on, the tank is heated to t_max every legionella_days (default 7), on the cheapest day within legionella_band days either side (default 1). The cheapest day is the one with the lowest mean price over its 96 quarters. On that day it starts in a quarter whose price is the lowest of the rest of the day. The interval restarts when the sensor reaches t_max.

Nightly tau fit

Every day fit_nights measures the loss from the raw sensor states of the last 10 nights (only since the boiler was added). Each night from 01:00 to 06:00 with the unit off (never above 0.1 kW) gives k = drop / 5 / (mean tank temperature - mean room temperature), and tau = 1 / median(k). This is done for the main, bottom and top sensor separately; between them the time constant per layer is interpolated by height. When the median drop is under four of the sensor's smallest steps, it is more rounding than loss: the main sensor then falls back to 110 hours, a bottom or top sensor to the value of the main sensor.

In the code: custom_components/zenmaster/solver/boiler.py, custom_components/zenmaster/solver/heating.py, custom_components/zenmaster/coordinator.py

Clone this wiki locally