Execute function in a time slot

With Rules and Timers. There are lots of examples on the forum.

Trigger the rule when the Switch changes. Set a Timer for 5 minutes. When the Timer goes off, check to see if the Switch activated. If so do one thing. If not do something else.