Programming timers questions

I would like to use an IR motion sensor to start a timer. While the timer is running down I would like to inhibit another process from running down.

Idea is this. Motion sensors in garage, when door open and sense motion start 20 minute timer. When more motion detected restart 20 minute timer. When no motion for 20 minutes, shut garage door. Yes, I have door position sensors hooked up.

I was thinking about having the sensor trigger a variable using milli() then subtracting the trigger time from current time.

Any other ideas how to do this?

Declare a variable

unsigned long lastMotion;

Every time motion is detected, do

lastMotion = millis();

Monitor the variable in loop() something like this

if (millis() - lastMotion > 20 * 60 * 1000) closeDoor();

Thanks, That was along the lines I was thinking. Is that the most efficient way or could I do anything else?

Is that the most efficient way or could I do anything else?

Yes. It is the simplest solution, therefore the most efficient. And, yes, you can do something else. Why you would want to, though, is a mystery.

I don't want to, just trying to learn.

Thanks for the input.