If motion is detected X times in X Minutes - extend the time the lights are on. How is that possible?

I had a similar problem and this was my solution: Occupancy Duration Helper - Finally poop in peace (-: