I've recently modified the code a bit. Will post an update soon. The way a PIR motion sensor works, is that you can setup the duration of a detected movement by tweaking a potentionometer. That will determine the amount of time the PIR sensor will report back as a motion detection. In reality you know only one thing. There was at least one motion detected that triggered the motion pin of the PIR sensor. Between that period and that and the interval you've setup, there might have been a lot of movement but the PIR doesn't report that back.
How I solved that is as follows. I turned the potentionometer to the lowest must interval duration. Whenever the first movement has been detected, it will report that to my Home Automation controller and it will start a timer that is 30 seconds after the detected motion. As my current motion detection interval of the PIR sensor is around 3 seconds, it will give me another 27 seconds to detect a follow up motion.
If a follow up motion has been detected, it will reset the 30 second timer. So that has another 27 seconds the time to detect another motion. If however no motion has been detected when the 30 seconds timer times out, it will tell my home automation controller that there's no longer any motion.
As most PIR sensors are quiet sensitive, they detect my presence by each small movement a wake. In most cases the movement caused by breathing is enough for the PIR sensor to detect my presence.
Hope's this explains is. I've tried it in my best English ;-)