I’m busys creating my own dashboard.
Thats going fine.
I did make a template for counting amount of lights on in a specific room.
This is working fine.
working template:
{%- set ns = namespace(lightsensors=[]) -%}
{%- set ns.lightsensors = states.light
| selectattr('entity_id', 'in', area_entities('Woonkamer'))
| selectattr('state', 'eq', 'on')
| map (attribute='name') | list -%}
{{ ns.lightsensors | count }}
Now i try to create a look a like template for count the amount of doors are open in a specific Area.
Not working template:
{%- set ns = namespace(doorsensors=[]) -%}
{%- set ns.doorsensors = states.door
| selectattr('entity_id', 'in', area_entities('Woonkamer'))
| selectattr('state', 'eq', 'on')
| map (attribute='name') | list -%}
{{ ns.doorsensors | count }}
What is wrong with this template?
Is “states.door” not correct?
Thanks
EDIT:
I did found the solution allready states.door needs to be states.binary sensor
and test on attributes.device_class also
Instead of starting with all binary_sensors in your system (states.binary_sensor), it starts with all entities in Woonkamer (a much smaller number of entities), then selects just the binary_sensors. After that it proceeds similarly to your version, filtering by device_class and state. No for-loop is needed to produce the final count.
currently we can only do this WTH, where are the floor_entities() for more than 1 targeted area, but Petro got his PR merged, so from 2025.4 on we finally will have floor_entities() !