Lights via Motion and Automation ... Timer vs Restart Automation

I am working on an Automation that in it’s basic form will turn on lights following a motion detection. I am planning on having a delay before the lights turn off of a specified value. When the time is up, the lights go off.

I’ll have some other conditions that will apply (time of day, day, sun position, lux, etc.) but I see 2 solutions to this problem and I’m looking for pros / cons to each.

Solution #1 - Single Automation that Restarts on a Motion Trigger

- id: '1637293261926'
  alias: Motion Lights (No Lux) - Hallway
  description: ''
  - type: motion
    platform: device
    device_id: bfcb6cb207346179b1382f413e5aaddb
    entity_id: binary_sensor.hallway_motion
    domain: binary_sensor
  - condition: time
    after: input_datetime.motionstarttime_downstairs
    before: input_datetime.motionstoptime_downstairs
  - service: light.turn_on
      entity_id: light.hallway_ceiling_light_1
      brightness_pct: 100
      transition: 3
  - wait_template: ''
    continue_on_timeout: true
    timeout: 00:05:00
  - service: light.turn_off
      entity_id: light.hallway_ceiling_light_1
      transition: 3
  mode: restart

Solution #2 - Two Automations … one that triggers on motion and starts (or restarts) a timer and a second that listens for the timer completing and then turning the lights off.

Any opinions on the more elegant / fail safe solution?

It looks like you’ve just tried to make a janky delay here, may be better to go with the official one if you go this route.

Anyway, doing it in one automation like this will continuously turn the light on to 100% bright, which may cause some problems if you ever want it dimmer than that. I think you could also achieve something similar with a wait_for_trigger that waits until the motion sensor state has been off for five minutes. This just stops it from continuously restarting, which I would consider more “elegant”. I haven’t done this exact thing myself before, so unsure if any quirks pop up, but I don’t think any should and it would probably be what I’d go with.

If you do separate it out into two automations, I wouldn’t do a timer and instead do what I said above: just wait for the state to be off for five minutes. There’s no reason to add complexity to something that already has a fine solution, but, based on that custom delay, it looks like you may just enjoy reinventing the wheel :slight_smile:

Either use this blueprint or borrow its code.

Haha, I definitely don’t like reinventing the wheel. I blame it on ignorance. Thanks for the pointer and reference, I’ll take a look at that!

1 Like

Thanks. I’ll check out the features / code on that one. At first glance it looks pretty promising. I thought at one point Scenes were having issues with multiple lights though. I’ll have to do some homework, but the logic on that Blueprint looks pretty close to what I was wanting … great reference!