Motion lights

Two automations

1.) turn on like if motion is detected
2.) turn off light when motion is clear for 5 minutes using the for field.

Is this the correct way of doing it?

I’ve had a couple automations kick off that had a for statement of an hour and it was only like two minutes ???

That should do it.

What did your trace show ?

Have a look at blueprints, there are plenty of blueprints that cover this sort of thing.

Just learning about this for the first time.

This happen while in the room and the occupancy sensor was just triggered on a few minutes ago. So no way it was in a clear state for an hour.

Does the automation look correct?

Or Entity Controller in HACS, which is much more compact.

This looks nice, but I want to understand how to write the automations natively and not depend on perhaps an integration breaking due to upgrades.

Blue prints or a manual automation like above seem like the less of the three from breaking due to upgrades.

if you use

to: 'off'

in the trigger, it triggers from ‘on’, ‘unavailable’ and ‘unknown’ to ‘off’

better use

from: 'on'
to: 'off'

and I would not use for: for anything more then a few minutes.

Why? What reasons shouldn’t I?

The drawback of using long periods of time in for, is that its countdown is reset whenever Home Assistant restarts or automations are reloaded (if you compose/modify automations with the Automation Editor, the moment you click the Save button it will automatically reload all automations).

1 Like

And the timer will also reset if the item becomes unavailable.

Can you provide a better example of how to do this?

Use a timer

After some YouTube videos, I have a question.

Can a timer be used twice at the same time? I assume not and I should have timer helpers created for every automation??

Here is what I’ve come up with… Thinking this will work just fine?

This was fixed in the release last November.

1 Like