Automation - repeat until trigger (bug?)

i have a button which sends click, double click, hold, release etc. im setting this up to control lights for dimming plus some extra features.

I want to hold for dim (or brighten depending on state of light) and use repeat until the ‘release’ trigger ID however this does not seem to be possible. The only way to get the repeat loop to stop on the release is to change the automation run type to “restart” where it does not look for the specific trigger ID so prevents me doing my extras (I want to use a wait until trigger elsewhere using trigger ID from same button).

the wait until trigger works as expected even if automation run type is set to single. I would expect the repeat until trigger to behave in a similar fashion. Am misunderstanding the functionality of this automation component or is this a bug?

Yeah, what you’re trying to do won’t work in a single automation. I suggest separating the “release” functionality into a separate automation and turn an input_boolean on or off (your choice) when the event happens. Then have the repeat/while loop exit based on the input_boolean changing state.

The flow would look like:

First automation:

  1. Trigger on button push, turn input_boolean.button on
  2. Loop to brighten/dim until input_boolean.button turns off

Second automation:

  1. Trigger on button release
  2. Turn input_boolean.button off
1 Like

Thanks, I was considering that as an option and guess its the only way.

is there a specific use case of the repeat until - trigger? I cant understand how it could actualy do anything unless it reacts to the selected trigger!

Do you have a pointer to where this “repeat until trigger” construct is described? I’m not sure what you’re talking about. All the “repeat” options here work based on conditions: https://www.home-assistant.io/docs/scripts/#repeat-a-group-of-actions

dosnt seem to be in documentation but they have clearly thought about it and built into UI


Okay, fair enough. I don’t know what that’s really doing, since triggers are events and wouldn’t be directly suitable for use in a condition, but there is a wait_for_trigger that has similar functionality within an action. In any case, I suggest searching for or filing an issue on GitHub with your findings, as without documentation it’s difficult to know how it should behave or if it’s broken.

I ran a quick test with repeat until “triggered by” and it let me specify a trigger ID. In the YAML, it ended up as a condition: trigger, and I couldn’t get the loop to exit no matter which automation mode I used. I’m not sure how it’s supposed to work.

I highly doubt this is a bug.

I doubt they ever thought it would be used the way you did in your automation. The Automation Editor doesn’t prevent you from composing a non-functional automation.

This is a Trigger Condition:

- condition: trigger
  id: release

The UI allowed you to select the word release because it’s the id of one of your automation’s triggers.

Once the repeat is underway, subsequent triggers cannot influence its Trigger Condition (regardless of whatever mode you have chosen; default is single).

Basically, you have created a repeat whose condition relies not on the automation’s current trigger but on some future trigger. That simply doesn’t work.

Once the automation is executing its action the only “future” trigger it can detect (while still remaining in its currently executing action) is with a wait_for_trigger.

It’s a non-viable automation; the Trigger Condition was misused in the repeat.

if that is the case, the bug is that the UI give the the option to repeat until trigger.

It would be very useful if it could work in this way and I feel should be possible given that its similar to wait_for_trigger which does work even if mode is single. in my case I have a button that sends a hold signal and later a release signal so I want my automation to perfom the loop once hold signal is recieved and stop when release (dimming lights in my case). I realise I can do this with a helper boolean but adds more complication for something that is trying to be accessible and usable by someone with little programming experiance.

That’s not a bug either.

The Automation Editor can’t guess what you are trying to build so it offers all available options. You’re free to compose whatever you want, including something that doesn’t work.

It’s not the same and if you feel it is I suggest you review the documentation for Scripts and Script Syntax.

my mistake, I thought I had used wait_for_trigger with a trigger ID but had actually set the trigger to the same as the trigger ID of the automation but not the trigger ID itself!

Unfortually the repeat until trigger does not seem to give me the same option when I select this same device. As you say, the syntax in each differs (the top set of code is from the repeat until trigger and the bottom is from wait for trigger)

image

If you’re still looking for a solution, I think this is still the easiest option, and will definitely work.

There’s no such thing as “repeat until trigger”. It’s something you invented when you chose an incompatible condition for use with repeat.

Review the documentation for repeat until, repeat while. They require conditions that rely on the state machine and/or the “repeat loop variable”. repeat can’t listen for triggers.

easiest option was to change the mode to ‘restart’ and alter my wait until section of code to take account of the fact that the previous section is repeated while the next part is carried out.

strange as I wouldnt have thought the automation would proceed past wait until trigger if set in the restart mode.

I know Its much cleaner and would work better to set up boolean but thats going to take a good 5 mins to do and ive already spent so much time finding this awkward workaround!

What kind of device is it? There may be an existing blueprint for it.

its a WXKG01LM. good suggestion, will have a look in blueprints tomorrow but feel its probably unlikely…

You’re in luck, there are several blueprints for that device:
https://community.home-assistant.io/search?expanded=true&q=WXKG01LM%20%23blueprints-exchange

… there will be any integrations that will repeat an loop during hold then stop on the release