How to write a single Automation to turn off any fan that is on for over 8 hours?

Hi,

Is there a way to write a single automation to turn off any fan that has been running for over 8 hours.
I have fan’s all over the house but my kids refuse to turn them off.
I can write 11 separate automations but would love to simplify this in 1 automation.

Thank you!

Just list he 11 fans in the trigger.

triggers:
  - trigger: state
    entity_id:
      - fan.one
      - fan.two
      - fan.three
# ...
      - fan.eleven
    to: 'on'
    for:
      hours: 8
actions:
  - action: fan.turn_off
    target:
      entity_id: "{{ trigger.to_state.entity_id }}"

Thank you so much for the quick responds.

I’m able to get all Fan’s in a trigger but how do I stop the Fan that was running for 8 hours without stopping any other Fan’s?

The automation does not accept:

target:
entity_id: “{{ trigger.to_state.entity_id }}”

I believe you want trigger.entity_id

Thanks Jorggs.

If I use:

action: fan.turn_off
metadata: {}
data: {}
target:
entity_id: trigger.entity_id

The Fan does not stop after the configured time.

Please post your yaml in a code block </>.

Joggers was just meaning the inner part. So the correct should be

...
entity_id: "{{ trigger.entity_id }}"
1 Like

It works. Thank you both so much!
p.s. I will do my best to post code properly in the future.

1 Like

Glad you got it working, thank you @Hellis81 for clarifying my poor reply :joy: :pray: