I am trying to display a card that shows the amount of open windows in specific areas. For that I have created the following code (areas currently not being filtered for testing purposes):
{% set open =
states.binary_sensor
| selectattr('attributes.device_class', 'eq', 'opening')
| selectattr('state', 'eq', 'on')
| list |length
%}
{{ open }}
Within the developer tools this works great, resulting in 2
, because 2 windows are currently open.
But when putting this code into a markdown card nothing is displayed. If, however, I remove the line filtering for device_class, then a value is displayed.
However, that value is of course not correct, because it then shows all binary_sensor
s that are on.
Does anybody know what is happening here? I am super confused as it works in dev tools but not in cards…