Automation trigger for x minutes after entity state change

I need to create an automation trigger for a scene to be triggered say 90 seconds after an entity has changed state.
The automation template in HA allows for an action to be triggered after a delay but only if the entity has remained in that state for say 90 seconds

To explain the use case further , I live in a semi urban area where brownouts are common.
I have a power backup that kicks in 30 seconds or so after mains power goes down.
However that sets a lot of my devices (lights mostly) to an on state.

I have created a binary sensor (Ping based) that changes state to off when power goes out and on when it resumes.
The way I want to use it is for HA to :
1 - 00:00:00 State changes from on to off (power outage)
2 -approx 00:00:30 - State changes from off to on (backup power kicks in)
3 - approx 00:01:30 - all devices are back online
4 - approx 00:02:00 - trigger scene to set all lights to off (unless it’s between dusk and midnight)

Any thoughts or suggestions?

Hey superczar,

hm, the trigger would be the State (on to off)
Then just add a “delay” action with a time of 00:01:30 and put your “activate scene” after that :slight_smile:

Thanks - I feel stupid now :slight_smile:
Still pretty new to HA so really appreciate your help!

1 Like

Yeah, it can be confusing

Delay is just “wait for x amount of time, then continue”
You also have a “wait” action, this is basically: “Wait until y happens (like a state change or whatever).” If y doesn’t happen you can also specify a timeout after which it either continues executing your automation it cancels.

And then, don’t forget about the “State” Trigger with the “For” field - basically “Trigger this automation if the state is z for at least x amount of time.”