Triggering an automation 'X' only if automation 'Y' has been triggered 5 minutes before

Its all in the title.
I want to trigger automation X only if automation Y has been triggered. This is easy enough.

But I cant get it to work, if automation has been triggered 5 minutes before or less. If it has been more than 5 minutes then do nothing.

I assume this involves templating? And I’m very bad at them! Any ideas?

Timer helper?

1 Like

value_template: “{{ ( as_timestamp(now()) -
as_timestamp(state_attr(‘automation.light_on’, ‘last_triggered’))
|int(0) ) < 120 }}”

This is what I found so far. But it doesn’t work. I put this in the condition section of the automation

If that’s the condition, what is the trigger for automation x?

This looks OK at face value (I’m not at my PC right now). Have you tried checking it in developer tools - template?

I will try with timer helper. You can start timer when automation 1 triggers and set condition to run second automation when timer change from running to idle.
I don’t claim that this will work.
Or better to say create trigger that will trigger second automation when timer change from active to idle.

When automation Y is triggered, do whatever it does and then enable automation X. Then have automation Y wait 5 mins and disable automation X.

Correction: It’s not disable, it’s “Automation: Turn off”

This sounds like a good idea.

So the timer (5 minutes) is triggered by automation X, and for automation Y to run, I want the timer to still be running. If the timer goes to idle/5 minutes have passed. Then I do not want to run automation Y.

How do I go about creating the timer and consequently the automation. :slightly_smiling_face:

I’m not sure what upu mean here.
I do not want to run automation Y, if it has been 2 minutes since automation X ran.

Doesn’t work in the developer tools. So it must be the template which has something missing. I’m not sure what could be wrong with it

OK, try this - I changed out all your quotes from ` to '…

{{ ( as_timestamp(now()) - as_timestamp(state_attr('automation.light_on', 'last_triggered')) |int(0) ) < 120 }}

edit1: this works for me in dev toolstemplate when using one of my automations.

edit2: You need to put it back inside double-quotes "

"{{ ( as_timestamp(now()) - as_timestamp(state_attr('automation.light_on', 'last_triggered')) |int(0) ) < 120 }}"

I have trouble understanding sarcasm but you want to trigger automation x if automation y was triggered before 5 minutes.
I don’t know will this work, but test it out, if you wish.
Create timer helper call it as you wish and set it up for 5 minutes.
Create automation y and add call service timer to start a timer when automation triggers something.
Create automation x and trigger that automation by timer going from active to idle. Timer will change from active to idle only when automation y has been triggered.

1 Like

I must not understand exactly what you are trying to do. My solution is basically, Turn off the automation(s) you don’t want to trigger and turn them back on when you do.

So I think you are almost stating what I want to to achieve.
I want the automation X to only run if automation y triggered 5 minutes or less.

So for example, If automation y triggered at 8.00pm I only what to trigger automation X if I press a button and it is 8.05pm or less. If it is past 8.05pm then do nothing.

So now I created a timer helper. Now I’m struggling on using if and if not statements. Can they be used in GUI automation. Or do I need to code in yaml

It would help to provide a more concrete example. But it is as easy as this:
In automation X, start the timer helper with a duration of 5 mins.
In automation Y, add a condition to check if the timer is running or not.

There were no buttons, time condition or any else in beginning. I really don’t know how all that came out.
Why don’t you start like a man will do.
Create simple automation to turn on light. When the light is turn on call timer helper.
Create second automation to turn another light on, but in this automation use timer helper as a trigger to turn another light on.
If it works make it more complex adding other conditions to it.

Yep it was as simple as that.
Well I didn’t know helpers existed before this post. So after figuring that out it was simple enough.
Thanks for the help!

1 Like