How can i set an automation to turn off a light after it has been on for 15 minuts

My kids are notorious about leaving the laundry light on. I want to set an automation that will turn the light off after it has been turned on for 15 minutes. They are controled by Smart wifi switched that are connected to HA with Tuya set at 30 second polling. This is the settings so far.


is there something im missing

Not sure if you’re missing anything, but I had a heck of a time getting mine to work like this for a closet light. No matter what I changed in the UI, it would always turn off on the 15 minute mark of the hour (1:00, 1:15, 1:30, 1:45, 2:00 etc.) But not “After 15 minutes elapsed time”

I may have gave up - don’t remember, will check it out at home.

hope someone was able to get this to work

I don’t use the UI but from the yaml file. This works for me. Change the entity_id and minutes to suite your needs.

- alias: 'turn off light after timeout'
  trigger:
    - platform: state
      entity_id:
       - light.storage_room
       - light.closet
      to: 'on'
      for:
        minutes: 6
    - platform: state
      entity_id:
       - light.h_1
      to: 'on'
      for:
        minutes: 10

  action:
    - service: light.turn_off
      data_template:
        entity_id: "{{ trigger.entity_id }}"

## Lights office ON / OFF

- alias: sensor.office_pir turn_on desktop_light if Night
  trigger:
    platform: state
    entity_id: sensor.office_pir
    to: 'ON'
  condition:
    condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
    service: homeassistant.turn_on
    entity_id: switch.desktop_pc_light

- alias: sensor.office_pir turn_off desktop_light no_motion_detected 5min
  trigger:
    platform: state
    entity_id: sensor.office_pir
    to: 'OFF'
    for:
      minutes: 5
  action:
    service: homeassistant.turn_off
    entity_id: switch.desktop_pc_light

1 Like

You need to add an action, choose delay, 00:15:00
Then select device and choose ‘off’

1 Like

You can do it as @duceduc suggested above or if you want to use the UI you should probably use a state trigger instead of a device trigger and then set the ‘for’ option to ‘00:15:00’.

I don’t use the UI editor so I’m not really sure what “duration” means for a device trigger. It seems like it should mean what you want but if it’s not working then it’s either a bug or not intuitive and means something else.

either way a state trigger will work fine.

I fiddled with the settings a bit and if I turn it on with HA it works as it should. But if I turn on the switch manually HA doesn’t recognize that its on for quite a while. I think the polling with Tuya just takes longer than the setting even though I set it for every 30 seconds it can take up to 5 minutes for it to be recognized.

1 Like

Did you managed to resolve it? @miguelromao 's approach works at my place, but only when lights are being turned on by pir sensor. When I turn them on manually with light switch, they remain turned on.