Does my list of binary_sensors have any that are on

I am trying to tell if any of a list of binary_sensors as received from a blueprint !input are on.
I came up with this, but don’t know if it’s the best way.
Anyone have suggestions?

{{ door_open | map('states') | select('eq','on') | list | count > 0 }}

Follow up question, Say my door_open list above has numbers and text as the states.
The numbers I would want to determine on or off as well, where <= 0 is false and > 0 true. But the list is mixed. I would also like to lower case the text as well.

Trying to figure this out but with the mixed list, lower case gt and le tests, I’m a bit lost.

so far:

    {{- door_open | map('states') 
    | select('in', ['true','True','yes','Yes','YES','on','ON','t','T','y','Y'])
    | list | count > 0 -}}

and that is working for the text/bool stuff. Numbers are messing with me as is how to add the lower filter.

I was going to suggest using bool to determine truthy/falsy. However, it doesn’t support negative values or single letters like Y and N.

{% set x = ['ON', 'on', 'On', 'TRUE', 'True', 'true', true,
  'OFF', 'off', 'Off', 'FALSE', 'False', 'false', false] %}

{{ x | map('bool') | list }}

{{ -7 | bool }}

Thanks for the help. I have something that works 90% of my original goal, I think.
I now need people to give it a test and poke holes in it.

Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.

1 Like