Add an automation execution mode that is one-per-trigger

I sometimes find myself wanting a new automation mode that is somewhere in between “once” and “parallel”.

I want it to be able to run one instance per trigger, in parallel.
This can be worked around by duplicating automations, but it would be much neater for me if this mode existed.

A concrete example:

I have an automation that uses my security cameras to detect motion. I then run an AI query to determine if it’s important, and then notify me.

I have one trigger per camera, then all other code is shared.
If multiple cameras trigger motion at a very similar time, I would like to be able to have an instance of my automation running in parallel for each triggered camera.

I envisage it to be logically similar to “parallel”, but with an extra check that the automation isn’t already running with the activated trigger. the unique set of running automations could be a new attribute, a bit similar to the current running count attribute.

Thanks for reading!

PS. in the interests of covering many use cases, it could be that this behaviour should be applied to queue, loop and restart too. So it’s a checkbox that makes the mode act per-trigger, instead of for the whole automation…

That is exactly what parallel mode will do. All you have to do is include a condition that checks that the AI query is not already running for the triggering camera.

1 Like

Apologies for my naivety, but, how do I check that?
I can’t see any attributes on the automation (or script) that would tell me that?

I have no idea it is your AI query. This:

That is the thing you use in your conditions.

Ok. So can i enumerate the list of currently running automations/scripts?
I can indeed query things about my automation/script if i have a way to access them.

To come back to this - an automation has a built-in way to know what triggered it for the current instance. It’s nothing to do with my specific setup. so if i can enumerate the running instances, i can query their trigger?

Yes. But you don’t need to. You know you have called it for the camera.