How to run a loop only once while having constant update on a sensor?