Turn off light after time

How can I turn off a light after a period of time in an automation?

I have a basic automation to turn on the back porch light when the back door is opened but it’s mainly for when letting the dog out so I want it to turn off after about 5-10 minutes.I’m going to add something to only turn the light on when it’s dark as well.

  • alias: ‘BackPorch Light Door Trigger’
    trigger:
    platform: state
    entity_id: binary_sensor.neo_coolcam_doorwindow_detector_sensor_2
    to: ‘on’
    action:
    service: switch.turn_on
    entity_id: switch.back_porch_light

Take a look at the examples. I think this is exacly what you’re looking for.

you da besttttt… now how can i make this not happen if im actually outside without a motion sensor lol

Basically what I did is created an input_boolean and use it as a condition to turn the light off such that, if I turn it on, it won’t turn the light off after your set time. It will just keep the light on forever until the input boolean is switched back off manually.

I was thinking about this for most of my lights that have automations. It would be nice if we had an attribute that by default showed if it were manually turned on or home assistant did it. I don’t want input booleans for every light i set up. I’d create an automation to set the boolean back after the light was turned off manually or automation