How to get automation to repeat once triggered

Never mind, that won’t work either. The state has to change to trigger the event, and the door simply remains open. I think the answer is to add a trigger from “violated” back to “normal”, and the while loop checks for THAT trigger. I’ll test it.

You appear to be uninterested in my suggestion to fix the while condition and focused on something else. Therefore I’ll bow out and let someone else help you. Good luck.

That’s what I said way up there ^.

And like I said you should use “repeat-until” instead of “repeat-while”.

trigger on the door being open (for however long you want) then in the action use repeat to send the announcement every minute (or whatever) until the door is closed.

if you have more than one door sensor that you want to trigger on you need to use parallel mode.

OR

you can just create one automation per door sensor and eliminate the confusion/complication of trying to figure out all of the different conditions and trigger id’s.

Just simplify things. It doesn’t make sense to try to condense everything into one automation and then tie yourself up in knots working out the logic.

Yes you end up with more automations but in the end they are more maintainable.

Taras I don’t know what you mean by “fix the while condition”. I assumed you meant delete it.

Your while should be conditioned by the door state, not the triggered event.
Replace with a repeat until door is closed (up to you to write the correct syntax)
Because, basically, you want to stop the loop when you shut the door close.

Edit: @finity is right, you should probably duplicate the automation for every zone as this one is kind of hard to maintain.

The whole idea is to simplify; the way finity suggests I would have over 30 automations (I have over 30 doors and windows to monitor) all doing the same thing. Insteon ISY-99 does this with one simple script; I’m trying to turn off my ISY automations and move to Home Assistant but I guess HA UI scripting still hasn’t gotten there yet. The ISY is always aware of states without me having to poll it. So HA’s entity ID would automatically change from “true” to “false” when the violation goes away.
So the answer is I can’t do what I’m trying to do simply, it requires a monster long automation…

You can write multiple triggers and their opposites and identify them.
Like if this and this and that (main door violated)
If not this or not this or not that (main door safe)
Then, and only then, you’ll be able to wait for the safe event triggering in your loop.

You can also have a look at template triggers. It is very powerful but required some coding experience.

Like this:

          {% set den_slider = states('sensor.den_slider') == 'Violated' %}
          {% set kitch_slider1 = states('light.kitch_slider1') == 'Violated' %}
          {% set front_door = states('sensor.front_door') == 'Violated' %}

          {{ den_slider or  kitch_slider1 or front_door }}

Good idea Olivier. I need to dig into template triggers. Meanwhile I’ll brute force it and have every entity tested for violation with different ID’s, then alert until the entity reverts with the “repeat until”. It’s a monster automation. In fact it’s much faster to do this in yaml vs. UI, I can use copy/paste.

I do that a lot :slight_smile: I do the basic structure of the automation using the UI, then switch to yaml and copy/paste tons of code at once.
I’m also a fan of VSCode as I open my automations.yaml and can also copy/paste from others look alike automations.

EDIT: You can also run scripts from automations, so it put the automation itself to the diet by removing repeated code.

I would do that but don’t know how to pass an entity to a script from my automation. If I could do that this would be easy! I’ll read up on scripting.

You might be able to do it with a script that is triggered by the automation.

you just need to set up the script to do what you want and the call the script with the automation sending the script data as variables from within the automation.

then you only need to run the automation and script in parallel mode.

That is assuming that a script can have more than one instance of itself running in parallel like an automation does. I can’t find a verification of that in the docs tho so I’m not 100% how that works.

Passing argument is not very difficult.
https://www.home-assistant.io/integrations/script/#passing-variables-to-scripts