How in automation make an action to stop after specify time

Hi gues. I’m new to homeassistant and this is my first post.
I need your helps.

I’ m trying to do an automation from the UI following the path: configuration --> create and edit automations.

The automation I want to do is this:

When a motion detector is activated, turn_on a light switch for 5 minutes and after this time the light turn_off .

I have made the following automation and it works but without the possibility to turn off the light switch after 5 minutes.

- id: '1595890583920'
  alias: Light kitchen from sensor
  description: ''
  trigger:
  - entity_id: binary_sensor.sensor_kitchen_g_152
    platform: state
    to: 'on'
  condition: []
  action:
  - device_id: b8cbd34b2c044a85bd5c0defc052111c
    domain: switch
    entity_id: switch.shelly_shsw_1_111d39
    type: turn_on
  mode: single
  max: 10

How can I “Turn off” the entity_id: switch.shelly_shsw_1_111d39, after 5 minutes?

Thanks in advance for your help.

SOLVED.

with action “DELAY”

- id: '1595890583920'
  alias: Lihgt kitchen from sensor
  description: ''
  trigger:
  - entity_id: binary_sensor.sensor_kitchen_g_152
    platform: state
    to: 'on'
  condition: []
  action:
  - device_id: b8cbd34b2c044a85bd5c0defc052111c
    domain: switch
    entity_id: switch.shelly_shsw_1_111d39
    type: turn_on
  - delay: 00:050:00
  - device_id: b8cbd34b2c044a85bd5c0defc052111c
    domain: switch
    entity_id: switch.shelly_shsw_1_111d39
    type: turn_off
  mode: queued
  max: 10

(It was my first script automation. :smiley:)

mode: should be reset? Also, typo in your delay time i think

mode “single” also works well.
what you mean ‘typo delay time’.?

Should just be 00:05:00?

Also, i haven’t tried it out but the doc makes it sound like it would turn off lights after 5 minutes even if new motion was detected

I fixed a couple bugs:

- id: 'auto_motion_light'
  alias: 'Automatic motion-activated light'
  description: 'Keep light on for 5 minutes after motion detected'
  trigger:
  - entity_id: binary_sensor.sensor_kitchen_g_152
    platform: state
    to: 'on'
  condition: []
  action:
  - device_id: b8cbd34b2c044a85bd5c0defc052111c
    domain: switch
    entity_id: switch.shelly_shsw_1_111d39
    type: turn_on
  - delay: 00:05:00
  - device_id: b8cbd34b2c044a85bd5c0defc052111c
    domain: switch
    entity_id: switch.shelly_shsw_1_111d39
    type: turn_off
  mode: restart