How to stop an automation once a condition is met (when a door is changed from open to closed)

Hi,

I’m sure this has been asked many times but I’m unable to find a direct answer in the forum.

I have door sensors. I want to set an automation to keep making a sound until the door is closed. I can easily set the automation to run when the door is opened, but how to I tell HA to stop the automation as soon as the door is closed? I’m not very good at using scripts so I’m using the GUI on the automation page. I can’t see any option for stopping the automation automatically.

Thank you.

The easiest way is to make a new automation, “stop sound when door is closed”

Use the repeat until function. That should do it.

Hello ritchie,

Well automations are started from triggers and end when the actions are complete. Generally automations are very quick and done.

You may be having a bit of an XY Problem.

If you want to make decisions in the actions / while the actions are running that is possible.

Generally for simplicity’s sake you have an automation trigger on a thing happening, that starts or runs an action, then another automation that triggers on a different event, and that stops the first action or runs something else.

Lots of opportunities to combine things , but starting out simple and getting it going is what I recommend.

Thanks. All good advice but the repeat until option was the final one I decided on. Thanks for all the help.

Be advised that when Home Assistant is restarted, all automations that are in progress are terminated.

That means if your automation is busy iterating its repeat until, it will be immediately terminated and will not resume on restart.

Given this potential failure scenario, examine your automation and determine what are the possible consequences. If they’re benign then no worries, otherwise you may need to redesign the automation to be more resilient.