Namespace openen window sensor template

Hi,

I have this template sensor to show me what doors are opened, and I need a similar one for windows and lights. I don’t have any coding skills so it’s hard for me to make the template from scratch so I tried to replace “door” with “window” but it doesn’t work… I doesn’t even show as a sensor entity.

    - name: "What doors are opened"
      unique_id: xxxxxxxxxxxx
      icon: mdi:door-open
      state: >
        {%- set ns = namespace(doorsensors=[]) -%}
        {%- set ns.doorsensors = states.binary_sensor 
                  | selectattr('attributes.device_class', 'defined') 
                  | selectattr('attributes.device_class', '==', 'door')
                  | selectattr('state', 'eq', 'on') 
                  | map(attribute='name') | list -%}
        {%- if (ns.doorsensors | count > 0) -%}
          {{ ns.doorsensors | list | join('\n')}}
        {%- else -%}
          none
        {%- endif %}

what domain are your windows? are they binary_sensors or covers?

binary_sensors just like my door sensors. Same devices.

Are they window device classes?

Yes, they are.

Then simply replacing 'door' with 'window' will work in that template.

It’s working now, after the second restart. Thanks.

Other device_classes work the same? Or just doors and windows?

any device_class that’s available for binary_sensors will work with that template.

Great! Thanks. Just made a new one for battery state off battery powered devices and works.