Help with closing garage door when leaving home

I tried to write a script to close the garage door when I’m not home, but all it does is make my garage door close and open in an infinite loop when I’m not home (I’m using garadget).

Here is my code:

  - alias: "Close Garage Door When Leaving Home"
    trigger:
      - platform: state
        entity_id: cover.garage_door
        from: 'open'
    condition:
      - condition: state
        entity_id: device_tracker.ashton_ashton
        state: 'not_home'
    action:
      service: cover.close_cover
      entity_id: cover.garage_door

Edit: I fixed it using zone triggers instead.

What you have in trigger should be a condition.