Motion lights turn on/off automatically?

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'
1 Like

good one :point_up:

and indeed,

mode: restart

will cause the delay to be reset (but that was not a requirement :thinking:)

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.

1 Like

@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 :grin:)

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. :wink:

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).

hmm, now that you mentioned it…it is a binary sensor, however HA offers me:

totally agree :joy:

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.

1 Like

What you see in “Visual” mode is usually a “prettified” version of reality. Developer Tools > States shows reality.