Skip to content

Instantly share code, notes, and snippets.

@JonTheNiceGuy
Last active September 9, 2024 07:07
Show Gist options
  • Save JonTheNiceGuy/17fcd695999807a69599249e02ef3f56 to your computer and use it in GitHub Desktop.
Save JonTheNiceGuy/17fcd695999807a69599249e02ef3f56 to your computer and use it in GitHub Desktop.
blueprint:
name: Turn off Switch after Time has elapsed
description: Given a switch entity, watch for it turning on, and then turn it off after a certain period of time.
domain: automation
input:
switch:
name: Switch
description: Select the switch to monitor and control
selector:
entity:
domain: switch
time:
name: Duration
description: The duration to leave the switch on for
selector:
duration:
trigger:
- platform: state
entity_id: !input switch
to: 'on'
for: !input time
condition: []
action:
- service: switch.turn_off
data: {}
entity_id: !input switch
mode: single
@jeremyjhartley
Copy link

So this was super helpful. I was wondering if this can be modified to include multiple lights/switches. My use case is that I have 7 different bath fans. I only want them to run for 15 minutes after they get turned on. My family tends to leave them running indefinitely. I could duplicate the automation 7 times with each entity, but I was wanting to create one automation and just list all 7 devices.

@JonTheNiceGuy
Copy link
Author

Hey @jeremyjhartley I honestly don't know. I'm sorry to say that I just took some code someone else wrote, and tidied it up and made it reusable. I suspect you probably can just add each of the devices, but if not I don't know how you would change this. I personally run several automations, but that's more because I want to see what's happening, rather than anything more sensible!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment