Dynamic binary_sensor icon group (best way 2021)

Hello.

I got multiple KNX window binary sensors. They do all have the device_class window. Now I have grouped the sensors to an “all windows” group. I would like to have a button in the lovelace UI that is icon only and shows the current state of the windows via the window-open and window-closed MDI icons.

What is the best way to get that working in 2021 home assistant?

Thank you very much!

Try with a template sensor like this, replacing the group with your own group of course:

template:
  - binary_sensor:
      - name: Windows open
        device_class: window
        state: >
          {{ expand('group.windows_doors_outside')|selectattr('state','eq','on')|list|count > 0}}
1 Like

Works perfectly fine. I fixed the double pipe syntax error but other than that it does its job nicely. Thank you very much.

Glad that it worked. Fixed the double pipe, thanks for spotting.

1 Like

Will this toggle showing either mdi:window-open and mdi:window closed? and possibly turn the window open icon to yellow?

Yes, it does exactly that.

Would it matter if all of my window sensors are named device_class opening in dev tools?
Answer- yea it probably does.

So where would the template code go? The ui editor won’t accept templates. :frowning:

It doesn’t matter what the device class of the individual windows is, as long as all of them are binary sensors, the code works fine and rhe icon behaves accordingly.

I don’t know, I don’t use the UI editor. Just add the code to configuration.yaml.