Hello all,
I’m trying to create a template sensor that counts all light entities (state: on) that are in the same area as the template sensor itself. Somehow I cannot access the area of the template sensor - can someone point me in the right direction? This is what I have at the moment:
{% set target_entities = area_entities(area_name(this.entity_id)) %}
{{ (states.light |
selectattr('state', 'eq', 'on') |
rejectattr('entity_id', 'in', label_entities('Group')) |
rejectattr('entity_id', 'in', label_entities('Helper')) |
selectattr('entity_id', 'in',
target_entities) | list | length) | int(0) }}
Specifically, it seems that this.entity_id
is not working correctly.
Hope someone knows what I’m missing here
Edit:
The following works correctly but doesn’t use the area
of the template sensor since it’s hardcoded:
{% set area = 'Keuken' %}
{% set target_entities = area_entities(area) %}
{{ (states.light |
selectattr('state', 'eq', 'on') |
rejectattr('entity_id', 'in', label_entities('Group')) |
rejectattr('entity_id', 'in', label_entities('Helper')) |
selectattr('entity_id', 'in',
target_entities) | list | length) | int(0) }}