Resetting sensor on inactivity

Try putting a timeout filter on the integration with value : 0 ?

By the way, please take a moment to figure out how to format your code properly for the forum so it is easier for us to read.