Writing an histeresis automation for all climate entities

I would like to create an automation that checks all my climate devices each 5 minutes (time pattern trigger with /5) to see if any of the following conditions is true and then acts accordingly:

  • Last measured temperature >= setpoint temperature + 2 degrees —> change HVAC mode to off
  • Last measured temperature <= setpoint temperature - 1 degree —> change HVAC mode to heat

I’m struggling with defining this in yaml but it seems pretty straightforward. How would you guys approach this?

What have you tried so far?

The trigger you want is pretty straight forward, minutes: /5, if that’s all you need. My preference is to trigger on the rooms temperature sensor but I am sure 5 minute intervals would work equally well.

Is it the conditions you are struggling with?

A choose action with two separate options would do the trick, with a template condition for the logic you provided in each option. Here is an example to get you started;

{{ states('sensor.my_room_temp') | float(default=20) >= states('input_number.setpoint) | float(default=20) + 2 }}

Replace respective sensor names/defaults with your own

[edit] forgot to add the offset

What about a Generic Thermostat?