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.
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