Light timer-dim-timer-off with override to ON if interrupted by motion

Hi, I am looking for a simple light dimmer recipe where light turns on to full brightness with motion, but goes dim after 15 minutes of “motion stays inactive”, and then off in another 5 minutes. But, when it goes dim, if for some reason the person is still there and the trigger doesn’t detect him, he can frantically wave his hand and turn the light back on, in which case the turn-off-timer restarts. I tried a few things but it doesn’t work 100% of the time. This is what I tried.
For turning off:

For turning on:

Sometimes light turns off even if presence is there and then triggers to ON the next time motion is sensed.