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: