Need some assistance with Garage Door automation with Shelly 1

I apologize in advance that I am not a YAML programmer. I am trying to use an article that I found that explains how to use a Shelly 1 to automate your garage door. I was able to get the equipment wired up, and configured in the web interface for the Shelly 1. Then I got to the part about editing the configuration.YAML file. I copied and pasted the info from the article into the file, but when I did a “check configuration” I get an error.

First of all, here is the article I’m trying to use.

Here is my configuration.YAML file with the personal stuff astrisked out.

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

# Example configuration.yaml entry
light:
  - platform: decora_wifi
    username: ********************
    password: ************
    
http:
 base_url: https://*******************
 ssl_certificate: /ssl/fullchain.pem
 ssl_key: /ssl/privkey.pem

cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        value_template: >-
          {% if is_state('binary_sensor.shelly1_e8db84d6db1c_input','on') %}
            Open
          {% else %}
            Closed
          {% endif %}
        open_cover:
          service: switch.turn_on
          data:
            entity_id: cover.garage_door
        close_cover:
          service: switch.turn_on
          data:
            entity_id: cover.garage_door
        stop_cover:
          service: switch.turn_on
          data:
            entity_id: cover.garage_door
        icon_template: >-
          {% if is_state('binary_sensor.shelly1_e8db84d6db1c_input','on') %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %)

And here is the error I’m getting from the configuration checker.

Invalid config for [cover.template]: invalid template (TemplateSyntaxError: expected token ‘end of statement block’, got ‘%’) for dictionary value @ data[‘covers’][‘garage_door’][‘icon_template’]. Got “{% if is_state(‘binary_sensor.shelly1_e8db84d6db1c_input’,‘on’) %}\n mdi:garage-open\n{% else %}\n mdi:garage\n{% endif %)”. (See ?, line ?).

I’m hoping it is just a formatting error or a simple thing but I’m not good with config files yet. Any help would be apprecaited.

Thank you for your time.

The error says that the icon template is malformatted, hint is


expected token ‘end of statement block’, got ‘%’

Now have a look at the line


{% endif %)

:wink:

Thank you for that information! I know enough about code format to figure out from your hint that I needed to change the parenthesis at the end to a curly brace since that is the format of the other instances like this in the code. THat seems to have fixed my error! Now I just have to figure out what that code block does so I can figure out how to use this for my garage door. Thank you again! I’ve been in IT for 30+ years, but I’ve never been able to get into coding. Always operations and networking. But I like learning new things.

What that last code block “icon_template” does is check to see if your door is open " {% if is_state(‘binary_sensor.shelly1_e8db84d6db1c_input’,‘on’) %} " (eg the shelly1 is in the on state)

If it is open, then it sets the icon for the garage door entity to an open door ( mdi:garage-open ) else it sets the icon to mid:garage which will show in a closed state.

the entire configuration is using the jinja templating system. If you go to the main menu on the left just above settings you will see “Developer Tools” If you select that, the menu at the top will show various options, one of which is Templates. This is a great place to learn about templates and play with them as you build templates for your automations etc. The other links such as States, Services, etc. are also a great place to learn more about what is under the hood in Home Assistant. Hopefully this helps.

John has already given some valuable pointers. Additionally, you might have a look at the Jinja documentation:

There are a few kinds of delimiters. The default Jinja delimiters are configured as follows:

** {% ... %} for Statements*
** {{ ... }} for Expressions to print to the template output*
** {# ... #} for Comments not included in the template output*

Thank you both for the additional information! I will try to make time to learn more about the config files as well as the developer tools. Your assistance is greatly appreciated.

I think the entity IDs you are referencing under the switch service calls are wrong too: It refers to the cover you are defining. It should be the switch entity of the Shelly.

Thank you. I wondered about that. I had redefined the device as a cover as I thought I needed to for automations like this. I’ll go back to the switch identity.