Getting error in configuration.yaml

Friends,

In the quest of cleaning up my config files, I added a folder “template” in the configuration and the following in the configuration yaml.

Blockquote
template:
sensor: !include_dir_merge_list ./templates

Blockquote

I have created a lot of template sensors that are in different files under the “template” foldor. I am getting the following error in the configuration.yaml file:
Incorrect type. Expected “array”.
Can you please help me resolve this error.

Thanks

Do:

template: !include_dir_merge_list ./templates

then in your individual files, start like this:

- sensor:
    - name: etc

Thanks for prompt reply. Howver, when i did what you said, all sensors disappeared.

You need to include the - sensor: (or other subdomain) at the top of each file and indent them properly. Did you do that?

Please post your config as text not screenshots: I can’t copy your config to edit it to show you what I mean. Here’s examples from my system:

# configuration.yaml
template: !include_dir_merge_list templates
# templates/energy.yaml
- sensor:
    - name: "Grid consumption"
      unique_id: d4c56989-7dd6-4e03-90c7-efc22a55f1cc
      [other config]

    - name: "Electricity cost"
      unique_id: 2ac05fc6-9850-490d-a471-dcbac024dbae
      [other config]
# templates/binary_sensors.yaml
- binary_sensor:
    - name: mild_weather
      unique_id: 37e80ebe-4006-40e3-aead-6b512be6cd44
      state: "{{ 10 < states('sensor.outside_temperature')|int(0) < 26 }}"
# templates/recent_motion.yaml
- trigger:
    - platform: state
      entity_id:
        - binary_sensor.utility_room_motion
      to: 'on'

  sensor:
    - name: "Latest motion"
      unique_id: 071ebe1d-c9f6-4f8e-b7f7-259528410d07
      icon: mdi:run
      device_class: timestamp
      state: "{{ now() }}"

Your way should work if you only have simple (non-trigger-based) template sensors, and no other template entities like binary sensors, but you need to use:

template:
  - sensor: !include_dir_merge_list ./templates

The sensor is a list header (docs) and lists are dentoed in YAML with a hyphen.