Turn off any device in a list after it has been on for a certain amount of time

So I know similar questions are asked frequently. There are a ton of ways to shut off a light or device after a certain number of minutes. I want to create a “catch all” type of automation that is essentially “if any of these devices gets turned on for 15 minutes, shut it off”. My use case is that my kids or my wife leaves their bath fan running indefinitely. I want the to shut off after 15 minutes. I know I can make a separate automation for each bath fan or one automation with a separate trigger and action for each bath fan. I am just wondering if there is a more straight forward way?

something like this?

trigger:
  - platform: state
    entity_id:
      - light.light1
      - light.light2
      - light.light3      
    for:
      minutes: 15
condition: []
action:
  - action: homeassistant.turn_off
    target:
      entity_id: >
        {{ trigger.to_state.entity_id }}

note that i used homeassistant.turn_off so that you can put any entity that supports the generic off. including switches, fans, lights…

1 Like

I will give it a try