Start second timer after first finished

Hello, complete new here, and searched many topics, and YouTube, but I can’t find a working solution.
I have the following situation: Motion sensor, and led strip. That’s it.
What I want: after movement, enable the led strip for a fixed time, e.g. 2 minutes. After the two minutes, motion can be detected again, for e.g. 15 seconds. And this time, when there is a new motion within these 15 seconds, the timer may start again for 15 seconds. And this goes on as long as there is motion.
Is this possible?

I have watched this YouTube tutorial, but in this example, the timer restarts after a new motion is detected. And I want a fixed time after the first motion.

I tried with delay, but just don’t know to make the second part.

This is the code from the Youtube tutorial

alias: Badkamer beweging copy original
description: ""
triggers:
  - trigger: event
    event_type: timer.finished
    event_data:
      entity_id: timer.badkamer_timer
    id: Timer finished
  - type: no_motion
    device_id: 7c9b2ceb48db904196b9aa1ae269caad
    entity_id: 1434ddd41f85d7fccc3e9f6342a9204b
    domain: binary_sensor
    trigger: device
    id: Motion stopped
  - type: motion
    device_id: 7c9b2ceb48db904196b9aa1ae269caad
    entity_id: 1434ddd41f85d7fccc3e9f6342a9204b
    domain: binary_sensor
    trigger: device
    id: Motion detected
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Motion stopped
        sequence:
          - action: timer.start
            data:
              duration: "120"
            target:
              entity_id: timer.badkamer
      - conditions:
          - condition: trigger
            id:
              - Motion detected
        sequence:
          - action: timer.cancel
            target:
              entity_id: timer.badkamer_timer
            data: {}
          - type: turn_on
            device_id: 7c9b2ceb48db904196b9aa1ae269caad
            entity_id: 8243d8b162c2cc1f8f8a023b6391e913
            domain: light
      - conditions:
          - condition: trigger
            id:
              - Timer finished
        sequence:
          - type: turn_off
            device_id: 7c9b2ceb48db904196b9aa1ae269caad
            entity_id: 8243d8b162c2cc1f8f8a023b6391e913
            domain: light
mode: single

And this is my simple code

alias: Badkamer licht aan
description: ""
triggers:
  - type: motion
    device_id: 7c9b2ceb48db904196b9aa1ae269caad
    entity_id: 1434ddd41f85d7fccc3e9f6342a9204b
    domain: binary_sensor
    trigger: device
conditions: []
actions:
  - action: light.turn_on
    metadata: {}
    data:
      brightness_pct: 33
      transition: 2
    target:
      entity_id: light.badkamer_esp32_badkamer_ledstrip
  - action: timer.start
    metadata: {}
    data:
      duration: "60"
    target:
      entity_id: timer.badkamer
  - delay:
      hours: 0
      minutes: 0
      seconds: 15
      milliseconds: 0
  - action: light.turn_off
    metadata: {}
    data:
      transition: 0
    target:
      entity_id: light.badkamer_esp32_badkamer_ledstrip
mode: single

Regards, Peter

You can do this with repeat until no motion (delay 15 seconds). (You’ll have to look up the exact syntax.)

However, you should first make sure that your motion detector can actually detect a change in 15 second increments. My experience is that anything under a minute is iffy.

The way I handle this is to have the automation turn on the lights for longer than the minimum time of the sensor (5 minutes in this case) and if the sensor triggers again during those 5 minutes, it restarts the automation. This means it will always be on for 5 minutes from the last time motion was detected:

- alias: Bedroom closet lights on motion
  id: bedroom_closet_lights_on_with_motion
  mode: restart
  trigger:
    platform: state
    entity_id: binary_sensor.bedroom_closet_motion_sensor, binary_sensor.new_motion_sensor
    to: 'on'
  action:
    - service: homeassistant.turn_on
      entity_id: switch.bedroom_closet_ceiling_lights
    - delay: '00:05:00'
    - service: homeassistant.turn_off
      entity_id: switch.bedroom_closet_ceiling_lights

-David

There’s an example of how to do this in the Cookbook:

Motion activated lights automation