Using helper in climate.set_temperature?

I have some automations to change the temperature on my two zigbee thermostats at different times of the day. I tried to use a helper which can be set using a slider on my dashboard (so in different seasons we can adjust the low/high temps we want) but it seems like the climate.set_temperature service doesn’t accept the name of a helper for target_temp_low/high ??

Is there some way to make this sort of thing work?

Use a template to get the input_number’s value.

    - service: climate.set_temperature
      target:
        entity_id: climate.kitchen
      data:
        target_temp_high: "{{ states('input_number.your_high_choice') }}"
        target_temp_low: "{{ states('input_number.your_low_choice') }}"
        hvac_mode: heat_cool
2 Likes

Perfect. I haven’t yet delved particularly far into templates, but I guess I should at least become familiar with them. What’s the best quick-start guide?

Let me know if you have any questions.

Yeah, my first question is, conceptually, what the heck is a template doing? Is it textual replacement? Is it a function that gets run at automation execution time? It seems like it’s tied to Python, but can it use arbitrary python code? Is it something else? I feel like the documentation assumes a base level of understanding that is missing. Just pointing at Jinja to say “we’re using their template system” is already sort of putting the cart before the horse. Is there a better intro to templates conceptually, like something that describes what the full range of problems is they are supposed to solve and how they go about solving it?

Home Assistant employs other open-source software products and tools (python, YAML, Jinja2, etc). Documentation for the other tools isn’t replicated in Home Assistant’s documentation; one uses the product’s own documentation. That’s why, for example, the section on templating, contains a link to Jinja2’s documentation.

The link I posted above leads to an explanation of how the Jinja2 templating language is employed in Home Assistant. It describes templating functions that are unique to Home Assistant (i.e. not a standard part of Jinja2). It also provides examples of how the functions are used to process data (read, calculate, search, etc).

Everything between {{ }} or {% %} is processed by the Jinja2 processor. You can easily experiment with Jinja2 templates in the Template Editor (in the main menu: Developer Tools > Template).

For example, this gets a sensor’s value, converts it to a floating point number, then rounds it.

{{ states('sensor.whatever') | float(0) | round(2) }}

This template might be used in a Template Sensor or in a service call or wherever a computed value is permitted.

The Jinja2 templating language was developed for use with python so, naturally, some measure of python is permitted within a template.

What’s important to keep in mind is the boundary between what’s YAML and what’s Jinja2. In my first post I showed you how to employ a template to supply a value for target_temp_high. The target_temp_high is YAML and part of the entire service call to climate.set_temperature. It expects to be supplied with a value and that’s what the template does, it gets the input_number’s value and assigns it to target_temp_high.

1 Like

At what point is it processed? For example can a template be used in a trigger? or do triggers have to be fixed values and only actions can be templated because the template is run after the trigger?

Typically, the template is evaluated when one of the entities within it changes state. There are other things that can cause the template to be evaluated (for example, if it contains now() it will be evaluated at least every minute) but that’s the most common one.

Reference: Rate limiting updates

Yes, templates are supported by the Template Trigger.