Furnace Circulate Automation via Template?

I’ve recently replaced my thermostat with a CT101 and added the new unit to my HA installation.

I’ve created some basic automation to periodically start and stop the furnace fan to circulate air. However, the current logic is rather clunky in that it doesn’t take into account whether the furnace’s current mode is currently needed.

This seems like something I should be able to do in a single automation and it seems like templating is the tool I should use to do it. I’m just not fully wrapping my head around how to integrate the templating with HA automation UI. Using the Templates portion of the UI I came up with the what’s shown below. Am I on the right track, anyone have advice/pointers on how to get this into the Automation UI?

{% set thermostat = states.climate.thermostat_32 %}
{% set current_temp = thermostat.attributes.current_temperature %}
{% set target_temp = thermostat.attributes.temperature %}

{# save the current furnace mode #}
{% set original_mode = thermostat.attributes.operation_mode %}

{# do we need to leave the mode active? #}
{% if thermostat.attributes.operation_mode  == 'heat' %}
    {% if current_temp > target_temp %}
-data:
    entity_id: {{ thermostat.entity_id }}
    operation_mode: 'off'
  service: climate.set_operation_mode
    {% endif %}
{% elif thermostat.attributes.operation_mode  == 'cool' %}
    {% if current_temp < target_temp %}
-data:
    entity_id: {{ thermostat.entity_id }}
    operation_mode: 'off'
  service: climate.set_operation_mode
    {% endif %}
{% endif %}

{# begin circulating air #}
- data:
    entity_id: {{ thermostat.entity_id }}
    fan_mode: on
  service: climate.set_fan_mode

{# delay here #}
- delay: 0:10

{# restore original mode #}
-data:
    entity_id: {{ thermostat.entity_id }}
    operation_mode: '{{ original_mode }}'
  service: climate.set_operation_mode
{# set fan auto #}
- data:
    entity_id: {{ thermostat.entity_id }}
    fan_mode: auto
  service: climate.set_fan_mode

You can only use templates in designated templating fields and they cannot span multiple fields. So pretty much your entire section you posted won’t work.

  single_yaml_field_template: >
    {% do stuff%}
    {% more stuff %}
    {{ output my stuff }}
  different_yaml_field_template: >
    {% can't use crap from other template %}

Typically, fields that have _template in them allow templates with the exception of data_template. Any field under data_template can be templated:

  data_template:
    field1: >
      {{ blah }}
    field2: >
      {{ blah blah }}