Help with Script Syntax

I’m trying to create a helper script to automate the opening/closing of my garage doors. The idea is to be able to flick the opener lights on and off using ratgdo ahead of closing the door with the cover.close command, perhaps make an alexa announcement that the doors are closing in x seconds, etc.

anyway, I am just beginning with it but I am having a hard time getting the first pass of the script to save, I get the dreaded “extra keys not allowed” error message. Can you guys help? Here is the script. What did I do wrong? Don’t worry too much about what the script actually does, I’m just trying to figure out where I went wrong in the syntax to get the darn thing to save.

alias: Smart Garage Door Opener
fields:
  entity:
    default: "all"
  lights:
    default: "yes"
  action:
    default: "open"
  notification:
    default: "none"  
sequence: 
  - choose:
    - conditions:
      - condition: template
        value_template: "{{ entity == 'cover.left_door' }}"
        sequence:
        - service: variable.set_variable
          data_template:
            variable: matching_ratgdo
            value: ratgdoesp1-649ae1
      - condition: template
        value_template: "{{ entity == 'cover.middle_door' }}"
        sequence:
        - service: variable.set_variable
          data_template:
            variable: matching_ratgdo
            value: ratgdo2-f83d3b
      - condition: template
        value_template: "{{ entity == 'cover.bikes' }}"
        sequence:
        - service: variable.set_variable
          data_template:
            variable: matching_ratgdo
            value: ratgdo3-ec8fe3
      default:
        - service: variable.set_variable
          data_template:
            variable: matching_ratgdo
            value: ratgdo3-ec8fe3
  - choose:
    - conditions:
      - condition: template
        value_template: "{{ lights == 'yes' }}"
        sequence:
          - service: cover.open
            data_template:
              entity_id: "{{ entity }}"
      - condition: template
        value_template: "{{ lights == 'no' }}"
        sequence:
          - service: cover.open
            data_template:
              entity_id: "{{ entity }}"
mode: single

The default of your first Choose is indented too far. It should be at the same depth as choose.

1 Like

Thanks. That wasn’t enough to get it to work. I ended up having to be very verbose and include “conditions:” before each “condition” and finally got it to compile. Here is the corrected script in case it helps anybody else.

alias: Smart Garage Door Opener
fields:
  entity:
    default: "all"
  lights:
    default: "yes"
  action:
    default: "open"
  notification:
    default: "none"  
sequence: 
  - choose:
    - conditions:
      - condition: template
        value_template: "{{ entity == 'cover.left_door' }}"
      sequence:
        - service: variable.set_variable
          data_template:
            variable: matching_ratgdo
            value: ratgdoesp1-649ae1
    - conditions:
      - condition: template
        value_template: "{{ entity == 'cover.middle_door' }}"
      sequence:
        - service: variable.set_variable
          data_template:
            variable: matching_ratgdo
            value: ratgdo2-f83d3b
    - conditions:
      - condition: template
        value_template: "{{ entity == 'cover.bikes' }}"
      sequence:
          - service: variable.set_variable
            data_template:
              variable: matching_ratgdo
              value: ratgdo3-ec8fe3
    default:
      - service: variable.set_variable
        data_template:
          variable: matching_ratgdo
          value: ratgdo3-ec8fe3
  - choose:
    - conditions:
      - condition: template
        value_template: "{{ lights == 'yes' }}"
      sequence:
        - service: cover.open
          data_template:
            entity_id: "{{ entity }}"
    - conditions:
      - condition: template
        value_template: "{{ lights == 'no' }}"
      sequence:
        - service: cover.open
          data_template:
            entity_id: "{{ entity }}"
mode: single

You can make it significantly more concise by assigning variables and using a few templates. The following should be functionally equivalent to what you posted, though it contains a few unused variables…

alias: Smart Garage Door Opener
fields:
  entity:
    default: "all"
  lights:
    default: "yes"
  action:
    default: "open"
  notification:
    default: "none"  
sequence:
  - variables:
      mapper:
        cover.left_door: ratgdoesp1-649ae1
        cover.middle_door: ratgdo2-f83d3b
        cover.bikes: ratgdo3-ec8fe3
  - service: variable.set_variable
    data_template:
      variable: matching_ratgdo
      value: "{{ mapper.get(entity, 'ratgdo3-ec8fe3') }}"
  - condition: template
    value_template: "{{ lights in ['no', 'yes'] }}"
  - service: cover.open
    data:
      entity_id: "{{ entity }}"
mode: single

Nice, use a mapper to help match the ratgdo to the door. A lot more elegant.

I kept having trouble with the variable service calls but was able to get it working using different syntax. I found myself using the visual editor a lot more than I had thought, I keep messing up with the syntax in yaml mode.

Tanks for the help! Here is the code in case it is useful to anyone.

alias: Smart Garage Door Opener
fields:
  which_door:
    default: cover.all_garage_doors
  flash_lights:
    default: "yes"
  what_to_do:
    default: open
  notification_type:
    default: none
variables:
  matching_ratgdo_light: nothing
  mapper:
    cover.left_door: light.left_door_light
    cover.middle_door: light.middle_door_light
    cover.bikes: light.bikes_door_light
    cover.all_garage_doors: light.all_ratgdo_lights
sequence:
  - variables:
      matching_ratgdo_light: "{{ mapper.get(which_door) }}"
  - if:
      - condition: template
        value_template: "{{ flash_lights == 'yes'}}"
    then:
      - repeat:
          count: 10
          sequence:
            - action: light.turn_on
              metadata: {}
              data: {}
              target:
                entity_id: "{{ matching_ratgdo_light }}"
            - delay:
                hours: 0
                minutes: 0
                seconds: 0
                milliseconds: 500
            - action: light.turn_off
              metadata: {}
              data: {}
              target:
                entity_id: "{{ matching_ratgdo_light }}"
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ what_to_do == 'open' }}"
        sequence:
          - action: cover.open_cover
            metadata: {}
            data: {}
            target:
              entity_id: "{{ which_door }}"
      - conditions:
          - condition: template
            value_template: "{{ what_to_do == 'close' }}"
        sequence:
          - action: cover.close_cover
            metadata: {}
            data: {}
            target:
              entity_id: "{{ which_door }}"
mode: single