So you only want the automation to turn the light on if it’s off AND the last time it was turned on was by something other than HA, no matter how much time has passed?
I would create two input_datetime helpers, called “last on” and “last HA on”, and a secondary automation that sets “last on” to the current time whenever the light goes on.
Then the main automation is two triggers (motion & lux); a condition that the light is off and a template condition that the “last on” and “last HA off” are the same (to within a couple of seconds).
The action them turns the light on and sets the “last HA on” helper to the current time.
A third automation triggers 5 minutes after the “last HA on” time to turn the light off.
You could combine all into a single automation with trigger IDs everywhere, but keep it simple at first to get it working.
“Answers are easy. It’s asking the right questions which is hard.” - Tom Baker.
This is pretty much the first automation that most people do - so there are already plenty of examples on the forum.
This just means that the light will flash all night long, since as soon as the light is turned on it will increase the Lux level and when it turns off it will trigger the automation again - I am guessing that’s not what you want.
So that means the automations will only run if the last time the light was turned off it was done manually - again not sure thats what you want, but easy to implement:
Add an input boolean lets call it allow_auto.
Every time the light is turned on set allow_auto to ON **
Before an automation turns the light off, first set allow_auto to OFF
Add a guard condition to all of your automations to check if allow_auto is ON.
** - The light turning on will either be because the allow_auto is already on or someone is manually turning on the light.
Thank you guys. So here is what I did and it work so far.
Increased LUX threshold so Bulb does not react to the bulb in garage.
For automation: I created Helper 5min Timer. Every time I want turn light ON the Timer is Started. And I finish timer on a Trigger when I want turn Light OFF. There is a trigger to turn Light OFF when timer is Finish. All in one automation with 4 triggers: Motion detected, Lux moved from HI to Low, Lux moved from Low to HI, Timer changes from Active to Idle.
And 4 Options for Actions.