Files
home-assistant-blueprints/occupancy_controlled_lights.yaml
John Ogle 89d268b3f4 Fix trigger to use domain-based filtering
Replaces template variable in trigger entity_id with domain/device_class trigger and condition filter. This properly handles dynamic sensor selection from target selector.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-05 17:23:24 -08:00

126 lines
3.9 KiB
YAML

blueprint:
name: Occupancy Controlled Lights with Adaptive Lighting
description: Automatically turn lights on/off based on multiple occupancy sensors with adaptive lighting support. Lights turn on when any sensor detects motion and turn off only when all sensors are clear for the configured delay.
domain: automation
input:
occupancy_sensors:
name: Occupancy Sensors
description: Occupancy sensors to monitor (can select individual sensors or entire areas)
selector:
target:
entity:
domain: binary_sensor
device_class: occupancy
lights:
name: Lights
description: Light entities to control
selector:
target:
entity:
domain: light
adaptive_lighting_switch:
name: Adaptive Lighting Switch
description: Adaptive lighting switch entity for this room
default: {}
selector:
entity:
domain: switch
integration: adaptive_lighting
turn_on_transition:
name: Turn On Transition
description: Transition time in seconds when turning lights on
default: 5
selector:
number:
min: 0
max: 300
step: 1
unit_of_measurement: seconds
turn_off_transition:
name: Turn Off Transition
description: Transition time in seconds when turning lights off
default: 15
selector:
number:
min: 0
max: 300
step: 1
unit_of_measurement: seconds
adapt_brightness:
name: Adapt Brightness
description: Whether to adapt brightness when turning on lights
default: true
selector:
boolean:
adapt_color:
name: Adapt Color
description: Whether to adapt color when turning on lights
default: true
selector:
boolean:
off_delay:
name: Off Delay
description: Time to wait after no motion before turning lights off
default: 0
selector:
number:
min: 0
max: 3600
step: 1
unit_of_measurement: seconds
variables:
sensors: >
{% if occupancy_sensors.entity_id is defined %}
{{ occupancy_sensors.entity_id }}
{% elif occupancy_sensors.area_id is defined %}
{{ area_entities(occupancy_sensors.area_id) | select('match', 'binary_sensor.*') | select('device_attr', 'device_class', 'occupancy') | list }}
{% else %}
[]
{% endif %}
trigger:
- trigger: state
domain: binary_sensor
device_class: occupancy
condition:
- condition: template
value_template: "{{ trigger.entity_id in sensors }}"
action:
- choose:
- conditions:
- condition: template
value_template: "{{ expand(sensors) | selectattr('state', 'eq', 'on') | list | count > 0 }}"
sequence:
- if:
- condition: template
value_template: "{{ adaptive_lighting_switch != none }}"
then:
- action: adaptive_lighting.apply
data:
entity_id: !input adaptive_lighting_switch
turn_on_lights: true
transition: !input turn_on_transition
adapt_brightness: !input adapt_brightness
adapt_color: !input adapt_color
else:
- action: light.turn_on
target: !input lights
data:
transition: !input turn_on_transition
- conditions:
- condition: template
value_template: "{{ expand(sensors) | selectattr('state', 'eq', 'on') | list | count == 0 }}"
sequence:
- delay:
seconds: !input off_delay
- condition: template
value_template: "{{ expand(sensors) | selectattr('state', 'eq', 'on') | list | count == 0 }}"
- action: light.turn_off
target: !input lights
data:
transition: !input turn_off_transition
mode: single