Deprecation of legacy template entities in 2025.12

I have no idea if this will help anyone or not but here goes anyway…

First let’s imagine that you don’t use any !include in your configuration.yaml. So everything is contained in that one file.

if you have the old style templates in your configuration.yaml file will look like this:

binary_sensor:
  - platform: template
    sensors:
      my_first_binary_sensor:
        friendly_name: Some Name
        value_template: "{{ my template }}"
        icon_template: "{{ my icon template }}"
      my_second_binary_sensor:
        friendly_name: Some Other Name
        value_template: "{{ my next template }}"
        
sensor:
  - platform: template
    sensors:
      my_first_sensor:
        friendly_name: Some Sensor Name
        value_template: "{{ my template }}"
      my_second_sensor:
        friendly_name: Some Other Sensor Name
        value_template: "{{ my next template }}"
        icon_template: "{{ my icon template }}"

cover:
  - platform: template
    covers:
      my_first_cover:
        friendly_name: Some Cover Name
        value_template: "{{ my template }}"
      my_second_cover:
        friendly_name: Some Other Cover Name
        value_template: "{{ my next template }}"
        icon_template: "{{ my icon template }}"

etc
etc

to convert those to the new style templates you simply (and I mean simply…) do this:

(NOTE: default_entity_id: isn’t required. you only need it if you want to keep the same entity_id as the old sensor. Without it tyhe new entity _id will be the same as the name but all lower case with an underscore instead of spaces)

template:
  - binary_sensor:
      - default_entity_id: binary_sensor.my_first_binary_sensor
        name: Some Name
        state: "{{ my template }}"
        icon: "{{ my icon template }}"
      - default_entity_id: binary_sensor.my_second_binary_sensor:
        name: Some Other Name
        state: "{{ my next template }}"
        
  - sensor:
      - default_entity_id: sensor.my_first_sensor
        name: Some Sensor Name
        state: "{{ my template }}"
      - default_entity_id: sensor.my_second_sensor
        name: Some Other Sensor Name
        state: "{{ my next template }}"
        icon: "{{ my icon template }}"

  - cover:
      - default_entity_id: cover.my_first_cover
        name: Some Cover Name
        state: "{{ my template }}"
      - default_entity_id: cover.my_second_cover
        name: Some Other Cover Name
        state: "{{ my next template }}"
        icon: "{{ my icon template }}"

etc
etc

if you use !includes then you configuration.yaml will look like this before (for example):

binary_sensor: !include binary_sensors.yaml

sensor: !include sensors.yaml

cover: !include covers.yaml

then in the included yaml files:

binary_sensors.yaml:

  - platform: template
    sensors:
      my_first_binary_sensor:
        friendly_name: Some Name
        value_template: "{{ my template }}"
        icon_template: "{{ my icon template }}"
      my_second_binary_sensor:
        friendly_name: Some Other Name
        value_template: "{{ my next template }}"

sensors.yaml:

  - platform: template
    sensors:
      my_first_sensor:
        friendly_name: Some Sensor Name
        value_template: "{{ my template }}"
      my_second_sensor:
        friendly_name: Some Other Sensor Name
        value_template: "{{ my next template }}"
        icon_template: "{{ my icon template }}"

covers.yaml:

  - platform: template
    covers:
      my_first_cover:
        friendly_name: Some Cover Name
        value_template: "{{ my template }}"
      my_second_cover:
        friendly_name: Some Other Cover Name
        value_template: "{{ my next template }}"
        icon_template: "{{ my icon template }}"

then to use the new style templates using one single included file your configuration.yaml will look like this (for example):

binary_sensor: !include binary_sensors.yaml

sensor: !include sensors.yaml

cover: !include covers.yaml

template: !include templates.yaml

then in templates.yaml:

  - binary_sensor:
      - default_entity_id: binary_sensor.my_first_binary_sensor
        name: Some Name
        state: "{{ my template }}"
        icon: "{{ my icon template }}"
      - default_entity_id: binary_sensor.my_second_binary_sensor:
        name: Some Other Name
        state: "{{ my next template }}"
        
  - sensor:
      - default_entity_id: sensor.my_first_sensor
        name: Some Sensor Name
        state: "{{ my template }}"
      - default_entity_id: sensor.my_second_sensor
        name: Some Other Sensor Name
        state: "{{ my next template }}"
        icon: "{{ my icon template }}"

  - cover:
      - default_entity_id: cover.my_first_cover
        name: Some Cover Name
        state: "{{ my template }}"
      - default_entity_id: cover.my_second_cover
        name: Some Other Cover Name
        state: "{{ my next template }}"
        icon: "{{ my icon template }}"

If you use packages or directories then it’s very much the same but I don’t have time to do the conversion examples in this post.

4 Likes

Templates.yaml was the first one I tried with the covers - they were in configuration.yaml with the platform template. When that didn’t work I put the new format in configuration.yaml. When that didn’t work I went off on different paths hoping it was just placement or syntax.
Bottom line I pasted the suggested yaml sent to me in the deprecation notification. It worked for the 17 sensors it gave

Please share your attempted sensor and cover templates config. And if using includes then share how they are configured too.

I need some assistance with these yaml changes. I have 4x sensors in sensors.yaml, I have repair messages for all but the first entry “living Room”. I mucked around until I received the green tick in File Editor.

Back in my configuration.yaml I have the following line

sensor: !include sensors.yaml

But this produces the following

  • Invalid config for ‘sensor’ at sensors.yaml, line 3: required key ‘platform’ not provided, please check the docs at Sensor - Home Assistant
  • Invalid config for ‘sensor’ at sensors.yaml, line 13: required key ‘platform’ not provided, please check the docs at Sensor - Home Assistant
  • Invalid config for ‘sensor’ at sensors.yaml, line 23: required key ‘platform’ not provided, please check the docs at Sensor - Home Assistant
  • Invalid config for ‘sensor’ at sensors.yaml, line 33: required key ‘platform’ not provided, please check the docs at Sensor - Home Assistant

If i change configuration line to sensors: !include sensors.yaml i don’t receive the above errors.

From what I’ve read it appears I don’t need the sensors.yaml and can load all into configuration.yaml, is that the best approach?

This is my updated sensor.yaml. Thanks in advance :slight_smile:

template:
- sensor:
  - unique_id: hvac_living_room_temperature
    device_class: TEMPERATURE
    unit_of_measurement: °C
    default_entity_id: sensor.hvac_living_room_temperature
    icon: mdi:thermometer
    name: HVAC Living Room Temperature
    state: '{{ state_attr(''climate.device_02731d'',''current_temperature'') }}'

  template:
- sensor:
  - unique_id: hvac_office_temperature
    device_class: TEMPERATURE
    unit_of_measurement: °C
    default_entity_id: sensor.hvac_office_temperature
    icon: mdi:thermometer
    name: HVAC Office Temperature
    state: '{{ state_attr(''climate.device_02786c'',''current_temperature'') }}'

  template:
- sensor:
  - unique_id: hvac_lene_s_office_temperature
    device_class: TEMPERATURE
    unit_of_measurement: °C
    default_entity_id: sensor.hvac_lene_s_office_temperature
    icon: mdi:thermometer
    name: HVAC Lene's Office Temperature
    state: '{{ state_attr(''climate.device_0276f8'',''current_temperature'') }}'

  template:
- sensor:
  - unique_id: hvac_bedroom_temperature
    device_class: TEMPERATURE
    unit_of_measurement: °C
    default_entity_id: sensor.hvac_bedroom_temperature
    icon: mdi:thermometer
    name: HVAC Bedroom Temperature
    state: '{{ state_attr(''climate.device_0279b3'',''current_temperature'') }}'

guess my day is done lol, 200 to do :rofl:

and then once I add more than a few of the suggestions I get issues lol


I am sure blue means its not registering :stuck_out_tongue:

Solved: I had to change the way includes are written in configuration.yaml:
template: !include_dir_merge_list _switches/

I also removed template: from the individual yaml files leaving -switch on top of each entry.

- switch:
    - name: Heater
      state: "{{ is_state('input_boolean.heater', 'on') }}"
      turn_on:
        - service: input_boolean.turn_on
          target:
            entity_id: input_boolean.heater
        - service: switch.turn_on
          target:
            entity_id: switch.heater_smart_plug
        - delay: "00:00:01"
        - service: script.heater_power
      turn_off:
        - service: input_boolean.turn_off
          target:
            entity_id: input_boolean.heater
        - service: switch.turn_off
          target:
            entity_id: switch.heater_smart_plug

- switch:
    - name: AC Power
      state: "{{ is_state('input_boolean.ac_power', 'on') }}"
      turn_on:
        - service: input_boolean.turn_on
          target:
            entity_id: input_boolean.ac_power
        - service: switch.turn_on
          target:
            entity_id: switch.ge_ac_power_status
      turn_off:
        - service: input_boolean.turn_off
          target:
            entity_id: input_boolean.ac_power
        - service: switch.turn_off
          target:
            entity_id: switch.ge_ac_power_status

Original post:
Can i still use subfolders for this? I tried fixing my yaml using the suggestions but the automations aren’t triggering the switches. The switches don’t show up in Devices and Services either. I put the code directly the configuration.yaml and still got nothing. The legacy code still works when i revert back.

Configuration.yaml:
switch custom: !include_dir_merge_list _switches/

_switches\evironment.yaml legacy code:

- platform: template
  switches:  
    heater:
      value_template: "{{ is_state('input_boolean.heater', 'on') }}"
      turn_on:
        - service: input_boolean.turn_on
          entity_id: input_boolean.heater
        - service: switch.turn_on
          entity_id: switch.heater_smart_plug
        - delay: '00:0:01'
        - service: script.heater_power
      turn_off:
        - service: input_boolean.turn_off
          entity_id: input_boolean.heater
        - service: switch.turn_off
          entity_id: switch.heater_smart_plug

- platform: template
  switches:
    ac_power:
      value_template: "{{ is_state('input_boolean.ac_power', 'on') }}"
      turn_on:
        - service: input_boolean.turn_on
          entity_id: input_boolean.ac_power
        - service: switch.turn_on
          entity_id: switch.ge_ac_power_status
      turn_off:
        - service: input_boolean.turn_off
          entity_id: input_boolean.ac_power
        - service: switch.turn_off
          entity_id: switch.ge_ac_power_status

Suggested code:

template:
- switch:
  - turn_on:
    - entity_id:
      - input_boolean.heater
      action: input_boolean.turn_on
    - entity_id:
      - switch.heater_smart_plug
      action: switch.turn_on
    - delay: 0:00:01
    - action: script.heater_power
    turn_off:
    - entity_id:
      - input_boolean.heater
      action: input_boolean.turn_off
    - entity_id:
      - switch.heater_smart_plug
      action: switch.turn_off
    default_entity_id: switch.heater
    state: '{{ is_state(''input_boolean.heater'', ''on'') }}'
    name: heater
    
template:
- switch:
  - turn_on:
    - entity_id:
      - input_boolean.ac_power
      action: input_boolean.turn_on
    - entity_id:
      - switch.ge_ac_power_status
      action: switch.turn_on
    turn_off:
    - entity_id:
      - input_boolean.ac_power
      action: input_boolean.turn_off
    - entity_id:
      - switch.ge_ac_power_status
      action: switch.turn_off
    default_entity_id: switch.ac_power
    state: '{{ is_state(''input_boolean.ac_power'', ''on'') }}'
    name: ac_power

Like you I had a number of template sensors in yaml.

I decided to just re-create them in the GUI with Helpers (Helpers-create Helper-Template-Sensor) - and then delete them in the yaml file.

I just had to add this to configuration.yaml instead:
template: !include_dir_merge_list _switches/

I also removed template: from the individual yaml files leaving -switch on top of each entry.

Everthing below #aqi template is not working because of a missing space between # and aqi template

And is this the whole file, or is there more above? The syntax colors for that first one look weird as well

The template integration does not go inside the sensor integration. It stands on its own.

And you only need one template: integration. Like this in your configuration.yaml file:

template:
- sensor:
  - unique_id: hvac_living_room_temperature
    device_class: TEMPERATURE
    unit_of_measurement: °C
    default_entity_id: sensor.hvac_living_room_temperature
    icon: mdi:thermometer
    name: HVAC Living Room Temperature
    state: '{{ state_attr(''climate.device_02731d'',''current_temperature'') }}'

  - unique_id: hvac_office_temperature
    device_class: TEMPERATURE
    unit_of_measurement: °C
    default_entity_id: sensor.hvac_office_temperature
    icon: mdi:thermometer
    name: HVAC Office Temperature
    state: '{{ state_attr(''climate.device_02786c'',''current_temperature'') }}'

  - unique_id: hvac_lene_s_office_temperature
    device_class: TEMPERATURE
    unit_of_measurement: °C
    default_entity_id: sensor.hvac_lene_s_office_temperature
    icon: mdi:thermometer
    name: HVAC Lene's Office Temperature
    state: '{{ state_attr(''climate.device_0276f8'',''current_temperature'') }}'

  - unique_id: hvac_bedroom_temperature
    device_class: TEMPERATURE
    unit_of_measurement: °C
    default_entity_id: sensor.hvac_bedroom_temperature
    icon: mdi:thermometer
    name: HVAC Bedroom Temperature
    state: '{{ state_attr(''climate.device_0279b3'',''current_temperature'') }}'

Or you can use a new !include if you want to. e.g.

configuration.yaml

template: !include templates.yaml

Then in templates.yaml:

- sensor:
  - unique_id: hvac_living_room_temperature
    device_class: TEMPERATURE
    unit_of_measurement: °C
    default_entity_id: sensor.hvac_living_room_temperature
    icon: mdi:thermometer
    name: HVAC Living Room Temperature
    state: '{{ state_attr(''climate.device_02731d'',''current_temperature'') }}'

  - unique_id: hvac_office_temperature
    device_class: TEMPERATURE
    unit_of_measurement: °C
    default_entity_id: sensor.hvac_office_temperature
    icon: mdi:thermometer
    name: HVAC Office Temperature
    state: '{{ state_attr(''climate.device_02786c'',''current_temperature'') }}'

  - unique_id: hvac_lene_s_office_temperature
    device_class: TEMPERATURE
    unit_of_measurement: °C
    default_entity_id: sensor.hvac_lene_s_office_temperature
    icon: mdi:thermometer
    name: HVAC Lene's Office Temperature
    state: '{{ state_attr(''climate.device_0276f8'',''current_temperature'') }}'

  - unique_id: hvac_bedroom_temperature
    device_class: TEMPERATURE
    unit_of_measurement: °C
    default_entity_id: sensor.hvac_bedroom_temperature
    icon: mdi:thermometer
    name: HVAC Bedroom Temperature
    state: '{{ state_attr(''climate.device_0279b3'',''current_temperature'') }}'

Finally if you want long term statistics for those sensors then each one should have an additional option state_class: measurement

2 Likes

Hey, I just wanted to report that for me the migration guide in the warning worked perfectly for me. Gave me a slight scare considering my templates but all went smoothly on my end :slight_smile:
I also used this chance to migrate away from configuration.yml to a template folder like you showed @petro

1 Like

I was given a suggestion for below but the formatting was all to pot so im looking to see if someone can suggest what this template sensor should look like in the new format.

Once i understand one i can attack the other 176 errors lol

current_switches_on:
  unique_id: current_switches_on
  unit_of_measurement: "ON"
  value_template: >-
    {% set switches = [
      states.switch.alexa_power_hub,
      states.switch.charlottes_bedroom_speakers,
      states.switch.charlottes_leds_mains,
      states.switch.charlottes_tv_mains,
      states.switch.dressing_room_speakers,
      states.switch.dressing_room_tv_mains,
      states.switch.dressing_room_tv_spare_mains,
      states.switch.echo_show_15_mains,
      states.switch.en_suite_extractor_fan,
      states.switch.home_audio,
      states.switch.katies_bedroom_speakers,
      states.switch.katies_leds_mains,
      states.switch.katies_tv_mains,
      states.switch.kitchen_speakers,
      states.switch.kitchen_tv_mains,
      states.switch.kitchen_tv_socket_left,
      states.switch.living_room_tv_backlight_mains,
      states.switch.living_room_tv_mains,   
      states.switch.loft_internet_mains,  
      states.switch.loft_powerbar_mains,    
      states.switch.master_bedroom_socket_1_socket_1,
      states.switch.master_bedroom_socket_1_socket_2, 
      states.switch.master_bedroom_speakers,
      states.switch.master_bedroom_tv,
      states.switch.printer_mains,          
      states.switch.projector_and_screen,
      states.switch.ps5_mains,
      states.switch.qbittorrent_alternative_speed,  
      states.switch.tumble_dryer_mains,  
      states.switch.washing_machine_mains,      
      states.switch.upstairs_bathroom_extractor_fan,   
      states.switch.xbox_s_mains,  
      states.switch.xbox_x_mains
    ] %}
    {{ switches | selectattr('state','eq','on') | list | count }}

configuration.yaml

template:
  - sensor:
      - name: Current Switches On
        unique_id: current_switches_on
        unit_of_measurement: "ON"
        state: >
          {% set switches = [
            states.switch.alexa_power_hub,
            states.switch.charlottes_bedroom_speakers,
            states.switch.charlottes_leds_mains,
            states.switch.charlottes_tv_mains,
            states.switch.dressing_room_speakers,
            states.switch.dressing_room_tv_mains,
            states.switch.dressing_room_tv_spare_mains,
            states.switch.echo_show_15_mains,
            states.switch.en_suite_extractor_fan,
            states.switch.home_audio,
            states.switch.katies_bedroom_speakers,
            states.switch.katies_leds_mains,
            states.switch.katies_tv_mains,
            states.switch.kitchen_speakers,
            states.switch.kitchen_tv_mains,
            states.switch.kitchen_tv_socket_left,
            states.switch.living_room_tv_backlight_mains,
            states.switch.living_room_tv_mains,   
            states.switch.loft_internet_mains,  
            states.switch.loft_powerbar_mains,    
            states.switch.master_bedroom_socket_1_socket_1,
            states.switch.master_bedroom_socket_1_socket_2, 
            states.switch.master_bedroom_speakers,
            states.switch.master_bedroom_tv,
            states.switch.printer_mains,          
            states.switch.projector_and_screen,
            states.switch.ps5_mains,
            states.switch.qbittorrent_alternative_speed,  
            states.switch.tumble_dryer_mains,  
            states.switch.washing_machine_mains,      
            states.switch.upstairs_bathroom_extractor_fan,   
            states.switch.xbox_s_mains,  
            states.switch.xbox_x_mains
          ] %}
          {{ switches | selectattr('state','eq','on') | list | count }}

Hi

Luckily i only had about 20 issues to fix, but im getting warnings about some of my remaingin items in sensors.yaml, and i cant find a way to recreate them under templates.yaml. Can someone please provide me with some advice how to update them. Thanks

- platform: integration
  source: sensor.current_sensor_pzem_004t_v3_power_2
  name: current_sensor_pzem_004t_v3_energy_kw
  unique_id: 1b9a9cdb-5113-4fc2-afac-2a8750a1a068
  round: 3
  unit_prefix: k

- platform: average
  name: "Inverter 1 Average discharge"
  duration:
    minutes: 5
  entities:
    - sensor.inverter_1_battery_charge_apms

- platform: average
  name: "Inverter 2 Average discharge"
  duration:
    minutes: 5
  entities:
    - sensor.inverter_2_battery_charge_apms

- platform: history_stats
  type: time
  name: Study Extractor Fan On Today
  entity_id: switch.study_extractor_fan_study_extractor_fan
  state: "on"
  start: "{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}"
  end: "{{ now() }}"

- platform: history_stats
  type: time
  name: Inverter 1 High Power Off Today
  entity_id: scene.high_power_devices_off_inv1
  state: "on"
  start: "{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}"
  end: "{{ now() }}"

- platform: history_stats
  type: time
  name: Inverter 2 High Power Off Today
  entity_id: scene.high_power_devices_inv2
  state: "on"
  start: "{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}"
  end: "{{ now() }}"

Those aren’t template sensors, they should remain in your sensors.yaml

This change only applies to platform: template

Great almost 100 sensors to reconfigure…
And i guess recreating them will create new sensors and loose all history graphs?

A number in this list was really helpfull, now i have to click one by one, and soemtimes i dont even know what i clicked anymore, because the popup comes before the list …

Not if you keep the same unique_id and entity_id.

so i would have to delete each old sensor while creating the new sensor with the same ids one by one and reboot homeassistant so the history is transfered to new sensors?

You can do more than one at once. Though starting with one or two is a good idea. Just to make sure you have the format right.

Also I would suggest commenting out your old sensors rather than deleting them. Just so you have the reference there until everything is confirmed as working.

1 Like