Skip to main content

Water Heater

The water heater is an essential component in residential energy systems, especially in highly electrified homes where it significantly contributes to power demand during Demand Response (DR) events. The Model Predictive Control (MPC) formulation for the water heater optimizes its operation to maintain hot water availability while minimizing energy costs and respecting grid power limits. This section presents the MPC formulation for the water heater, which models the tank's temperature dynamics, considering heating power, heat losses to the ambient environment, and water consumption. The formulation prioritizes user comfort by minimizing deviations from a desired water temperature, making it suitable for integration into Home Energy Management Systems (HEMS).

The water heater operates with continuous power control, allowing flexible power allocation within the device's capacity limits, unlike binary on/off control. This approach enhances the MPC's ability to finely adjust energy usage, thereby reducing demand peaks during re-energization. The formulation is designed to be computationally efficient, using a linear model of temperature dynamics to ensure real-time optimization on embedded devices. The inclusion of water flow and ambient temperature effects allows for accurate modeling of real-world conditions, making the controller robust to varying usage profiles.

Optimization Formulation

The MPC formulation for the water heater optimizes the power allocated to the device over a prediction horizon TT, with time steps of duration Δt\Delta t (e.g., 10 minutes). The objective is to minimize the comfort penalty, defined as the squared deviation between the water temperature and a desired temperature, weighted by a user-defined priority. The power allocation cost is included in the overall MPC objective, while the comfort term is specific to the water heater.

The comfort penalty is formulated as follows:

JWH,k=PWHk=1T(XWHdXkWHΔαWH)2J_{WH,k} = P_{WH} \sum_{k=1}^{T} \left( \frac{X^{d}_{WH} - X^{WH}_{k}}{\Delta \alpha_{WH}} \right)^2

where:

  • PWHP_{WH} is the priority weight for the water heater.
  • XWHdX^{d}_{WH} is the desired water temperature (constant over the horizon, e.g., 80°C).
  • XkWHX^{WH}_{k} is the water temperature at time kk.
  • ΔαWH\Delta \alpha_{WH} is the normalization factor (e.g., 50 K).

The temperature dynamics of the water heater are modeled as follows:

Xk+1WH=XkWH+ΔtCV[SkWHCV˙k(XkWHXinlet)2(XkWHTa)],kX^{WH}_{k+1} = X^{WH}_{k} + \frac{\Delta t}{C V} \left[ S^{WH}_{k} - C \dot{V}_{k} (X^{WH}_{k} - X_{\text{inlet}}) - 2 (X^{WH}_{k} - T_a) \right], \quad \forall k

where:

  • SkWHS^{WH}_{k} is the power allocated to the water heater at time kk.
  • CC is the water heater constant (thermal capacity per unit volume, in Wh/°C/L).
  • VV is the tank volume (in liters, converted to m³ for consistency).
  • V˙k\dot{V}_{k} is the water flow rate at time kk (in m³/s).
  • XinletX_{\text{inlet}} is the inlet water temperature (e.g., 16°C).
  • TaT_a is the ambient temperature.
  • Δt\Delta t is the duration of the time step (in hours).

Constraints ensure that the water heater operates within physical and operational limits:

  • Temperature Limits:
XWHXkWHXWH,k\underline{X}^{WH} \leq X^{WH}_{k} \leq \overline{X}^{WH}, \quad \forall k

where XWH\underline{X}^{WH} and XWH\overline{X}^{WH} are the minimum and maximum allowed temperatures (e.g., 30°C and 90°C).

  • Power Limits:
0SkWHSWH,max,k0 \leq S^{WH}_{k} \leq S^{WH,\max}, \quad \forall k

where SWH,maxS^{WH,\max} is the maximum power of the water heater (in W).

  • Initial Condition:
X0WH=XinitialWHX^{WH}_{0} = X^{WH}_{\text{initial}}

where XinitialWHX^{WH}_{\text{initial}} is the initial water temperature.

The power injection of the water heater, which contributes to the global power constraint, is simply:

SkWH,kS^{WH}_{k}, \quad \forall k

Justification of the Formulation

The continuous power formulation allows for finer granularity in power allocation, which is essential for mitigating DR peaks by avoiding abrupt power surges. The comfort penalty uses a constant desired temperature to simplify user input while ensuring hot water availability consistent with typical residential needs. The temperature dynamics model integrates water flow and thermal losses to the ambient environment, making it sensitive to actual usage patterns. The linearity of the dynamics and the absence of binary variables enhance computational efficiency, allowing MPC execution on resource-constrained embedded devices. The water heater constant CC simplifies the thermal model by combining thermal capacity and conductance effects, reducing the number of parameters while maintaining good accuracy.

Variable Definitions

Variables and parameters specific to the water heater formulation are summarized in the following table.

Variable/ParameterDescriptionUnits
SkWHS^{WH}_{k}Power allocated to the water heater at time kkW
XkWHX^{WH}_{k}Water temperature at time kk°C
XWHdX^{d}_{WH}Desired water temperature (constant)°C
PWHP_{WH}Priority weight for the water heater-
ΔαWH\Delta \alpha_{WH}Normalization factor (e.g., 50 K)K
CCWater heater thermal constant (thermal capacity per volume)Wh/°C/L
VVTank volume
V˙k\dot{V}_{k}Water flow rate at time kkm³/s
XinletX_{\text{inlet}}Inlet water temperature°C
TaT_aAmbient temperature°C
XWH\underline{X}^{WH}Minimum water temperature°C
XWH\overline{X}^{WH}Maximum water temperature°C
SWH,maxS^{WH,\max}Maximum water heater powerW
XinitialWHX^{WH}_{\text{initial}}Initial water temperature°C
Δt\Delta tTime step durationh

Classes

This module defines the WaterHeaterMPC class, which models an electric water heater for MPC.

It extends the abstract DeviceMPC class, providing a concrete implementation for formulating the optimization problem specific to controlling a water heater. This includes defining objectives related to maintaining water temperature within a desired range and incorporating constraints such as power limits, tank volume, and thermal dynamics influenced by ambient temperature and water flow.

WaterHeaterMPC

Represents a water heater for the MPC.

This class models the thermal behavior of an electric water heater. It formulates an optimization problem to control the heater's power consumption to maintain the water temperature within a desired range, while considering hot water usage, heat losses, and system constraints.

Methods

__init__(devices: List[Dict[str, Any]])

Initializes the WaterHeaterMPC.

Args:

  • devices: A list of dictionaries, where each dictionary contains the configuration and parameters of a water heater device.
create_mpc_formulation(start: datetime, stop: datetime, steps_horizon_k: int, interval: int = 10, norm_factor: int = 50)

Creates the optimization formulation for the water heater.

This method constructs a CVXPY optimization problem based on a thermal model of the water heater tank. The objective is to minimize deviations from a desired temperature setpoint. The model includes constraints for:

  • The thermal dynamics of the water tank, accounting for heating, heat loss to the ambient environment, and hot water draws.
  • Temperature limits (min and max).
  • Maximum power output of the heating element.

Args:

  • start: The start time of the optimization horizon.
  • stop: The end time of the optimization horizon.
  • steps_horizon_k: The number of time steps in the horizon.
  • interval: The duration of each time step in minutes.
  • norm_factor: A normalization factor for the objective function.

Returns:

  • A tuple containing the objective terms, constraints, and the dispatch variable for the CVXPY optimization problem.