How do I set dynamically every on aggregateWindow?

You could compute delta= v.timerangestart - v timerangestop in a variable at the beginning. Note that, one of the 2, at least in the past, was a duration, so you have to convert it to a time (or an integer?) I don’t remember if it was start or stop but you’ll figure it out.
Then you make a sequence of if-else. Something like:

Test = if delta <1h then… Else if delta < 3h then…
I don’t remember exactly the if structure and i am on the phone. Anyway, we do something similar somewhere so it is doable

Then you replace your 10m in your script inside of the aggregate window with the variable Test
Good luck