TapHome

Bivalent Heating: Heat Pump and Gas Boiler by Outdoor Temperature

Switch between a heat pump and a gas boiler when the outdoor temperature stays below or above a threshold for several hours, with one Equation smart rule and two statistics.

Last updated:

A heat pump runs most of the year and the gas boiler stays blocked. Only when it has been freezing for a longer time does the system switch to the gas boiler and block the heat pump, and it switches back only after a longer mild period. One Equation smart rule and two statistics of the outdoor temperature do this without any script.

The example uses −5 °C for 3 hours to switch to the boiler and 0 °C for 12 hours to switch back. Thresholds and durations are yours to choose.

You need:

  • an outdoor temperature sensor,
  • an output that turns the gas boiler on,
  • an output that blocks the heat pump.

How it works

  • The Maximum of the outdoor temperature over the last 3 hours is −5 °C or lower only if the temperature stayed at −5 °C or lower for the whole 3 hours. One warmer reading inside the window raises the maximum and the countdown starts again.
  • The Minimum over the last 12 hours is 0 °C or higher only if the temperature stayed at 0 °C or higher for the whole 12 hours.
  • Between the two thresholds the rule has to remember what it did last. That is the LastState variable: the previous result of this Equation. Without it, the boiler would switch off as soon as the temperature rose from −6 °C to −2 °C, although 12 hours above zero have not passed yet.

Both statistics use Period type Period to now: a rolling window that ends at this moment and moves on with time. Current period is a fixed calendar period (the current hour from the full hour, the current day from midnight) that starts again at its beginning, so it cannot tell how long a condition has lasted.

Create the statistics

Open the detail of the outdoor temperature sensor, then Statistics, and add two statistics:

StatisticsPeriod typeDuration
MaximumPeriod to now3 hours
MinimumPeriod to now12 hours

Create the statistics before the smart rule. The variable picker of the Equation lists only statistics that already exist on the device. A variable whose statistic does not exist stays empty and the rule never reacts, without showing an error.

Create the Equation smart rule

Variables

Add the outdoor temperature sensor twice and pick a statistic from the Statistics part of the list each time:

  • Maximum, Period to now, 3 hours — rename the variable to TMAX3
  • Minimum, Period to now, 12 hours — rename the variable to TMIN12

Equation

TMAX3 <= -5 OR (LastState AND !(TMIN12 >= 0))

The operators are AND, OR and ! — && and || do not exist in the TapHome script. !(TMIN12 >= 0) keeps the boiler running while the 12-hour minimum has no value yet.

If result is TRUE, perform following actions:

  • Gas boiler — turn on
  • Heat pump block — turn on

If result is FALSE, perform following actions:

  • Gas boiler — turn off
  • Heat pump block — turn off

Behaviour over time

The grey lanes are what the rule watches: the outdoor temperature (shape only, without a scale) and the two statistics. A striped bar is a window counting down, a dashed outline is a countdown cancelled by a warmer reading. The blue lanes are what the rule switches. The time axis is in hours and to scale.

Equation
1 2 3 4 5 6
Outdoor temperature
Maximum3 hours
Minimum12 hours
Boiler
Heat pump
  1. The temperature drops below −5 °C and the 3-hour countdown starts.
  2. A warmer hour (−3 °C) cancels the countdown. The 3 hours start again when it is below −5 °C once more.
  3. After 3 hours below −5 °C the result is TRUE: the boiler turns on and the heat pump is blocked.
  4. The temperature rises to −2 °C. The maximum is above −5 °C now, but LastState keeps the boiler running.
  5. The temperature reaches 0 °C and the 12-hour countdown starts.
  6. After 12 hours at 0 °C or above the result is FALSE: the boiler turns off and the heat pump runs again.

Alternative with two smart rules

The same works without LastState, with two Equation smart rules: one only switches to the boiler (TMAX3 <= -5, actions only for TRUE), the other only switches back (TMIN12 >= 0, actions only for TRUE). Both act on the same outputs, so check their order on the outputs. The pattern is described in Hysteresis equation.

Things to keep in mind

  • Accuracy. The Core recalculates the statistics about every minute, also when no new reading comes. The 3-hour window follows the readings to about a minute. The 12-hour window is built from hourly blocks, so the switch back can come about an hour earlier or later.
  • Partial window after creating the statistics. A new statistic has no history yet. If you create the rule during frost below −5 °C, the boiler turns on immediately; during the first 12 hours the minimum covers only the time since the statistic was created.
  • Saving resets LastState. Every saved change of the rule starts it again with LastState FALSE. If you save it while the boiler runs and the temperature is between −5 °C and 0 °C, the system switches back to the heat pump. A restart of the Core does not reset it.
  • Manual changes stay. A manual change of the boiler or the heat pump block is not overridden while the result stays the same; the rule takes the outputs back when its result changes.

See also — Statistic values in smart rules, Hysteresis equation, Equithermic regulation, Boiler cascade.