Problem Using New Template Sensor format

Still a bit green with HA. I’m trying to start using the new template when creating sensors but I’m running into a brick wall:

As an aside, i have created this sensor using the old templating method and it works, I wanted to add attributes but couldn’t, that was why I’m changing to the new method.

I created a new template_sensors.yaml file and included it in my config.yaml using “template: !include template_sensors.yaml”

inside the template_sensors yaml file I have the following code:

template:
  - sensor:
      - name: Public power Available
        unit_of_measurement: "Presently"
        state: >
          {% if states('binary_sensor.elec_indoors_contact') == 'off' %}
            {%set p_stat = "Grid Not Available"%}
          {% else %}
            {%set p_stat = "Grid Available" %}
          {% endif %}
          {{p_stat}}
        attribute_template: 
          time_since_last_change: >
            {{ (as_timestamp(now()) - as_timestamp(states.binary_sensor.elec_indoors_contact.last_changed)) | timestamp_custom("%H:%M:%S", false) }}

However, it doesn’t load when I try to restart all template entities in developer tools, I get the following error:

Logger: homeassistant.config
Source: config.py:868
First occurred: 12:59:34 PM (1 occurrences)
Last logged: 12:59:34 PM

Invalid config for [template]: [template] is an invalid option for [template]. Check: template->template. (See /config/template_sensors.yaml, line 1).

I’ve read all the topics I could find on here but wasn’t able to solve this issue. would appreciate any assistance.

remote the template: from the top of the file. When you use an include, it basically tells HA to take everything from that other file and glue it into the main file. So in your case with the file you have, you technically have something that looks like this:

template:
  template:
    - sensor: ...

Thanks a million, it works now.

Now the attribute_template wasn’t working, I changed it to attributes and it worked perfectly.