Template sensor not working in coniguration.yaml

Feeling an absolute noob here, but can’t get this to work.

Template sensor works just fine in the template tester (developer tools tab) but only sends out ‘unknown’ when added to coniguration.yaml

Screenshot 2024-02-24 at 19.32.48

There are two ways to define a Template Sensor using YAML:

  1. Modern
template:
  - sensor:
      - name: "Average temperature"
        unit_of_measurement: "°C"
        state: >
          {{ (states('sensor.bedroom1') | float(0) +
              states('sensor.bedroom2') | float(0)) / 2 %}
  1. Legacy
sensor:
  - platform: template
    sensors:
      average_temperature:
        friendly_name: "Average temperature"
        unit_of_measurement: "°C"
        value_template: >
          {{ (states('sensor.bedroom1') | float(0) +
              states('sensor.bedroom2') | float(0)) / 2 %}

The example you posted is an invalid combination of the two methods. It begins with modern by defining the template key and then switches to legacy using things like friendly_name and value_template and a structure that is only used by legacy format.

Define a Template Sensor using either format but don’t blend the two formats together.

The Template Editor only evaluates templates. It doesn’t validate YAML.