Automation to monitor security camera motion detection only while garage door is open

I’m trying to create an automation that will close my garage door after 5 minutes if no motion has been detected in the last 4 minutes by my 3 security cameras. I want to do this because I do not want my garage door to stay open if no one is in the garage or outside. My teenage children have a hard time keeping the garage door closed when they come into the house.

I have an automation created to run when the garage door has been opened for 5 minutes, it looks at the state of the motion detection of the cameras, and if the motion state has been OFF for 5 minutes on all 3 cameras, it closes the garage door.

However, if the state has not been OFF for 5 minutes on all cameras, then the automation fails and does not close the garage, and the automation does not run again until the garage is re-opened.

I need to make it work so that it is constantly monitoring the state of the cameras to close the garage door when all 3 cameras have no motion detected for 4 minutes.

Add two triggers:

  1. Garage door open for 5 minutes
  2. No motion on all three cameras for 5 minutes

Add two conditions:

  1. Garage door open for >=5 minutes
  2. No motion on all three cameras for >=5 minutes