Timer for any/all light switch?

I’m looking at:

But I’m not sure I can do what I’m hoping… Essentially I want to setup an automation that will take any light switch that has been turned on, and after X hours, automatically turn it off if it’s still on. And I was hoping to do this without writing an automation for every light, just one that somehow takes input as both the trigger and action entity_id?

Generically I was hoping for something like:

- alias: "Turn Lights Off"
  initial_state: True
  trigger:
    platform: state
    entity_id: <trigger.template>
    to: 'on'
    for: 02:00:00
  action:
    service: light.turn_off
    entity_id: <trigger.template>

Where <trigger.template> would be whatever device triggered the automation to start… Any thoughts?

Can you put them all in a group and monitor the group?

Edit: Just realized you want track and control each light independently.

      Interested what you find out.
1 Like

So far I’ve been working on implementing this in AppDaemon since it seems way more likely to deal with this. It’s my first venture into AppDaemon, but I have a decent background in Python so it’s not too bad :slight_smile:

I’d still be interested in how this could be done with yaml in automations since I have other use cases I’d be interested in using this on.