Automation help please. Retrigger

I have an automation that turns on a light when a PIR detects movement.

How can I reset or retrigger the turn off delay? In other words, as long as the PIR sees movement, the light stays on. When there is no movement, the light turns off after X minutes.

It is pretty easy in Node Red, but I want to learn more about automations.

an example would be:

automation:
  trigger:
    - platform: state
      entity_id: binary_sensor.kitchen_motion
      from: 'on'
      to: 'off'
      for: '00:05:00'

This will trigger an automation if the kitchen motion sensor goes from ‘motion’ to ‘no motion’ and stays that way for 5 minutes.

What I do is it a bit long winded but works every time

I have the Motion Turn on a input_boolean and them I turn that off after 1 sec

  - id: 451a9b93-31b8-4064-8fe3-efd452ba33f7
    alias: Turn on/off someone in room 1
    initial_state: true
    trigger:
      - platform: state
        entity_id: binary_sensor.office_motion #"{{ states.input_text.motion_a_1.state.split('-')[0] }}"
        to: 'on' #"{{ states.input_text.motion_a_1.state.split('-')[1] }}"
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.someone_in_room_1
      - delay: 00:00:01
      - service: input_boolean.turn_off
        entity_id: input_boolean.someone_in_room_1

so now each the motion turn on the “boolean” 1 sec turn it off maths easyer

so now we can put some good logic in place

#=======================================================================
  # now This Is the Brains of it
  # if the state does NOT change for X minutes do something
  # you mite want to as some conditions to make it smarter
  # this automation is where you set the  action
  #=======================================================================
  - id: "13aee00d-8806-443b-9f1c-41b69871ca91" 
    alias: "motion on for x min"
    initial_state: true
    trigger:
      - platform: state
        entity_id: input_boolean.someone_in_room_1
        to: "off"
        for: "00:{{states.input_select.motion_delay_1.state}}:00"
    condition:
# ********************************************
# added a condition to make it smarter
# ie I know the states of the office switch
# off  = Auto turn on/off 
# ********************************************
      - condition: state
        entity_id: sensor.office_switch
        state: "OFF"
#
    action:
      - data:
          entity_id: input_select.motion_a_1
          option: "clear"
        service: input_select.select_option
# set the off action
      - data:
          entity_id: light.office
        service: light.turn_off
  #=========================================================

now the on bit

  #=======================================================================
  # Now the ON BIT
  # again add some conditions
  # office light MUST be off and the Light switch MUST be OFF
  #=======================================================================
  - id: "motion in office : light on "
    alias: "motion in office : light on "
    initial_state: true
# the motion action
    trigger:
      - platform: state
        entity_id: binary_sensor.office_motion
        to: "on"
# ********************************************
# added a condition to make it smarter
# ie I know the states of the office switch
# off  = Auto turn on/off 
# ********************************************
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: sensor.office_switch
          state: "OFF"
    action:
# Action to turn ON
      - data:
          entity_id: light.office
        service: light.turn_on
#=======================================================================

remeber that time is 00:00:00 format

so my input delay select is

  motion_delay_1:
    options:
      - "01"
      - "02"
      - "03"
      - "04"
      - "05"
      - "06"
      - "07"
      - "08"
      - "09"
      - "10"
      - "15"
      - "20"

Thanks.
And I thought this would be an opportunity to increase my understanding of automations. But, “clear as mud” reminds me of why I did it in Node Red for my garage light. One node was all it took.

But you have provided me with things to think about.

So, if I understand this, if the sensor sees motion within the five minutes, the turn-off automation won’t trigger?

Yes

each time the binary_sensor.office_motion goes "on it turn on the input_boolean.someone_in_room_1 and them 1 sec later it input_boolean.someone_in_room_1 off

now i wait for the Trigger input_boolean.someone_in_room_1 to off for input_boolean.someone_in_room_1 in a time format of “00:00:00”

to make it a bit smarter

I have a condition is the “sensor.office_switch” off which is the switch on the wall

now the action bit

turn the office light off

Correct.

Even I’m lost about what @myle is talking about. It seems overly complicated for a simple ‘turn my lights off after x amount of minutes’ automation. But whatever works for you!

The simplest way is:

automation:
  trigger:
    - platform: state
      entity_id: binary_sensor.kitchen_motion
      from: 'on'
      to: 'off'
      for: '00:05:00'
  action:
    - service: light.turn_off
      data:
        entity_id: light.kitchen

This will turn off the kitchen light, only when there has been no motion detected for 5 mins.