Error in template yaml file: expected a dictionary

Dear readers,

I’m coming from OpenHab and try to migrate to HAS. Up to now I only see benefits but it also comes with a learning curve.

I’m trying to setup a template file but i’m getting the error but I don’t understand what goes wrong here.

Could someone help me out?

Best regards,


Invalid config for [template]: 
expected a dictionary. Got [OrderedDict([('binary_sensor', [OrderedDict([('name', 'Dark'), ('state', "{ states('sensor.sn_3004189162_pv_current_a')|float > 0.2 }")]), 
OrderedDict([('name', 'dummy'), ('state', 'true')])])]), OrderedDict([('sensor', 
[OrderedDict([('name', 'hallo'), ('state', 'false')])])])].
 (See /config/templates/templates.yaml, line 3).
# Example entry with two sections
#template:
# Define state-based template entities
- binary_sensor:
    - name : "Dark"
      state : "{  states('sensor.sn_3004189162_pv_current_a')|float > 0.2   }"
      
      
    - name : "dummy"
      state: "true"

- sensor:
  - name: "hallo"
    state: "false"
  
  # Define trigger-based template entities
  # - trigger:
                            
  #    sensor:
                                      
  #    binary_sensor

Agree…learning curve … look at the docs for examples
Here it is missing the second { and }

Template - Home Assistant (home-assistant.io)

Always try it out in Developer Tools > Templates (tab)

Thank you for your replies,

The double curled brackets were not the only issue, also somehow the entity wasn’t “right”. I’ve taken another entity and now it works as expected.

I’ll look further into the documentation. I now have at least one working example!

Best regards!

Oooh I was to fast.
It still gives the error for the template.yaml file, while the developper tool gives none. The error is now on line 0

Invalid config for [template]:
expected a dictionary. Got [OrderedDict([(‘binary_sensor’, [OrderedDict([(‘name’, ‘Dark’), (‘state’, “{{ states(‘sensor.sn_3004189162_grid_power’) | float < 0.2 }}”)]), OrderedDict([(‘name’, ‘dummy’), (‘state’, ‘true’)])])]), OrderedDict([(‘sensor’, [OrderedDict([(‘name’, ‘hallo’), (‘state’, ‘’)])])])]. (See /config/templates/templates.yaml, line 0).

- binary_sensor:
  - name : "Dark"
    state : "{{  states('sensor.sn_3004189162_grid_power') | float < 0.2   }}"

  - name : "dummy"
    state: "true"

- sensor:
  - name: "hallo"
    state: ""

# Define trigger-based template entities
# - trigger:
#    sensor:
#    

Lose the spaces before the colons in your binary_sensor key values, so:

  - name: "Dark"

So, oke I finally found the error.
It was caused by the different behavior of

!include_dir_list and !include_dir_merge_list

When using the first (what I did) then a yaml file may only contain ONE entry. And with that no ‘-’ character because it can’t be a dictionary LIST

When using the second one, it may contain more entries and with that IS a dictionary list that must start with ‘-’ character.

When using sub-files for configurations the error line reference would be bogus.

It’s all explained in:

Best regards!