Loop / Repeat Function for Garage Door Script

Hi All,
My goal from the automation is to close my garage doors when there is no motion detected on a driveway camera. Since my camera can see a rather busy road, the driveway will see motion a lot over the course of a day. To account for that, I wanted to use a loop/repeat to have the script check the motion sensor until it is off. This repeat function would keep running until both garage doors are closed.

garage_doors_down:
  condition: state
  entity_id: binary_sensor.driveway_motion
  state: "off"
  sequence:
    - alias: "put down single garage door"
      service: cover.close_cover
      target:
        entity_id: binary_sensor.single_myq_gateway
    - alias: "put down door garage door"
      service: cover.close_cover
      target:
        entity_id: binary_sensor.double_myq_gateway
  repeat:
    sequence:
      - service: cover.close_cover
        target:
          entity_id: binary_sensor.single_myq_gateway
      - delay: "00:00:05"
      - service: cover.close_cover
        target:
          entity_id: binary_sensor.double_myq_gateway
      - delay: "00:00:05"
    until: "{{ is_state(cover.single,'closed') and is_state(cover.double,'closed') }}"

I’m doing something wrong, but not sure what. Any ideas?

Few things that I can see. Your trigger should likely look like this:

  trigger:
  - platform: state
    entity_id: binary_sensor.driveway_motion
    to: 'off'
    for: 00:00:05

when 00:00:05 is the amount of time (HH:MM:SS) that the motion should be off for before the automation triggers. This happens on a state CHANGE, so motion would have to change from something (on most likely) TO ‘off’ for (in the case above) 5 seconds.

The second is that you need to use the service on the COVER. You have the BINARY_SENSOR as the entity / target of the service.

You really don’t need the repeat: sequence - as I believe the ‘for:’ shown above does what you want.

Lastly, and personally, I created two scripts for each of my garage doors that I call when I need to open / close them (each has a condition to ensure the door is not already opened or closed).

garage_door_east_open:
  sequence:
  - condition: state
    entity_id: cover.garage_door_east_zw
    state: closed
  - service: cover.open_cover
    entity_id: cover.garage_door_east_zw
  mode: single
garage_door_east_close:
  sequence:
  - condition: state
    entity_id: cover.garage_door_east_zw
    state: open
  - service: cover.close_cover
    entity_id: cover.garage_door_east_zw

Then my automations just call the respective scripts. This could also be included / wrapped into your automation using IF/THENs, but always a bunch of ways to do things in HA.