This is my first blueprint(!) and, having tested it, I created a blueprint of the code on this post: Turn light off after X minutes, no matter how it was turned on
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
Source: Turn off Switch after Time has elapsed.yaml · GitHub
If you have any improvements, please let me know, either in this thread, or as a comment on the github gist
All credit to john2014 for the initial post and sheminasalam for fixing their issues!
Edits:
2022-10-07 Updated link to new gist due to the wrong selector being used (time instead of Duration). Added link to the gist.