How to build a looping automation