Multiple sensors and template sensors in templates.yaml

Hi everyone,

I have tried to find the proper solution ind docs, this forum, but find none.
I think I am loosing my mind a little bit now.
It has stared when templates syntax changed at the end of the year 2025 and my templates are not working anymore.

The following is my old templates.yaml:

template:
  sensor:
    dimplex_mode_text:
      friendly_name: 'Dimplex Mode Text'
      value_template: >
        {% set mapper = {
          '0': 'Summer',
          '1': 'Auto',
          '2': 'Holiday',
          '3': 'Party',
          '4': '2nd heat generator',
          '5': 'Cooling'} %}
        {% set state =  states.sensor.dimplex_mode_2.state %}
        {{ mapper[state] if state in mapper else 'Unknown' }}
    outside_temperature:
      friendly_name: 'Outside Temperature'
      unit_of_measurement: '°C'
      value_template: "{{ state_attr('weather.forecast_domov', 'temperature') }}"
    dimplex_status_text:
      friendly_name: 'Dimplex Status Text'
      value_template: >
        {% set mapper = {
          '0': 'off',
          '1': 'Heat pump One heating',
          '2': 'Heat pump One heating',
          '3': 'Heat pump A swimming pool',
          '4': 'Heat pump One hot water',
          '5': 'Heat pump One heating + 2.heat generator',
          '6': 'Heat pump One swimming pool + 2.heat generator',
          '7': 'Heat pump A hot water + 2.heat generator',
          '8': 'Primary pump feed',
          '9': 'Heating sinks',
          '10': 'Lock',
          '11': 'Lower operating limit',
          '12': 'Low pressure limit',
          '13': 'Low-pressure shutdown',
          '14': 'High pressure protection',
          '15': 'Switching game lock',
          '16': 'Minimum order period',
          '17': 'Grid load',
          '18': 'Flow monitoring',
          '19': '2.Heat generators',
          '20': 'Low pressure brine',
          '21': 'Heat pump In defrosting',
          '22': 'Upper operating limit',
          '23': 'Block External',
          '24': 'Operating mode cooling',
          '25': 'Frost protection cold',
          '26': 'Preliminary limit',
          '27': 'Dew point guards',
          '28': 'Dew point',
          '29': 'Cooling passive',
          '30': ' '} %}
        {% set state =  states.sensor.dimplex_status.state %}
        {{ mapper[state] if state in mapper else 'Unknown' }}
    # Hvac Activiy 
    #hvac_activity:
      #friendly_name: 'HVAC Activity'
      #value_template: '{{ state_attr("climate.madimack_elite_v3_pool_heatpump", "hvac_action") }}'
    hvac_mode:
      friendly_name: 'HVAC Mode'
      value_template: '{{ state_attr("climate.madimack_elite_v3_pool_heatpump", "preset_mode") }}'
    daily_PVE_generation_treshold:
      friendly_name: 'Expected minimal daily PVE generation'
      value_template: '{{ states("sensor.solcast_pv_forecast_predpoved_dnes")|float * 0.8}}'
      
#helper sensor for hikvision doorbell - using intercom button "call status" attribbute CallStatus status ('idle'|'ring')
#helper for incoming SMS from Alarm (to check last notification date for "Home Alarm" state)
    RingBell:
        state: "{{ state_attr('button.intercom_call_status','CallStatus').status }}"
    AlarmSMS:
        state: "{{ state_attr('sensor.sm_s926b_s24_last_notification','android.messages')[-1][1:-1].split(', ')[2].split('=')[1] == 'Home Alarm'}}"
        attributes: 
          history: "{{ state_attr('sensor.sm_s926b_s24_last_notification','android.messages')[-1][1:-1].split(', ')[8].split('=')[1][:-3] | int (1) | timestamp_local }}"

#helper for PV Excess automation 
  switch:
        keba: # Keba does not have enable/disable switch
          friendly_name: "Keba"
          turn_on:
            action: button.press
            target:
              entity_id: button.keba_p30_de_enable
          turn_off:
            action: button.press
            target:
              entity_id: button.keba_p30_de_disable
        bazen_tepelko: # heatpump does not have enable switch, just hvac mode
          friendly_name: "BazenTepelko"
          turn_on:
            action: switch.turn_on
            target:
              entity_id: switch.tepelko_bazen_prepinac # http://homeassistant.local:8123/config/devices/device/b7c3ea15acb611210385403f8ac700e3 - cloud tuya device
          turn_off:
            action: switch.turn_off
            target:
              entity_id: switch.tepelko_bazen_prepinac # http://homeassistant.local:8123/config/devices/device/b7c3ea15acb611210385403f8ac700e3 - cloud tuya device

I have the following in the configuration.yaml:

...
modbus: !include modbus.yaml
sensor: !include sensors.yaml
template: !include templates.yaml
...

So I have several sensor types in the templates.yaml.

I know I have duplicity in the templates.yaml, the “template:” in the first line.
Even If i removed that one, and moved the whole section up, I got another error:
“Missing property state”.

So I tried with just state regular sensors and removed everything else:
templates.yaml:

sensor:
#helper sensor for hikvision doorbell - using intercom button "call status" attribute CallStatus status ('idle'|'ring')
#helper for incoming SMS from Alarm (to check last notification date for "Home Alarm" state)
    name: RingBell
    state: "{{ state_attr('button.intercom_call_status','CallStatus').status }}"
    
    name: AlarmSMS
    state: "{{ state_attr('sensor.sm_s926b_s24_last_notification','android.messages')[-1][1:-1].split(', ')[2].split('=')[1] == 'Home Alarm'}}"
    attributes: 
      history: "{{ state_attr('sensor.sm_s926b_s24_last_notification','android.messages')[-1][1:-1].split(', ')[8].split('=')[1][:-3] | int (1) | timestamp_local }}"

I have “Map keys must be unique” error now, so I couldn’t even put more basic sensors into one template file.

Any help appreciated.
Thanks.

Don’t put template: in your templates yaml file. When you use an include it is replaced by the file contents. So you are getting this:

template:
  template:
    sensor:

Instead of just:

template:
  sensor:

Also you have not migrated any of the config correctly. e.g. there is no value_template: in the new format. It is now state:

The are a whole bunch of other issues too. Not least of which is that the entities must be a list (use -).

template:
  - sensor:
      - name: etc...

  - switch:
      - name: etc...

The migration guide documentation is here: Template - Home Assistant

If after reading that you are still having issues then ask in the pinned help topic here: Deprecation of legacy template entities in 2025.12

1 Like

Thanks a lot, everything is working right now.
The following is my corrected templates.yaml configuration based upon your hints just to inspire anyone else:

- sensor:
    - name: dimplex_mode_text
      #friendly_name: 'Dimplex Mode Text'
      state: >
        {% set mapper = {
          '0': 'Summer',
          '1': 'Auto',
          '2': 'Holiday',
          '3': 'Party',
          '4': '2nd heat generator',
          '5': 'Cooling'} %}
        {% set state =  states.sensor.dimplex_mode_2.state %}
        {{ mapper[state] if state in mapper else 'Unknown' }}
    - name: outside_temperature
      #friendly_name: 'Outside Temperature'
      unit_of_measurement: '°C'
      state: "{{ state_attr('weather.forecast_domov', 'temperature') }}"
    - name: dimplex_status_text
      #friendly_name: 'Dimplex Status Text'
      state: >
        {% set mapper = {
          '0': 'off',
          '1': 'Heat pump One heating',
          '2': 'Heat pump One heating',
          '3': 'Heat pump A swimming pool',
          '4': 'Heat pump One hot water',
          '5': 'Heat pump One heating + 2.heat generator',
          '6': 'Heat pump One swimming pool + 2.heat generator',
          '7': 'Heat pump A hot water + 2.heat generator',
          '8': 'Primary pump feed',
          '9': 'Heating sinks',
          '10': 'Lock',
          '11': 'Lower operating limit',
          '12': 'Low pressure limit',
          '13': 'Low-pressure shutdown',
          '14': 'High pressure protection',
          '15': 'Switching game lock',
          '16': 'Minimum order period',
          '17': 'Grid load',
          '18': 'Flow monitoring',
          '19': '2.Heat generators',
          '20': 'Low pressure brine',
          '21': 'Heat pump In defrosting',
          '22': 'Upper operating limit',
          '23': 'Block External',
          '24': 'Operating mode cooling',
          '25': 'Frost protection cold',
          '26': 'Preliminary limit',
          '27': 'Dew point guards',
          '28': 'Dew point',
          '29': 'Cooling passive',
          '30': ' '} %}
        {% set state =  states.sensor.dimplex_status.state %}
        {{ mapper[state] if state in mapper else 'Unknown' }}
  # Hvac Activiy 
  #hvac_activity:
    #friendly_name: 'HVAC Activity'
    #value_template: '{{ state_attr("climate.madimack_elite_v3_pool_heatpump", "hvac_action") }}'
    - name: hvac_mode
      #friendly_name: 'HVAC Mode'
      state: '{{ state_attr("climate.madimack_elite_v3_pool_heatpump", "preset_mode") }}'
    - name: daily_PVE_generation_treshold
      #friendly_name: 'Expected minimal daily PVE generation'
      state: '{{ states("sensor.solcast_pv_forecast_predpoved_dnes")|float * 0.8}}'
#helper sensor for hikvision doorbell - using intercom button "call status" attribbute CallStatus status ('idle'|'ring')
#helper for incoming SMS from Alarm (to check last notification date for "Home Alarm" state)
    - name: RingBell
      state: "{{ state_attr('button.intercom_call_status','CallStatus').status }}"
    - name: AlarmSMS
      state: "{{ state_attr('sensor.sm_s926b_s24_last_notification','android.messages')[-1][1:-1].split(', ')[2].split('=')[1] == 'Home Alarm'}}"
      attributes: 
        history: "{{ state_attr('sensor.sm_s926b_s24_last_notification','android.messages')[-1][1:-1].split(', ')[8].split('=')[1][:-3] | int (1) | timestamp_local }}"

#helper for PV Excess automation 
- switch:
    - name: keba # Keba does not have enable/disable switch
      #friendly_name: "Keba"
      turn_on:
        action: button.press
        target:
          entity_id: button.keba_p30_de_enable
      turn_off:
        action: button.press
        target:
          entity_id: button.keba_p30_de_disable
    - name: bazen_tepelko # heatpump does not have enable switch, just hvac mode
      #friendly_name: "BazenTepelko"
      turn_on:
        action: switch.turn_on
        target:
          entity_id: switch.tepelko_bazen_prepinac # http://homeassistant.local:8123/config/devices/device/b7c3ea15acb611210385403f8ac700e3 - cloud tuya device
      turn_off:
        action: switch.turn_off
        target:
          entity_id: switch.tepelko_bazen_prepinac # http://homeassistant.local:8123/config/devices/device/b7c3ea15acb611210385403f8ac700e3 - cloud tuya device
1 Like

You can make the name “Dimplex Mode Text” so it looks better in the frontend. It will still use dimplex_mode_text in the entity id.

If for backward compatibility with the old sensor you need a different name and entity id there is a default_entity_id: option you can use.

I’d also advise using the unique_id: option. It gives you a lot more control from the frontend (e.g. changing the rounding of numeric sensors). You can use anything as long is it is unique. There are UUID generators online you can use (also available in VSCode if you use that editor). Or you can just use the entity id.