Last active
August 18, 2021 13:18
-
-
Save pavax/4eb086412c1e455a26da4dc64673b3b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Turn off entity after a while | |
description: > | |
Turn off entity after a period of time | |
domain: automation | |
source_url: "https://gist.github.com/pavax/4eb086412c1e455a26da4dc64673b3b9" | |
input: | |
target_entity: | |
name: target_entity | |
description: "The entity to turn off after a while." | |
selector: | |
entity: | |
target_state: | |
name: target_state | |
description: "The state of the entity to turn off" | |
default: "on" | |
selector: | |
text: | |
wait_time: | |
name: Wait time | |
description: "Time to wait until the entity should be turned off." | |
default: 5 | |
selector: | |
number: | |
min: 1 | |
max: 1440 | |
unit_of_measurement: minutes | |
mode: restart | |
max_exceeded: silent | |
variables: | |
target_entity: !input target_entity | |
target_state: !input target_state | |
wait_time: !input wait_time | |
trigger_time: > | |
{% set on_time = as_timestamp(now()) - as_timestamp(states[target_entity].last_changed) %} | |
{% set remain_time = (wait_time * 60) - on_time %} | |
{% set trigger_time = ( now().timestamp() + remain_time ) | timestamp_custom("%H:%M") %} | |
{{ trigger_time}} | |
trigger: | |
- platform: state | |
entity_id: !input target_entity | |
- platform: homeassistant | |
event: start | |
- platform: event | |
event_type: automation_reloaded | |
condition: [] | |
action: | |
- choose: | |
- conditions: | |
- condition: template | |
value_template: "{{ is_state(target_entity, target_state) }}" | |
sequence: | |
- wait_for_trigger: | |
- platform: template | |
value_template: "{{ states('sensor.time') == trigger_time }}" | |
- service: homeassistant.turn_off | |
data: {} | |
entity_id: !input target_entity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment