Sonoff 4ch - motion/door sensor activated, timer turn off

Hi all
I have searched through blueprints but I somehow can not find what I need.
I have a several rooms where I have either a RF door or motion sensor, which activates a light (or switch, due to being on a Sonoff 4ch pro r2). I need that light to turn off after 3 or 5 minutes after that, but I am just having a hard time finding a right way to do it.
Currently I have an automation set that the RF sensor triggers the switch on, which works. But once I put in the same automation a delay of 5 minutes and then turn off, it does not work. What am I doing wrong?