Can I make a generic timer for each light?
I want to have an automation, for each light that is turned on to turn it off in 30 minutes.
Does it have to survive a restart?
Not necessarily. What I’m looking for is something that I don’t write for each specific light. Write it once, work for all.
Surprisingly I can’t find a good way to do it in HA.
You can use the state change event, but that will completely flood the automation.
Not sure if that is an issue or not, but I would not do it.
My first idea was to some how trigger on entity_id light.*
to on
but that doesn’t seem to be possible.
You can do it quite easy in Node red like this:
This should trigger on all lights turning on, then it’s just a matter of delaying and then using the msg.topic (that is entity_id) in a call service to turn it off.
EDIT :
Actually it’s better to set the for option to 30 minutes than delaying the message.
Not saying it’s the best way, but you could make an automation that triggers every minute and turns off any lights on for longer than 30 min.
I solved it a bit different. Made an automation that has a bunch of lights which are on for x time, than do
target:
entity_id: "{{ trigger.entity_id }}"
action: homeassistant.turn_off
Here is the whole YAML.
alias: Timers - voor alle lichten en schakelaars
description: Schakel geselecteerde lampen en schakelaars uit na een bepaalde tijd
triggers:
- entity_id:
- light.wc_beneden
- light.warme_kamer
- light.koude_kamer
to: "on"
for:
hours: 0
minutes: 20
seconds: 0
trigger: state
- entity_id:
- light.studie
- light.shellydimmer_f36355
to: "on"
for:
hours: 3
minutes: 0
seconds: 0
trigger: state
- entity_id:
- light.bureaulamp
- light.trap_boven
to: "on"
for:
hours: 3
trigger: state
- entity_id:
- light.konijn
- light.paddenstoel
- light.dierenlamp
- light.badkamer
- light.douche
to: "on"
for:
hours: 1
minutes: 30
seconds: 0
trigger: state
- entity_id:
- light.garage_lichten
to: "on"
for:
hours: 1
minutes: 0
seconds: 0
enabled: false
trigger: state
- entity_id:
- light.trap_beneden
to: "on"
for:
hours: 0
minutes: 45
seconds: 0
trigger: state
- alias: >-
HiFi amplifier staat aan voor langer dan x tijd (want lijkt niet altijd
getriggerd te worden)
type: turned_on
device_id: 6896bacd257eede2b5c5b583ee387695
entity_id: baae55469258cfd03af2402516e0d494
domain: switch
for:
hours: 6
minutes: 0
seconds: 0
trigger: device
conditions: []
actions:
- target:
entity_id: "{{ trigger.entity_id }}"
action: homeassistant.turn_off
mode: restart