From d03b80a211d9cf5a849f7d4480dd9fae2caa94f8 Mon Sep 17 00:00:00 2001 From: John Ogle Date: Wed, 5 Nov 2025 17:20:11 -0800 Subject: [PATCH] Support area-based motion sensor selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- occupancy_controlled_lights.yaml | 44 ++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/occupancy_controlled_lights.yaml b/occupancy_controlled_lights.yaml index 6add3f5..c5384f9 100644 --- a/occupancy_controlled_lights.yaml +++ b/occupancy_controlled_lights.yaml @@ -1,15 +1,16 @@ blueprint: name: Occupancy Controlled Lights with Adaptive Lighting - description: Automatically turn lights on/off based on occupancy sensor with adaptive lighting support + 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_sensor: - name: Occupancy Sensor - description: Binary sensor that detects occupancy/presence + occupancy_sensors: + name: Occupancy Sensors + description: Occupancy sensors to monitor (can select individual sensors or entire areas) selector: - entity: - domain: binary_sensor - device_class: occupancy + target: + entity: + domain: binary_sensor + device_class: occupancy lights: name: Lights description: Light entities to control @@ -70,16 +71,19 @@ blueprint: trigger: - trigger: state - entity_id: !input occupancy_sensor + target: !input occupancy_sensors condition: [] action: - choose: - conditions: - - condition: state - entity_id: !input occupancy_sensor - state: "on" + - 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 @@ -98,15 +102,21 @@ action: data: transition: !input turn_on_transition - conditions: - - condition: state - entity_id: !input occupancy_sensor - state: "off" + - 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: state - entity_id: !input occupancy_sensor - state: "off" + - 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: