you might try using a blueprint like htis:
your question is a very common one for motion detection.
if you must do it by hand, the typical thing isn’t to turn the light off 4 minutes after detecting motion, but instead to do it 4 minutes (or however long you want) after detecting no motion.