Automation with "and if" within time period

Im trying to work out how to hold an automation open so that the and if option happens wirhin a certain time then it can then trigger.

Example

I have a ultrasonic sensor for sensing car is in the garage but it takes awhile to pickup the car. I also have a tesla vehicle that is in home assistant.

So i want to say

If car changes state from reverse to park “and if” within 5 mins the car presence sensor changes to car is present. Then close garage door.

Is this possible with automations?

Do it the other way round. Trigger on the last thing to happen then check if the first thing is in the correct state. Something like this:

triggers:
  - trigger: state
    entity_id: tracker.car_presence
    to: 'home'
conditions:
  - condition: state
    entity_id: sensor.car_gear_shift
    state: 'park'
actions:
  - action: cover.close_cover
    target:
      entity_id: cover.garage_door
1 Like

Will.give this a test good thinking thanks.