Last active
August 18, 2021 12:57
-
-
Save pavax/6afcd0eee7c990c456b99dd52680b4b0 to your computer and use it in GitHub Desktop.
Window aware light control
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: Window aware light control | |
description: > | |
Turn off the active lights when a window is opened. | |
As soon as the window is closed, turn them on again. | |
domain: automation | |
source_url: https://gist.github.com/pavax/6afcd0eee7c990c456b99dd52680b4b0 | |
input: | |
window_sensor_entity: | |
name: Window Sensor Entity | |
description: "Window Sensor" | |
selector: | |
entity: | |
domain: binary_sensor | |
target_light: | |
name: Light | |
description: "The lights to control: ⚠ Note: You must make sure to select entities (green badges). Lights for areas and devices can't be turned on again at the moment" | |
selector: | |
target: | |
entity: | |
domain: light | |
condition_sensor_entity: | |
name: Condition binary sensor (Optional) | |
description: "Optional binary sensor that must evaluate to on to trigger this automation" | |
default: | |
selector: | |
entity: | |
domain: binary_sensor | |
mode: restart | |
variables: | |
window_sensor_entity: !input window_sensor_entity | |
condition_sensor_entity: !input condition_sensor_entity | |
lights: !input target_light | |
active_lights: > | |
{% set entities = lights.entity_id | default('') %} | |
{{ states['light']|selectattr('state','eq','on')|selectattr('entity_id','in',entities)|map(attribute='entity_id')|join(',') }} | |
trigger: | |
- platform: state | |
entity_id: !input window_sensor_entity | |
to: "on" | |
condition: | |
- "{{ condition_sensor_entity == None or is_state(condition_sensor_entity, 'on') }}" | |
action: | |
- service: light.turn_off | |
target: !input target_light | |
- condition: template | |
value_template: "{{active_lights | length > 0}}" | |
- wait_for_trigger: | |
- platform: state | |
entity_id: !input window_sensor_entity | |
to: "off" | |
continue_on_timeout: false | |
timeout: "02:00:00" | |
- condition: template | |
value_template: "{{active_lights|length > 0}}" | |
- service: light.turn_on | |
data: | |
entity_id: "{{active_lights}}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment