Skip to content

Instantly share code, notes, and snippets.

@pavax
Last active June 21, 2021 18:45
Show Gist options
  • Save pavax/b0a8c373afe3aa060135e7b4a03316d9 to your computer and use it in GitHub Desktop.
Save pavax/b0a8c373afe3aa060135e7b4a03316d9 to your computer and use it in GitHub Desktop.
window_aware_lights_control.yaml
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/TBD
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 entites (green badges). Lights for areas and badges 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: "04: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