How to keep one automation from running within X seconds of another automation

Hi. How can I keep one automation from running within X seconds of another automation running? Thanks!

I Think you’d be better of, explaining your use-case and showing the code of your automations

in short , and automation run when it’s triggered, and execute it’s actions and wont run until it’s triggered again.
i.e my motion enabled light automation runs in a split second ( Meaning i have no delays/waits )

Automations have last triggered attribute, you can use that and compare with now in a template.

I have two automations. Each automation is set to turn a light on and send a notification, when it’s motion is triggered AND switch is on. The motions are for the same area. They are semi redundant but I want them both - I do not want both of them to run if one has already ran within X seconds because that results in multiple notifications.

Is this just a hypothetical question ? , or do you have problems with something you have up and running ? , ie some detailed Code not acting as you expected ?

conditions:
  - condition: template
    value_template: >
      {% set lt = state_attr('automation.another_automation','last_triggered') %}
      {% if lt is datetime %}
        {{ (now()-lt).total_seconds() > X }}
      {% else %}
        true
      {% endif %}

Replace automation.another_automation with the entity ID of your “another automation”, and X with your X.

This accommodates the situation where “another automation” has not been run before. Also note that the poorly-named last_triggered attribute is only updated when the actions block of the automation is reached, not when a trigger was fired.

Even thou the automation(last triggered) wont change upon next Motion-Detected ( If the Light is already ON, woudn’t the automation still send a “New” Notification, as it’s triggered by the Motion
I.e Motion Detected , send Notification And Turn on light
I.e Next Motion-Detected, Send Notification , but skip turn on light(as it’s still on)

Never mind, as i don’t “See” OP’s use-case/automations, i can’t really suggest anything, as a few seconds in an Area covered by 2 motion-sensors, would lead to multiple Notifications, if there isn’t another “Stop” in Conditions

Someone else had asked the same question. My recommendation was to consolidate the two automations into a single automation. Effectively, the single automation manages the timing of what should, or should not, happen.

The user posted their two automations, they proved to be good candidates for consolidation, and I provided the user with a consolidated version.

If this interests you, post your automations.

1 Like