Hi there.
I am trying to template an automation for set up climate modes i my home assistant but I think I am doing someting wrong, the state never changes. Can some one point me to right direccion?
You should also include a condition to prevent the action from executing if the difference is less than 5 — at the moment, it’d fall through the if and elif, and try to set the hvac_mode to False.
Alternatively, do a template trigger to run only if the gap is bigger than 5 instead of your time_pattern trigger. Like this (untested; the abs filter in the trigger always returns a positive number for the gap):
This will trigger on every update of either sensor if the gap is larger than 5; and the template in the action determines whether to heat or cool. I think I have it the right way around…
Note I’ve corrected a typo: the service should be climate.set_hvac_mode.
If it still doesn’t work, please post a screenshot of climate.flow_thermostat from the Developer Tools / States page, showing the States and Attributes columns.
What if the temperature difference is neither less than -5 or greater than 5? For example, what if it’s -4 or 4 degrees (i.e. a value between -5 and 5)? Your template doesn’t handle that case so it will return an empty string value to hvac_mode which will cause an error message.
idle is an invalid value for hvac_mode. It’s a valid value for hvac_action (which is set by the integration, not a service call).
Unless your template ends with an else containing a valid hvac_mode value, it will produce an empty value when the temperature difference is between -5 and 5. The service call climate.set_hvac_mode won’t accept an empty value.