Yeah that’s the way to do it (though I would recommend not using device triggers and actions). There used to be an example like this in the docs (it is a common question);
automation:
- alias: Turn on kitchen light when there is movement
trigger:
platform: state
entity_id: sensor.motion_sensor
to: 'on'
action:
service: homeassistant.turn_on
entity_id: light.kitchen_light
- alias: Turn off kitchen light 10 minutes after last movement
trigger:
platform: state
entity_id: sensor.motion_sensor
to: 'off'
for:
minutes: 10
action:
service: homeassistant.turn_off
entity_id: light.kitchen_light
I’m sure there are automation blueprints for this too if you search.
Out of curiosity, why do you recommend against using device triggers and actions? They seem to work fine, but I’m always looking to learn new and better ways!
Toml named the reasons in the linked thread.
Entity_ids are renameable, if you change the device that triggers the automation you can simple rename the entity_id of the new device to that one of your old, and the automation runs as before.
Using a device trigger you have to change the automation.
And device triggers don’t support templating, so it’s a good thing to get used used to the way toml suggested…
In your example imho it would imho now make no difference, both will do the same. But for things in future it would be more flexible and is easier to code in yaml for example.
Thanks all for your input and ideas!
I’ll be testing out some more implementations as you suggested before using it live.
But the fact is that my configuration is doing its job but don’t understand the logic behind the timer’s start point at xx:24 before going to active for additional 36 secs and then the finished event is fired…but somethings are just to get used to
There are a lot of ways to accomplish this, but you might consider using Automation for it. I used to script mine but found Automation better for my needs because I wanted to be able to re-trigger that 5 minute time out rather than let the light(s) go out, wait for motion and turn them back on again.