Help with my Automation for turning on the light

Hi guy, I just got my smart home set up and started using home assistant. I just made my first automation to turn on the light if door opened and motion is detected and its working well I just wanted it to turn the light off automatically if there is no motion for 5 min would that be possible ?
Ive attached a screenshot of the automation so far

Thank you in advance

Sure. Create another automation that checks for the motion sensor being off for 5 minutes.

Here is an example automation. I have two motion sensors.

alias: Workshop on with Motion
triggers:
  - entity_id: binary_sensor.workshop_motion
    from: "off"
    to: "on"
    trigger: state
  - entity_id: binary_sensor.workshop_radar_occupancy
    from: "off"
    to: "on"
    trigger: state
actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: light.workshop
            state: "off"
        sequence:
          - data:
              entity_id:
                - light.workshop
              brightness_pct: 100
            action: light.turn_on
  - wait_template: >
      {{ is_state('binary_sensor.workshop_radar_occupancy', 'off') and
      is_state('binary_sensor.workshop_motion', 'off') }}
  - data:
      entity_id:
        - light.workshop
    action: light.turn_off
initial_state: true
mode: restart
max_exceeded: silent

Here how it works.

The automation has two triggers. One for each motion / presence sensor

The action has a choose condition on the light being off and if so, turns the light on

Then it goes to waiting for trigger where it waits till both sensors are off.

Then turns light off.

While light is on, the automation will retrigger and just wait again

Here is another for an entrance where I just turn light on even if already on

alias: Entrance on with Motion
triggers:
  - entity_id: binary_sensor.entrance_motion
    from: "off"
    to: "on"
    trigger: state
conditions:
  - condition: numeric_state
    entity_id: sensor.entrance_luminance
    below: 10
actions:
  - target:
      entity_id: light.entrance_ceiling
    action: light.turn_on
    data: {}
  - wait_for_trigger:
      entity_id: binary_sensor.entrance_motion
      from: "on"
      to: "off"
      trigger: state
  - delay: 60
  - target:
      entity_id: light.entrance_ceiling
    action: light.turn_off
    data: {}
initial_state: true
mode: restart
max_exceeded: silent

And finally an advanced one with lots of conditions

alias: Kitchen On With Any Motion
triggers:
  - entity_id: binary_sensor.kitchen_motion
    from: "off"
    to: "on"
    trigger: state
  - entity_id: binary_sensor.kitchen_radar
    from: "off"
    to: "on"
    trigger: state
actions:
  - choose:
      - conditions:
          - condition: time
            after: "00:00:00"
            before: "06:00:00"
          - condition: state
            entity_id: light.kitchen_table
            state: "off"
        sequence:
          - data:
              entity_id: light.kitchen_table
              brightness: 30
            action: light.turn_on
      - conditions:
          - condition: time
            after: "06:00:00"
            before: "00:00:00"
          - condition: state
            entity_id: light.sink_up
            state: "off"
        sequence:
          - if:
              - condition: numeric_state
                entity_id: sensor.backyard_luminance_hue
                above: 300
            then:
              - if:
                  - condition: numeric_state
                    entity_id: light.kitchen_table
                    value_template: |
                      {% if states.light.kitchen_table.state == "on" %}
                        {{ states.light.kitchen_table.attributes.brightness }}
                      {% else %}
                        0
                      {% endif %}
                    below: 125
                then:
                  - data:
                      entity_id: light.kitchen_table
                      brightness: 255
                    action: light.turn_on
            else:
              - if:
                  - condition: state
                    entity_id: light.sink_up
                    state: "off"
                then:
                  - entity_id: scene.kitchen_normal
                    action: scene.turn_on
  - wait_template: |
      {{ is_state('binary_sensor.kitchen_motion', 'off')
         and is_state('binary_sensor.kitchen_occupancy', 'off')
         and is_state('binary_sensor.kitchen_radar', 'off') }}
  - delay: 60
  - if:
      - condition: template
        value_template: |
          {{ (states('sensor.backyard_luminance_hue')|int) > 50 or
             today_at("00:00") < now() < today_at("06:00") or
             ( is_state('binary_sensor.bed_sensor_kenneth', 'on') and
               is_state('binary_sensor.bed_sensor_diane', 'on') )
          }} 
    then:
      - target:
          entity_id:
            - light.kitchen
        action: light.turn_off
        data: {}
    else:
      - data:
          entity_id:
            - light.sink_up
            - light.sink_down
        action: light.turn_off
      - condition: state
        entity_id: light.kitchen_table
        state: "on"
      - data:
          entity_id: light.kitchen_table
          brightness: 120
        action: light.turn_on
initial_state: true
mode: restart
max_exceeded: silent

The kitchen has 3 sensors. 1 can trigger on when I do not want it. All 3 must be off before light turns off.
I have time conditions. I have illuminance conditions. E.g. in the evening the table light remains on to avoid dark house sensation. But at night it turns kitchen completely off.

Lots to play with

Creating grouped sensors via Helper may simplify your scenarios.

Thank you all for your helpful comments, I will try and see If I can do them :+1:t3:

The benefit of grouping sensors is ALL sensors in that group must meet the trigger condition before executing.

For example, I have 3 Hue sensors in my bathroom (lot’s of blind spots). All occupancy sensors need to be clear before the lights turn off via an automation.