group:
  all_windows:
    name: All windows
    entities:
      - binary_sensor.living_room_right_window_contact
      - binary_sensor.bedroom_left_window_contact
      - binary_sensor.bedroom_right_window_contact
      - binary_sensor.kitchen_window_contact

  bedroom_windows:
    name: Bedroom windows
    entities:
      - binary_sensor.bedroom_left_window_contact
      - binary_sensor.bedroom_right_window_contact

sensor:
  - platform: template
    sensors:
      open_window_count:
        friendly_name: Open windozw count
        value_template: >-
          {% set entityStates = states | selectattr('entity_id', 'in', state_attr('group.all_windows', 'entity_id')) %}
          {{ entityStates | selectattr('state', 'eq', 'on') | list | count | int }}

homeassistant:
  customize:
    binary_sensor.living_room_right_window_contact:
      device_class: window
      friendly_name: Living room right window
    binary_sensor.bedroom_left_window_contact:
      device_class: window
      friendly_name: Bedroom left window
    binary_sensor.bedroom_right_window_contact:
      device_class: window
      friendly_name: Bedroom right window
    binary_sensor.kitchen_window_contact:
      device_class: window
      friendly_name: Kitchen window
