"Running automations" condition in another automation

Hey team. Testing this is kinda tricky given it’s based around motion sorry - wanted to confirm this is doing what I think it’s doing?!
I want to use the “condition action” attached to only execute the next action if the other automation referenced (“Scullery - at night”) is not running. Have I got the attribute and state right on that? Thanks

Well, one way of doing it is to have that “other automation” set a virtual switch/boolean to “on” when it starts and to “off” when it stops.
from your current automation you can then just check the state of that switch/boolean in a condition.
But, I think it might also be possible via a template but I don’t have much experience with templates

Thanks, that’s a good idea for a fallback. I’m hoping that you can use the running “state” of an automation as a condition to streamline it though. I think the above is not working how I assumed…

An automation’s current attribute (displayed as “Running automations” in the visual Automation Editor) indicates how many instances of the automation are currently executing. A value of 0 indicates there are none running.

Be advised that most automations execute their actions very quickly (under a second or two) so their current value is 1 for a very brief time. Unless your automation takes several seconds to execute, there’s a very brief window of opportunity to detect it.

When using the Automation Editor, it has a habit of wrapping integer values in quotes thereby rendering it a string. For example, I created the State Condition you posted above and it looks like this:

condition: state
entity_id: automation.abc_test_1
attribute: current
state: "0"

However, current attribute’s value is an integer, not a string, so that State Condition may fail even when the value is zero.

I suggest you use a Template Condition because it offers better control over the value’s type (integer or string).

condition: template
value_template: "{{ is_state_attr('automation.abc_test_1', 'current', 0) }}"

4 Likes

Thanks for this level of detail, really appreciate it.
To your point re actions only “running” very briefly I don’t suppose you know if a “wait until” time action on the other automation will keep that automations state as 1? That’s what my logic is relying on, will check the state later when it’s running
Thanks again…

I was afraid that might be the case.

I’m not sure I understand the logic behind your request. I must have misunderstood it because it can’t be this:

You have two automations and you want to delay the second one’s completion until the first one has checked if the second one is running?

Maybe you should describe what you want to achieve with those automations instead of asking for a specific way that may or may not achieve your end goal?

On the surface it looks like for instance a timer helper might be more suited for whatever it is you want to accomplish. You can easily check if a timer is running and only use automations that are done a.s.a.p. Timers can also survive reboots, running automations cannot.

On top of that, timers can also be restarted or aborted when needed, and you can see how long they still run.

Yes you’ve understood correctly.
I guess the core question is does a “wait until” action step in an automation set the running automations value to 1 until it’s finished?

I’m probably trying to be more “streamlined” than necessary in trying to reference other automations and yes will just create a helper. Thanks all

Then whatever you’re designing is an anti-pattern.

Yes.

1 Like

Hello garethw. :love_you_gesture:

Sorry for the late response. I’ve only been in the Home Assistant scene for a few days and came across your problem yesterday, as I had the same issue. I also had in mind to solve the problem using a virtual switch, but I aim to avoid any unnecessary entities to prevent artificially inflating the system.

So here’s the solution to the problem:

  1. Choose your automation as the entity. In your case, it’s probably ‘automation.scullery_at_night’.
  2. In the next field, select ‘Running automations’ as the attribute, just like in your example.
  3. In the ‘state’ field, write either ‘true’ or ‘false’. Since you want the routine to continue only if your automation is not running, write ‘false’ in the field.
  4. Click on the three dots to the right of ‘Confirming running automations…’ and display the executed instructions as YAML code.
  5. You’ll notice that the word ‘false’ has been enclosed in quotation marks. This might be a system error and should not be the case. You need to remove these quotation marks. Then your instruction will work.

In my example, I want a motion sensor not to react during another 40-minute sunrise simulation, and in that case, to terminate the motion sensor automation prematurely. My check to see if the sunrise automation is currently running looks like this:

Note: If you remove the quotation marks “” in the YAML code, you won’t be able to return to the visual editor. It will signal this with an error message (see image, in German).

Question to you all: Is this a frontend issue? And if so, can the developers be informed about the problem to make Home Assistant even more powerful? Apparently, there’s still room for improvement here because once ‘Running automations’ is selected in the field shown above, you can’t choose parameters via a dropdown menu in the next field ‘state’, which requires input or selection.

I hope I was able to help some of you.

Stay crunchy - Flutz :sunglasses:

4 Likes