I am looking to set up an automation based on a motion detector binary sensor. I want the automation to trigger when the sensor goes to ‘on’, but ONLY if it has been ‘off’ more than 5 minutes previously (i.e. new motion).
I was thinking about making a second variable that is true whenever the state has been off > 5 minutes, and making it be a condition in the automation, but I’m afraid it will turn false when the sensor triggers before the automation can fire.
The variable for is relative to the new state, not the previous state.
That could work if you add a delay_off to keep it on for a few seconds extra, but it’s not necessary since all the data you need is available in the trigger variable. The last_changed property of the from_state will hold a datetime object reflecting when the previous state change occurred (in this case when the door closed). Add your offset to that time, and compare it to the current time.
No, that will always fail. The test that condition poses is “Check if the state is ‘off’ and has been so for at least 5 minutes”… but the current state is “on” not “off”.