Can a running automation be stopped?

Hi.

I’ve managed to write an automation which uses a repeat until loop and gets into an infinite loop sometimes.

I’m debugging this, but this is complicated by the fact I can’t see how to stop it. Is there some way on interrupting a running automation?

automation.turn_off will do that, but has the side- (or primary, really) effect of disabling the trigger. If you instead put the action into a script, then you can use script.turn_off.

Great thanks!

Just saving the automation in the UI does that?
I think it does. That is what it feel like at least.

1 Like

Ensure the conditions you are using include a test that prevents more than a maximum number of repetitions.

Here’s a simple example :

  until: "{{ repeat.index > 20  or  your_other_conditions }}"

This seems to generally work - and I haven’t found any other way of terminating a running automation other than a restart of HA. I see that people have suggested writing automations to cancel an automation - but that sort of defeats the purpose - needing to write an automation every time you want to cancel something that is already running :-

I think though that you need to make a significant change to the automation and re-save it to cancel it. For example, I have an automation with a repeat loop 15x in it. Just changing the description allows me to re-save it - but will not stop it from continuing to run. Changing the loop counter to a number lower than it is currently at (for example, my automation has run 7 of its 15 iterations, so I set the repeat loop counter to 5, and then save it. Now set it back to 15 and save it again - and the automation will have ended.