Config file format for sensor templates

As a newbie I am struggling with the syntax of HA configuration files for sensor templates.

I am running the following:

HA OS: 17.3
HA Core: 2026.6.0b0

Currently, my configuration.yaml includes the line:

sensors: !include sensors.yaml

And my sensors.yaml file is structured as follows:

platform: template
  - sensor:
      porteauto_g_etat_raw:
        unique_id: "PorteAuto-G-Etat_Raw"
        friendly_name: "Porte Garage G État Raw"
        value_template: >-
          {% if states('sensor.porte_garage_g_fermee') == 'unknown'
            or states('sensor.porte_garage_g_ouverte') == 'unknown' %}
          {{3}}
          {% else %}
          {{ int(states("sensor.porte_garage_g_fermee"))
            + int(states("sensor.porte_garage_g_ouverte")) }}
          {% endif %}
        
      porte_auto_g_etat:
        unique_id: "PorteAuto-G-Etat"
        friendly_name: "Porte Garage G État"
        value_template: >-
          {% set values = {0:'ouverte', 1:'entrouverte', 2:'fermée', 3:'inconnu',4:'inconnu'} %}
          {{ values[int(states("sensor.porteauto_g_etat_raw"))] }}

Upon restarting HA, I am getting the following error message about the above:

Enregistreur: homeassistant.config
Source: config.py:352
S'est produit pour la première fois: 12:24:54 (1 occurrence)
Dernier enregistrement: 12:24:54

Invalid config for 'template' at sensors.yaml, line 2: 'sensors' is an invalid option for 'template', check: sensors

I tried several variations with the placing of the keywords 'template', 'sensor(s), indentation, etc., but I failed to find the correct one.

Could someone please help me correct my mistakes?

Thanks in advance!

Template sensors (and all other template entities) go under the Template integration, not their domain integrations like sensor... so they do not belong in your sensors.yaml file.

Regarding the actual syntax, follow what is shown in the docs.

There are also numerous examples on how to convert from legacy templates (which it looks like you might be trying to do) in the deprecation thread from 6 months ago... as of the current beta, 2026.6.0b0, the legacy template syntax is fully deprecated.

Since your sensors are not using triggers or attributes and you are new to HA, you may be better served just creating these sensors in the UI through the Helpers dashboard.


FWIW, if you are actually a "newbie", you might also reconsider running beta... especially if this is your production instance.

There's also this thread

@Didgeridrew and @Petro

Thanks for your help: problem is now resolved!