Files
home-assistant-blueprints/occupancy_controlled_lights.yaml
John Ogle d03b80a211 Support area-based motion sensor selection
Updates occupancy controlled lights to use target selector like lights, allowing selection of entire areas of motion sensors. Lights turn on when any sensor in the selected areas/entities detects motion and turn off when all are clear for the delay period.

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

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

125 lines
4.5 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
trigger:
- trigger: state
target: !input occupancy_sensors
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: >
{% set sensors = occupancy_sensors.entity_id if occupancy_sensors.entity_id is defined
else (area_entities(occupancy_sensors.area_id) | select('match', 'binary_sensor.*') | select('device_attr', 'device_class', 'occupancy') | list) if occupancy_sensors.area_id is defined
else [] %}
{{ 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: >
{% set sensors = occupancy_sensors.entity_id if occupancy_sensors.entity_id is defined
else (area_entities(occupancy_sensors.area_id) | select('match', 'binary_sensor.*') | select('device_attr', 'device_class', 'occupancy') | list) if occupancy_sensors.area_id is defined
else [] %}
{{ expand(sensors) | selectattr('state', 'eq', 'on') | list | count == 0 }}
sequence:
- delay:
seconds: !input off_delay
- condition: template
value_template: >
{% set sensors = occupancy_sensors.entity_id if occupancy_sensors.entity_id is defined
else (area_entities(occupancy_sensors.area_id) | select('match', 'binary_sensor.*') | select('device_attr', 'device_class', 'occupancy') | list) if occupancy_sensors.area_id is defined
else [] %}
{{ expand(sensors) | selectattr('state', 'eq', 'on') | list | count == 0 }}
- action: light.turn_off
target: !input lights
data:
transition: !input turn_off_transition
mode: single