How to use a PIR sensor

I split off this non-related question from here

You should add a flag that you set once you've dealt with a situation and subsequently only enter the same branche again when the flag got un-set again.