Formatting templates in a script

Dear Community,

I need your help once again.

I want to control my air conditioner via Hassio. For this I have written a script (started by an automation), which should switch the air conditioning “on” or “off” depending on a sensor.

For this I want to use the following template in a script, which however does nothing. What I am doing wrong with this template?

  sequence:
    # Frostwaechter Poolhaus Hauptbereich EIN oder AUS schalten
    - service_template: >-
        {% if is_state('input_boolean.test_schalter', 'on') %}
          climate.set_hvac_mode
        target:
          entity_id: climate.klima_poolhaus
        data:
          hvac_mode: 'heat'
        {% else %}
          climate.set_hvac_mode
        target:
          entity_id: climate.klima_poolhaus
        data:
          hvac_mode: 'off'
        {% endif %}

If I only address the service (do not use a template) it works:

  sequence:
    # Frostwaechter Poolhaus Hauptbereich EIN oder AUS schalten
    - service: climate.set_hvac_mode
      target:
        entity_id: climate.klima_poolhaus
      data:
        hvac_mode: 'off'

What is wrong with my template? Is there perhaps a problem with the tabs (formatting)?
I thank you already for your support.

KR Markus

You don’t need to template the service, it is the same in both cases. The only thing that changes is the hvac_mode.

sequence:
    # Frostwaechter Poolhaus main area ON or OFF switch
    - service: climate.set_hvac_mode
      target:
        entity_id: climate.climate_poolhouse
      data:
        hvac_mode: >
          {% if is_state('input_boolean.test_switch', 'on') %}
            heat
          {% else %}
            off
          {% endif %}
1 Like

Many thanks Tom,

You made my day. It works now.

KR Markus

1 Like

hey @helfm, you might like to mark @tom_l’s post as the solution. This allows others to realise you no longer need help, allows others with the same problem to find the solution faster and finally gives @tom_l some credit for helping you out :+1:

Mann thx @jchh,

I will do it next time. Sorry.

KR Markus

No need to apologise!! :smiley: