Adding Timer Help Needed

I have an automation to turn on a light via script when motion detected. What I want to do is add a timer to turn the light off after there has been no motion for 2 minutes.

I’ve never used timers before so I’m confused as to whether to put it in the script or automation and the correct syntax. If someone more capable than me is able to help out I’d be grateful.

Automation:

-  alias: Turn on off stairs light when there is movement at night
   trigger:
     - platform: state
       entity_id: binary_sensor.staircase_sensor_occupancy
       to: 'on'
   condition:
     - condition: time
       after: '22:00:00'
       before: '08:00:00'
   action:
     - service: script.stairs_early

Script:

stairs_early:
  alias: Stairs Early
  sequence:
    - service: light.turn_on
      data:
        entity_id: light.stairs_spot
        brightness: 78
        color_temp: 366

No need to use a timer. Just turn off the light if motion has been off for 2 minutes straight.

-  alias: Turn on off stairs light when there is movement at night
   trigger:
     - platform: state
       entity_id: binary_sensor.staircase_sensor_occupancy
       to: 'off'
       for:
         minutes: 2
   condition:
     - condition: time
       after: '22:00:00'
       before: '08:00:00'
   action:
     - service: light.turn_off
       entity_id: light.stairs_spot

So I need to add a separate automation then? I was hoping to keep it all in one but is that not possible?

You can, but it makes it much harder to manage. Why do you want it in one?

1 Like

It was simply just to keep it all in one but if it’s easier to manage in separate automations I’m happy with that.

Thanks Petro.

Here’s what it would look like with 1 automation:

-  alias: Turn on off stairs light when there is movement at night
   mode: restart
   trigger:
     - platform: state
       entity_id: binary_sensor.staircase_sensor_occupancy
       to: 'on'
   condition:
     - condition: time
       after: '22:00:00'
       before: '08:00:00'
   action:
     - service: script.stairs_early
     - delay: "00:02:00"
     - service: light.turn_off
       entity_id: light.stairs_spot

but you’d need to update your script.

stairs_early:
  alias: Stairs Early
  sequence:
    - "{{ is_state('light.stairs_spot', 'off') }}"
    - service: light.turn_on
      data:
        entity_id: light.stairs_spot
        brightness: 78
        color_temp: 366
1 Like