Simple Timer to turn off a light, timer stops when the light is switched off manuallly

A simple timer which turns off a light after x amount of time. When the light is turned off, the timer is stopped so if you turn it back on, there is no running timer which could turn it off immediately.
Works with lights and switches.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Code:


blueprint:
  name: Light Timer
  description: Turn off a light after a certain time unless switched off manually
  domain: automation
  input:
    target_light:
      name: Light
      description: The light to turn off
      selector:
        entity:
          domain: 
            - light
            - switch
    light_wait:
      name: Wait time
      description: Time to leave the light on
      selector:
        duration:
      default:
          hours: 0
          minutes: 5
          seconds: 0

trigger:
  platform: state
  entity_id: !input target_light
  from: "off"
  to: "on"
condition: []
action:
  - wait_for_trigger:
      - platform: state
        entity_id: !input target_light
        to: "off"
    timeout: !input light_wait
    continue_on_timeout: true
  - if:
      - condition: state
        entity_id: !input target_light
        state: "off"
    then:
      - stop: ""
    else:
      - alias: "turn off the light"
        service: homeassistant.turn_off
        target: 
          entity_id: !input target_light
mode: single
1 Like