The problem is the motion sensor and the shutdown delay via the slider

Tell me how to make the code. If there was no movement after a while (adjusted by the slider), the light turned off. Do not use Delay, as the automation does not work correctly with it. Thank you.

Hi there. Welcome. This should work, if you replace the motion sensor, input_number and light entity with yours.

trigger:
  - platform: state
    entity_id: binary_sensor.your_motion_sensor_here # change this
    to: 'on'
  - platform: state
    entity_id: binary_sensor.your_motion_sensor_here # change this
    to: 'off'
    for:
      minutes: "{{ states('input_number.motion_delay') | int(0) }}"
action:
  - service: "light.turn_{{ trigger.to_state.state }}"
    target:
      entity_id: light.your_light_here # change this
mode: single