Closing garage door 30 min before sunset if no motion

Hi,

I am new to HA and trying to make sure my automation is correct for what I want to do. The end goal is to have HA close my garage door if it is at least 30 mins before sunset, there is no motion in the garage, and the garage door is open. Can someone check my work? Here is my code from the automation.yaml:

Thanks,
Andy

  alias: Close Left Garage Door 30 min before sunset
  description: ''
  trigger:
  - event: sunset
    offset: -00:30
    platform: sun
  - entity_id: binary_sensor.garage_motion_sensor
    for: 00:10
    platform: state
    to: 'off'
  condition:
  - condition: device
    device_id: a287e823d6834fa68c3124bf4b59adf4
    domain: cover
    entity_id: cover.left_garage_door
    type: is_open
  action:
  - device_id: a287e823d6834fa68c3124bf4b59adf4
    domain: cover
    entity_id: cover.left_garage_door
    type: close
  mode: single

This will run either when there’s been no motion for 10 minutes, or when it’s half an hour before sunset regardless.

You’ll want to add another condition I suspect, to avoid the door closing on you.

  condition:
  - condition: device
    device_id: a287e823d6834fa68c3124bf4b59adf4
    domain: cover
    entity_id: cover.left_garage_door
    type: is_open
  - condition: state
    entity_id: binary_sensor.garage_motion_sensor
    for: 00:10
    state: 'off'

That way it will only close if there’s not been motion for 10 minutes, and save you from a door in the face.

Thank you @Tinkerer. I will give this a try tonight!