Binary sensor, timer automation

i need some help with a problem.

I have a binary sensor, on state change i increment a counter.
now i want the counter to be reset after 5 min. of inactivity.

Is this posible if so how do i do it ?

Is it worth adding your yaml. Then we can see how you have written your counter?