Cant use more than one template sensor

so i tried to make template sensors that used the “place” attribute to make a new sensor that had the value of the place attribute of a life360 device tracker. for some reason only one sensor is created as an entity. am i allowed to make more than one template sensor? heres the code


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

http:
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem

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

#template:
#  - sensor:
#      - name: "carverlocation"
#        state: "{{state_attr('device_tracker.life360_carver_fell', 'place')}}"

#template:
#  - sensor:
#      - name: "tomlocation"
#        state: "{{state_attr('device_tracker.life360_thomas_margotta', 'place')}}"

template:
  - sensor:
      - name: "templatesensortest"
        state: "{{ state_attr('device_tracker.life360_thomas_margotta', 'place') }}"

template:
  - sensor:
      - name: "carverplace"
        state: "{{ state_attr('device_tracker.life360_carver_fell', 'place') }}"

#template:
#  - sensor:
#      - name: "tomplace"
#        state: "{{ state_attr('device_tracker.life360_thomas_margotta', 'place') }}"

notify:
        - name: pushover
          platform: pushover
          api_key: !secret pushoverapikey
          user_key: !secret pushoveruserkeyop6

sensor:
  - platform: xbox_live
    api_key: !secret xbapi
    xuid:
      - !secret xbusr


im not sure whats wrong but sometimes it changes which one works

The reason is because you have multiple template: keys in the file. There should only be one and all Template Sensors are defined under it.

Each additional instance of template: effectively overwrites the previous one.

ohhh i see, the template: thing is the platform or whatever and you have to list all them under that. my bad.

It’s the domain (platform is a term for something else). Other domains are light, switch, fan, lock, etc.

oh ok. im gonna have to read more about this.

If my reply answered your original question to your satisfaction, please consider marking my post (above) with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved.