AFAIK, you can’t reset the index… but if you did reset it, the delay would just repeat indefinitely until the power sensor was equal to 0… is that the actual goal?
If it is, you would be better off with a Wait for template or Wait for trigger. But even better than that would be to get rid of the waiting altogether. Either add a trigger for turning the switch off and use branched logic (If/Then or Choose actions) or set up a second automation to handle turning the switch off.
It looks like this automation might be running for hours at a time, right? That would not be a very good idea. Automations aren’t really intended for that (e.g. you shouldn’t restart HA while this is running). I have a suggestion, but would need confirmation first.
Yes, but this is not a very big problem in this case. I can do this using two different automations, but I would like to know how can I do this very standard algorythm. If I code something with assembler, I always do anti-rattle this style