Generic thermostat: how to avoid some weird behaviour (an approach)

I use generic_thermostat to control my central heating.
It kind of works if you don’t use away_mode (but that’s another story), here’s my config

- platform: generic_thermostat
  name: thermostat
  heater: switch.combi_boiler
  target_sensor: sensor.composite_temperature
  ac_mode: false
  cold_tolerance: 0.2
  hot_tolerance: 0
  precision: 0.1
  min_cycle_duration: 300 # the boiler seem to have it as 5 mins
  # set it off and then change on HA start (after restoring all settings)
  initial_hvac_mode: 'off'

Today was the second time I noticed a very strange behaviour:

  • temperature of the target_sensor was below target_temp-cold_tolerance but the thermostat is off and not heating
  • then I called my script that changes the thermostat’s mode to heat and temperature to desired one (and it’s below temperature of the target_sensor)
  • the thermostat’s state changed to heating and my heater turned on and kept working despite target_sensor's value being above target_temp on the LL card - really weird!

The reason why it happens is as follows:
In my script I call set_hvac_mode (with hvac_mode: heat) first and then call set_temperature.
If the target_temp was set to a value that is higher than the current target_sensor's value minus cold_tolerance and the thermostat’s mode was changed to off, after set_hvac_mode: heat the thermostat comes back to work and first of all compares its target_sensor's value with still unchanged target_temp and as it’s below, the heater comes on. And when I set a new (lower) temperature, it does not seem to react and keeps on heating because in my config I have min_cycle_duration: 300, which makes it wait for 300 seconds before it can change state (turn the heater off in this case).

So the solution is simple and kind of obvious but I bet I’m not alone - you just need to make all changes and only when everything is configured, call set_hvac_mode.
Hope it helps someone.

I use generic thermostat too, it is always in heat mode and the only thing I ever change is the set point.
That changes according to if there are doors/windows open, The house is unoccupied and then on time of day.

I can explain why mine is off on HA start if you wish, it makes sense :wink: