How can i use my homeassistant scene to turn on lights with motion, but then after a set amount of time (10 minutes) automatically shut them off?
You donât use scenes for that, have a look at automations. Iâve not looked, but I imagine youâll find some blueprints.
Thereâs certainly several helpful threads.
Search for automation, motion, light
ITâs fairly straightforward, I found using trigger IDâs makes things very simple, add 2 triggers one when motion is detected give that a trigger ID then one when motion stopped detecting, now hereâs the rub, if you want roughly 10 minutes the set the second âoffâ trigger to say âforâ 10 minutes, this will be 10 minutes after the motion sensor has stopped sensing so it depends on how long that takes, most are about 5 minutes or so. If you want exactly 10 minutes then a timer will be needed. After that in the actions section choose ⌠well⌠choose, you can then use triggered by your trigger IDâs. Sounds like a lot, but take your time, I found Smart Home Junkie a great help on you tube, did a whole tutorial on this.
i think @itnassol is over complicating things a bit:
description: ""
mode: single
trigger:
- platform: state
entity_id:
- binary_sensor.motion_bar_occupancy
from: 'off'
to: 'on'
condition: []
action:
- service: light.turn_on
data: {}
target:
entity_id: light.bar
- delay:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
- service: light.turn_off
data: {}
target:
entity_id: light.bar
if you insist on using a scene, create 2 scenes (one on, and one off), and use âscene applyâ instead of light.turn_on/off
Add mode: restart
so that movement serves to restart the delay
. Otherwise it will turn off the light after 10 minutes even if thereâs still movement.
Add this to the State Trigger to prevent triggering if the binary_sensorâs state changes to/from unavailable
(or if it has attributes, like battery level, and they change state).
- platform: state
entity_id: binary_sensor.motion_bar_occupancy
from: 'off'
to: 'on'
good one
and indeed,
mode: restart
will cause the delay to be reset (but that was not a requirement )
I do tend to go belt and braces, just found this to be a lot more stable over time, but I like your take on it.
@itnassol i donât like using too many triggers for the same thingâŚ
(i just love the recent addition, using a trigger_id in combination with choose/condition âtriggered byâ; it allowed my to reduce my automations by more than half )
I agree, the choose function has halved my automations, I am fairly new and very old, but itâs such a cracking piece of kit.
Yes, for a sensor
entity. The example you posted uses a binary_sensor
entity whose nominal states are always on
or off
.
It becomes a requirement the first time someone experiences the light turning off while theyâre still moving around.
Be advised that relying on delay
was not recommended in previous versions of Home Assistant because Reload Automations would terminate it. Now it only reloads new/modified automations and doesnât disturb automations that are in-progress (like the one above with a delay
in the process of counting down).
If one wants the automation to also survive a restart then it would need to be redesigned (use a timer
instead of a simple delay
).
But if you choose âdetectedâ from there and then look in the YAML, itâll be converted to âonâ.
Check developer tools and youâll see binary sensors are all on or off. Their device_class determines whatâs displayed in the front end.
What you see in âVisualâ mode is usually a âprettifiedâ version of reality. Developer Tools > States shows reality.