When presence is detected, lux value is updated and light comes on as expected.
When presence is cleared, light turns off and lux value updates to before the light turned off (so lux value is higher than 1200, depends on bulb brightness).
When presence is detected again, light stays off, although lux value is updated to reflect lower than 1200 - I want the light to come on not stay off
I think I understand why number 3 happens, even though the lux value is updated, the automation uses the value before it is updated. I tried adding a 1-second delay before conditions, but this does nothing and isn’t really ideal.
check your traces, it will tell you why it didnt continue on what step
On top of that, you created a long running automation, thats not the best pattern to do these.
I would suggest to inlcude both triggers (form on to off and from off to on) in start section, create ID for them and make logic in action to choose the right flow based on trigger id.
Show the automation trace of a time when it did not come on as expected. I think something else is bugging you. For instance, if the automtion hngs in the wait for trigger, then because of the single execution the automation won’t run again. This will for instance happen when you turn the light off manually when there is still motion.
It is better to split this in two separate automations then it is to have a long running automation.
Your hunch is correct. Most motion sensors with built in lux sensors will only update the lux sensor value after they detect motion. Granted, it’s only a few milliseconds, but it’s a long enough delay that your automation has already run by that time.
Show where you added the delay. It should be part of your trigger, not part of the conditions.
Something like this:
triggers:
- trigger: state
entity_id:
- binary_sensor.entrance_motion_sensor_occupancy
to: "on"
for:
hours: 0
minutes: 0
seconds: 1
#milliseconds: 500
Note I commented out the milliseconds part since that is not supported by the visual editor. Test the 1s in the visual editor first, then if it works, drop to yaml mode and test the milliseconds option.
Like @Edwin_D mentioned, looking at the automation traces will be a key part in determining why something did not behave as expected. Follow his advice and use the traces to troubleshoot.