Fix trigger syntax for area-based sensor selection

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 <noreply@anthropic.com>
This commit is contained in:
2025-11-05 17:21:58 -08:00
parent d03b80a211
commit a7d475c1c5

View File

@@ -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: