Generic light timer

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.

Actually it’s better to set the for option to 30 minutes than delaying the message.

1 Like

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.