How to write cover templates in a split configuration?

I have my templates split in separate files in a “templates” folder and configured like:
template: !include_dir_merge_list templates/

I have several files already created, for sensors and binaries, but today I need to create a cover template and I’m unable to find the correct format.
Of course the format in the documentation doesn’t work, as it’s written for a plain configuration.yaml.

# This format doesn't work.
cover:
  - platform: template
    covers:
      salon_persiana_principal:
        device_class: garage
        friendly_name: "Persiana principal"
        position_template: >
          {{100 - (state_attr('cover.salon_persiana1','current_position')|int)}}
        set_cover_position:
          service: cover.set_cover_position
          data_template:
            entity_id: cover.salon_persiana1
            position: >
              {{100 - position}}

Doesn’t give error, but the device is not there.

So I’ve tried to mimic the config on my other template files

- covers:
  - name: salon_persiana_principal
    # friendly_name: Persiana principal
    # device_class: shade
    position_template: >
      {{100 - (state_attr('cover.salon_persiana1','current_position')|int)}}
    set_cover_position:
      service: cover.set_cover_position
      data_template:
        entity_id: cover.salon_persiana1
        position: >
          {{100 - position}}

But also doesn’t work and gives the following error:

Invalid config for [template]: [cover] is an invalid option for [template]. Check: template->cover. (See /home/homeassistant/.homeassistant/templates/covers.yaml, line 0).

Could be that the template format has became uncompatible with the other templates when in separate files?

I finally moved this to a package, but still would be nice to solve it.

Template covers still use the old template format, per the docs:

cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        value_template: "{{ states('sensor.garage_door')|float > 0 }}"
        open_cover:
          service: script.open_garage_door
        close_cover:
          service: script.close_garage_door
        stop_cover:
          service: script.stop_garage_door

This means to use split configuration you would use:

cover: !include_dir_merge_list covers/

Your files like others in the split config would then NOT have the cover: key in them:

  - platform: template
    covers:
      salon_persiana_principal:
        device_class: garage
        friendly_name: "Persiana principal"
        position_template: >
          {{100 - (state_attr('cover.salon_persiana1','current_position')|int)}}
        set_cover_position:
          service: cover.set_cover_position
          data_template:
            entity_id: cover.salon_persiana1
            position: >
              {{100 - position}}

I see. So covers have their own configuration point. I thought that it had to be a part of templates.
Thank you Andrew.

Sensor, binary sensor, button, number and select template entities are defined in your YAML configuration files, directly under the template: key

Everything else is currently under it’s own integration key (cover, weather, light, switch etc)

1 Like