Garage Door Template Trouble

Hi all,

I used a shelly 1 to automate my garage but i’m having a really tough time getting this to show up as a cover in HA. I got this code to work when I inserted it into my config.yaml, but I can’t get it to work on the split out tempalte.yaml file. Any ideas? this is the code in my template. yaml file

cover:
  - name: "TEST Garage Door 2"
    state: "{{ states('binary_sensor.swgaragehoop_input') }}"
    device_class: opening
    open_cover:
      service: switch.toggle
      entity_id: switch.swgaragehoop
    close_cover:
      service: switch.toggle
      entity_id: switch.swgaragehoop
    stop_cover:
      service: switch.toggle
      entity_id: switch.swgaragehoop
      
    icon: >-
      {% if states('binary_sensor.swgaragehoop_input') == "on" %}
        mdi:garage-open
      {% else %}
       mdi:garage
      {% endif %}      

this is the error i get:

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

If you added it to your template.yaml file it would become

template:
cover:

if you create a cover.yaml and place the code in the file, then do a cover: !include cover.yaml in you configuration.yaml does this fix.

See here: Template Cover - Home Assistant

Cover hasn’t been moved to the non-legacy style configuration.

cover:
- platform: template
  covers:
    test_garage_door_2:
      ...

Thanks Petro.

so my config.yaml says:

cover: !include cover.yaml

My cover.yaml has:

cover:
- platform: template
  covers:
    test_garage_door_2:
      state: "{{ states('binary_sensor.swgaragehoop_input') }}"
      device_class: opening
      open_cover:
        service: switch.toggle
        data:
          entity_id: switch.swgaragehoop
      close_cover:
        service: switch.toggle
        data:  
          entity_id: switch.swgaragehoop
      stop_cover:
        service: switch.toggle
        data:
          entity_id: switch.swgaragehoop
      icon: >-
        {% if states('binary_sensor.swgaragehoop_input') == "on" %}
          mdi:garage-open
        {% else %}
          mdi:garage
        {% endif %}      

when i try and validate the config.yaml file i get:

Validate your configuration if you recently made some changes to your configuration and want to make sure that it is all valid.

Configuration invalid

Invalid config for [cover]: required key not provided @ data[‘platform’]. Got None. (See /config/configuration.yaml, line 16).

any ideas? I’m assuming i have bad syntax or format somewhere, because it works fine when it’s imbedded in the config.yaml file.

yes, because your file contains the field cover: in it. Your include already specifies that. What you’re feeding home assistant is:

cover:
  cover:
  - platform: template
    covers:
    ...

when you use include…

cover: !include cover.yaml
  ^
  |
already has field.

so your contents shoudl start…

- platform: template
  ....

Secondly, review the template cover docs. You’re mixing old style and new style fields in your configuration (state should be value_template)

1 Like

Petro, thanks so much for your help, it worked! I used the new syntax for my last template (the one with “state”) but this one as you said needed the older syntax (i.e. “value_template”).

Is that because for the first template, that i did for a sensor, i used Template.yaml, instead of sensor.yaml? Where as this time I used the template in the cover.yaml file?

It’s because there’s 2 formats. The old way and the new way. The new way supports triggers and other new fields like state_characteristic (for sensors). The old way is just how it used to be done. The new way was developed specifically to handle triggers as an optional method to update sensor states.

1 Like

I appreciate the color.

Just to close the loop and to show the resolved code. Thanks again Petro. This is all good to go now in my cover.yaml file.

- platform: template
  covers:
    garage_door_hoop:
      friendly_name: 'Garge Door - Hoop'
      value_template: "{{ states('binary_sensor.swgaragehoop_input') }}"
      open_cover:
        service: switch.toggle
        data:  
          entity_id: switch.swgaragehoop
      close_cover:
        service: switch.toggle
        data:  
          entity_id: switch.swgaragehoop
      stop_cover:
        service: switch.toggle
        data:
          entity_id: switch.swgaragehoop
      icon_template: >-
        {% if states('binary_sensor.swgaragehoop_input') == 'on' %}
          mdi:garage-open
        {% else %}
          mdi:garage
        {% endif %}      
    
    garage_door_house:
      friendly_name: 'Garge Door - House'
      value_template: "{{ states('binary_sensor.swgaragehouse_input') }}"
      open_cover:
        service: switch.toggle
        data:  
          entity_id: switch.SwGarageHouse
      close_cover:
        service: switch.toggle
        data:  
          entity_id: switch.SwGarageHouse
      stop_cover:
        service: switch.toggle
        data:
          entity_id: switch.SwGarageHouse
      icon_template: >-
        {% if states('binary_sensor.swgaragehouse_input') == 'on' %}
          mdi:garage-open
        {% else %}
          mdi:garage
        {% endif %}      

FYI you don’t need the icon_tempalte. Just do

device_class: garage

Best solution, more info Cover - Home Assistant

Also looking for semi open garage for cat :slight_smile: I got two sensor semi open (icon ie mdi:garage-alert-variant) and full open.

Code is full working for someone like me :slight_smile:

captive_portal:    
switch:
  - platform: gpio
    id: garage_door_relay
    pin: D5
    restore_mode: ALWAYS_OFF
    internal: True

binary_sensor:
  - platform: gpio
    pin:
      number: D6
      mode: INPUT_PULLUP
    name: "Garaz vrata I"
    device_class: garage_door
    filters:
      - delayed_on_off: 50ms
    id: garage_door_1
    internal: True
  - platform: gpio
    pin:
      number: D7
      mode: INPUT_PULLUP
    name: "Garaz vrata II"
    device_class: garage_door
    filters:
      - delayed_on_off: 50ms
    id: garage_door_2
    internal: True
cover:
  - platform: template
    name: "Ovladani garazove vrat"
    device_class: garage
    lambda: |-
      if (id(garage_door_1).state) {
        return COVER_OPEN;
      } else if (id(garage_door_2).state) {
        return COVER_OPEN;
      } else {
        return COVER_CLOSED;
      }  
    open_action:
      - switch.turn_on: garage_door_relay
      - delay: 0.1s
      - switch.turn_off: garage_door_relay
    close_action:
      - switch.turn_on: garage_door_relay
      - delay: 0.1s
      - switch.turn_off: garage_door_relay
    stop_action:
      - switch.turn_on: garage_door_relay
      - delay: 0.1s
      - switch.turn_off: garage_door_relay