Algorithm Overview¶
The Heating Curve Optimizer uses a sophisticated dynamic programming approach to minimize electricity costs while meeting your home's heat demand. This page provides a high-level overview of the optimization algorithm.
The Optimization Problem¶
At its core, we're solving this problem:
Optimization Goal
Minimize: Total electricity cost over the planning horizon
Subject to:
- Heat demand must be satisfied (or buffered/deferred within limits)
- Supply temperature stays within bounds
- Offset changes are limited (±1°C per time step)
- Thermal buffer constrained by heat debt limit (configurable)
Key Concepts¶
1. Heat Demand¶
Heat demand varies with weather:
Where:
- \(Q_{loss}(t)\) = Heat loss due to temperature difference
- \(Q_{solar}(t)\) = Solar gain through windows
Negative Demand
When \(Q_{solar} > Q_{loss}\), demand is negative, meaning solar gain exceeds heat loss. This excess heat is stored in the building's thermal mass as a buffer.
2. Heating Curve Offset¶
The heating curve offset adjusts the supply temperature:
The supply temperature is calculated as:
Where \(T_{base}\) is your heat pump's base heating curve (typically linear with outdoor temperature).
Offset range: -4°C to +4°C (configurable)
3. Heat Pump COP¶
The Coefficient of Performance (COP) determines how efficiently the heat pump converts electricity to heat:
Parameters:
- \(\text{COP}_{base}\): Base COP at standard conditions
- \(\alpha = 0.025\): Outdoor temperature coefficient
- \(k\): K-factor (how COP degrades with supply temp)
- \(f\): COP compensation factor (system efficiency)
COP Calculation Example
Given:
- Base COP = 3.5
- Outdoor temp = 5°C
- Supply temp = 40°C
- K-factor = 0.03
- Compensation = 0.9
Calculation: $$ \text{COP} = (3.5 + 0.025 \times 5 - 0.03 \times (40 - 35)) \times 0.9 $$ $$ = (3.5 + 0.125 - 0.15) \times 0.9 = 3.475 \times 0.9 = \mathbf{3.13} $$
4. Electricity Cost¶
The cost to produce heat at time \(t\):
Where:
- \(Q_{heat}(t)\): Heat delivered (kWh)
- \(\text{COP}(t)\): Heat pump efficiency
- \(P_{electricity}(t)\): Electricity price (€/kWh)
Two Levers for Optimization
The optimizer can reduce costs by:
- Timing: Heat when electricity is cheap
- Efficiency: Use lower supply temps (higher COP) when possible
Algorithm Flow¶
Optimization Strategy¶
Step 1: Forecast Horizon¶
The algorithm looks ahead for a configurable planning window (default: 6 hours).
Step 2: State Space¶
For each time step, the algorithm considers:
- Offset: -4°C to +4°C (9 possible values)
- Buffer: Cumulative thermal energy stored
- Cumulative offset sum: Running total (for smoothness)
This creates a 3-dimensional state space.
Step 3: Dynamic Programming¶
The algorithm uses backward induction:
- Start from the final time step
- For each state, calculate the minimum cost to reach the end
- Work backward to the current time
- Choose the path with minimum total cost
Step 4: Constraints¶
The algorithm enforces several constraints:
Offset Change Constraint¶
Maximum change per time step: ±1°C
# Only consider offsets within ±1 of current offset
for next_offset in range(max(-4, offset - 1), min(5, offset + 2)):
...
Temperature Bounds¶
Supply temperature must stay within configured min/max:
Buffer Constraint¶
Thermal buffer constrained by heat debt limit:
This allows the optimizer to reduce heating during expensive hours (creating "heat debt") and compensate during cheaper hours, enabling cost optimization through temporal load shifting.
Output¶
The optimization produces:
Primary Output¶
Optimal Heating Curve Offset for the current time step
This offset is immediately applied to your heating system.
Secondary Outputs¶
- Optimized supply temperature sequence (6-hour forecast)
- Buffer evolution (how thermal storage changes)
- Expected electricity cost (total for planning window)
Example Scenario¶
Let's see how the algorithm handles a typical day:
Input Conditions¶
| Time | Outdoor Temp | Solar Radiation | Electricity Price |
|---|---|---|---|
| 06:00 | 2°C | 0 W/m² | €0.15/kWh |
| 09:00 | 5°C | 200 W/m² | €0.30/kWh |
| 12:00 | 8°C | 600 W/m² | €0.35/kWh |
| 15:00 | 7°C | 300 W/m² | €0.25/kWh |
| 18:00 | 4°C | 0 W/m² | €0.40/kWh |
Algorithm Decisions¶
Rationale:
- 06:00 - 09:00: Prices low, outdoor temp cold → Pre-heat with high offset (+3°C)
- 09:00 - 12:00: Prices high, solar gain increasing → Reduce to medium offset (0°C)
- 12:00 - 15:00: Peak solar gain → Minimize heating with low offset (-2°C), build thermal buffer
- 15:00 - 18:00: Solar fading, prices moderate → Moderate heating (+2°C)
Why This Works¶
1. Temporal Shifting¶
Heat when electricity is cheap, reduce when expensive
2. Thermal Mass¶
Buildings store heat, allowing strategic heating
3. COP Optimization¶
Lower supply temps = higher efficiency = lower consumption
4. Solar Integration¶
Free heat from sun reduces need for heat pump operation
Limitations¶
Algorithm Assumptions
- Perfect forecasts: Assumes weather and price forecasts are accurate
- Simplified building model: Uses steady-state heat loss, not dynamic thermal modeling
- Fixed COP model: Assumes COP formula is accurate across all conditions
- No occupancy: Doesn't account for internal heat gains from people/appliances
Next Steps¶
Dive deeper into specific components:
- Dynamic Programming Details - Math and implementation
- COP Calculation - Heat pump efficiency modeling
- Buffer System - Thermal storage management
- Optimization Strategy - Advanced techniques
Explore: Real-World Examples to see the algorithm in action