SOLVED: Template sensor for open doors / windows in a group. Getting a “KeyError:” in Developer Tools

Can’t work out how I’ve got this wrong, which I clearly have.

There’s a group called doors_windows, and I’m trying to create a sensor which tells me how many are open. Getting a “KeyError:” in the Developer Tools.

# Doors and Windows Open

- platform: template
  sensors:
    door_count:
      value_template: >
        {{ states.group.doors_windows|selectattr('state','equalto','open')|list|length }}  

Any help much appreciated! Thanks!

Try this:

"{{ expand('group.doors_windows')|selectattr('state','eq','on')|list|count }}"

Most probably your sensors i this group ahow on/off and not open/close, open/clowe is only shown in the frontend. You can get the correct state under Developer Tools -> States.

Ach. Of course… Expand!

Thank you - that does indeed work beautifully.