Have a look at Entity Controller from HACS - it will do what you want in half a dozen lines. Here’s mine:
- bathroom_light:
sensor:
- binary_sensor.bathroom_motion_sensor_motion
entities:
- light.bathroom_1
delay: 600
block_timeout: 600
If the motion sensor detects movement, the light comes on for ten minutes. (If movement is detected in that time the period is extended for another ten minutes.) If the light is turned on or off manually it stays in that state for ten minutes, then goes off if there is no movement.
PS… Avoid device triggers if you can…