Lights turn on only if it was on in the past 5 minutes

I am fairly new to Sharptools Rule Engine and I was wondering if there was a way to create a rule to do this:
If I leave a room(presence sensor) turn off the light.
If I come back to that room (presence sensor) within 5 minutes from that light turning off, turn the light on.
If I come back to that room (presence sensor) after 5 minutes from that light turning off, do nothing.

Thanks
Justin

This first one is easy. IF x motion stays inactive for x time, then turn the light off.

The last two require three variables. Each time the light is turned off, store that time in a variable (using now() ).

Each time the motion in that room triggers (your IF), store that time in another variable (using now() ). Calculate the amount of time between those two variables in minutes and set that value to a third variable. Then use a 2nd IF in your rule, turn the light on if the calculated variable time is less than 5 minutes.

Why would you make it that complicated? You don’t need to time the motion, you only need the time it was last turned off.
So I’d link a variable to the turning off the lights, create a rule that uses “state stays off” for 5 minutes to turn the variable back off.

Now all you need is to create a second rule that turns the light on if motion AND variable is “on”.