Confused template in configuration.yaml

I can´t get this to work in the latest version of HA. There was a message that switch was depreciated and i tried to fix that but also lost the initial config. how should i do this.


template:
- switch:
  - platform: template
    switches:
      garage_door_1:
        value_template: "{{ is_state_attr('binary_sensor.garage_1_input', 'sensor_state', 'off') }}"
        turn_on:
          service: switch.toggle
          target:
            device_id: 24b0defe694c887c3b02fbf6cdb9b066
        turn_off:
          service: switch.turn_off
          target:
            device_id: 24b0defe694c887c3b02fbf6cdb9b066
        icon_template: >-
          {% if is_state('binary_sensor.garage_1_input', 'on') %}
            mdi:garage
          {% else %}
            mdi:garage-open
          {% endif %}

      garage_door_2:
        value_template: "{{ is_state_attr('binary_sensor.garage2_input', 'sensor_state', 'off') }}"
        turn_on:
          service: switch.toggle
          target:
            device_id: 07150b5772ce8095cb7392aa20b0426e
        turn_off:
          service: switch.turn_off
          target:
            device_id: 07150b5772ce8095cb7392aa20b0426e
        icon_template: >-
          {% if is_state('binary_sensor.garage2_input', 'on') %}
            mdi:garage
          {% else %}
            mdi:garage-open
          {% endif %}

The new syntax is documented here: https://www.home-assistant.io/integrations/template/#switch

Converting your config above (which TBH looks kinda odd):

configuration.yaml:

template:
  - switch:
      - name: Garage Door 1
        state: "{{ is_state_attr('binary_sensor.garage_1_input', 'sensor_state', 'off') }}"
        turn_on:
          service: switch.toggle
          target:
            device_id: 24b0defe694c887c3b02fbf6cdb9b066
        turn_off:
          service: switch.turn_off
          target:
            device_id: 24b0defe694c887c3b02fbf6cdb9b066
        icon: >
          {% if is_state('binary_sensor.garage_1_input', 'on') %}
            mdi:garage
          {% else %}
            mdi:garage-open
          {% endif %}

      - name: Garage Door 2
        state: "{{ is_state_attr('binary_sensor.garage2_input', 'sensor_state', 'off') }}"
        turn_on:
          service: switch.toggle
          target:
            device_id: 07150b5772ce8095cb7392aa20b0426e
        turn_off:
          service: switch.turn_off
          target:
            device_id: 07150b5772ce8095cb7392aa20b0426e
        icon: >
          {% if is_state('binary_sensor.garage2_input', 'on') %}
            mdi:garage
          {% else %}
            mdi:garage-open
          {% endif %}

If you need more help see the pinned topic about this here: Deprecation of legacy template entities in 2025.12

Thank you tom, your changes saved the day. In studio code server it looks if your code is wrong (patternWarning on all switch. services) but it does seem to work. So editing in the visual studio code plugin was a source of my confusion.

If you want to keep things a bit more tidy in configuration.yaml you could add template: !include template.yaml to it, create a file in the same folder called template.yaml and paste your templates into that. Remove template from line 1 and add your code to template.yaml:

 - switch:
    - name: Garage Door 1
      state: "{{ is_state_attr('binary_sensor.garage_1_input', 'sensor_state', 'off') }}"
and so on

Thanks added that to the list. I now have these files.

template: !include template.yaml
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
secrets: !include secrets.yaml

Kind regards Martin

1 Like