I’m embarrassed to ask this, but I can’t get this to work. I have a timer timer.office_lights and I want the lights to turn off when the timer finishes. When the lights go on the timer starts, but when the timer finishes nothing happens.
The problem with this use is people.
If they turn on the light in the toilet (for example) the timer is expected to turn the light off after (say) 15m. OK fine.
But I go in and turn the light off when I leave after 6 mins, you then come in 6 mins later and turn the light on.
The timer is already running and you only get 3mins before it all goes dark.
Instead, use a script and a delay.
The automation runs when the light turns on.
It Cancels the script (even if not running) and then starts the script
The script runs the delay (I usually set the delay via an input_number) and then it turns the light out.
I don’t have access to my examples right now but I’ll post a sample when I get back (about an hour)
Edit: be aware if you restart (mid timer OR delay ) - you will lose the turn off
This is from one of my packages so you ‘may’ have to adjust indentation to align with your configuration.
Entities shown are sample entities, edit to suit your system and entities.
Timer is in minute units, but you could do the same with hours or seconds.
Note: I have (and do) set minute timers to values of 720 (not had a problem yet)
The input number (without initial set) will retain your last set value accross restarts
input_number:
## delay off timer value
in_light_sample_timer:
name: Sample Light On Timer (mins)
#initial: 2
min: 1
max: 900
step: 1
mode: box
icon: mdi:alarm
automation:
##name: Light Sample Off Delay
- alias: au_light_sample_offdelay
trigger:
- platform: state
entity_id: light.sample
from: 'off'
to: 'on'
action:
- service: script.turn_off
entity_id: script.sc_light_sample_timer
- service: script.sc_light_sample_timer
## name: Switch Sample Off Cancels Timer
- alias: au_switch_kitchenf_offcancelstimer
trigger:
- platform: state
entity_id: light.sample
to: 'off'
action:
- service: script.turn_off
entity_id: script.sc_light_sample_timer
script:
## light off timer
sc_light_sample_timer:
alias: Light Sample Timer Script
sequence:
- delay: "00:{{ states('input_number.in_light_sample_timer') | int }}:00"
- service: light.turn_off
entity_id: light.sample
I can’t use that as my lights have the brightness changed according to time of day and whenever the adjustment happens I lose the timer (or it restarts - same difference)
It’s good you solved it but you have also marked your own post (with nothing relevant in it) as the solution.
Given where you started and where you ended up, I assume you meant to give the solution to Marc’s first post ???
if no motion in 5 mins, then finished timer turns off lights. If there’s been motion, then waits for 5 mins of no motion
I could have added a condition for if the timer is running, don’t turn off lights but my thinking is if no-ones there then it’s ok to turn off the lights. In the future if I have some toilet/bathroom lights I might do this.