Hi, I am trying to count the state attribute of some cover sensors is false.
Below give me the result of “False”, so that is correct.
{{ is_state_attr('cover.garage_104_1_107','current_position','100') }}
The next step below has to be result 1, but the last line of code is not correct.
Does anyone know how to achieve this?
{% set cover = [
is_state_attr('cover.garage_104_1_107','current_position','100'),
is_state_attr('cover.garage_104_1_107','current_position','0'),
] %}
{{ cover | selectattr('state', 'eq', 'False')| list | count }}
Your list contains booleans (not objects anymore).
Also remember that states are always strings, but attributes retain their type.
Try this:
{% set cover = [
is_state_attr('cover.garage_104_1_107', 'current_position', 100),
is_state_attr('cover.garage_104_1_107', 'current_position', 0),
] %}
{{ cover | select('==', False)| list | count }}
An improved version:
{% set cover = [
'cover.garage_104_1_107',
'cover.garage_104_1_107',
] %}
{{ cover | select('is_state_attr', 'current_position', 100) | list | count }}
EDIT: The second version isn’t exactly equivalent to the first. I assumed it was desired to have all positions at 100%.
What are you planning on doing with this?
Thank you Pieter.
This works great.
I have several covers. On a window the “normal” state is open, but a garage door the “normal” state is closed.
Now i can used this to see if there are covers in a not “normal” state.
{% set cover = [
is_state_attr('cover.garage_104_1_107', 'current_position', 0),
is_state_attr('cover.hal_25_1_28', 'current_position', 100),
] %}
{{ cover | select('==', False)| list | count }}
Great!
If you’re happy with my solution you can tag it as such to help others.
I have another idea that I’ll type up later when I can.
More solutions are always welcome 
I thought I could, but just to close the loop: I cannot really further improve on this.