From a7d475c1c54b3dfe892d56a6a9bf394e2766fc8b Mon Sep 17 00:00:00 2001 From: John Ogle Date: Wed, 5 Nov 2025 17:21:58 -0800 Subject: [PATCH] Fix trigger syntax for area-based sensor selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces invalid 'target' key in trigger with proper 'entity_id' using variables section to resolve target selector. Simplifies template logic by centralizing sensor resolution. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- occupancy_controlled_lights.yaml | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/occupancy_controlled_lights.yaml b/occupancy_controlled_lights.yaml index c5384f9..15c4d67 100644 --- a/occupancy_controlled_lights.yaml +++ b/occupancy_controlled_lights.yaml @@ -69,9 +69,19 @@ blueprint: 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 - target: !input occupancy_sensors + entity_id: "{{ sensors }}" condition: [] @@ -79,11 +89,7 @@ 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 }} + value_template: "{{ expand(sensors) | selectattr('state', 'eq', 'on') | list | count > 0 }}" sequence: - if: - condition: template @@ -103,20 +109,12 @@ action: 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 }} + value_template: "{{ 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 }} + value_template: "{{ expand(sensors) | selectattr('state', 'eq', 'on') | list | count == 0 }}" - action: light.turn_off target: !input lights data: