Area-Based Open Windows and Doors Sensor

This blueprint will help you create a sensor that returns the count of open windows based on selected Areas. The entity IDs and Areas where there are open windows are available as attributes.

Features:

  • Can track both windows and/or doors.
  • Multiple Areas can be used. If no Area is provided, the sensor will cover all Areas.
  • Specific windows and/or doors can be excluded.



Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Open Doors or Windows
  description: |
    The sensor's state returns a count of the number of open Doors and/or Windows. 
    Lists of their Entity ID's and the Areas with open windows are provided as attributes.
  domain: template
  author: Didgeridrew
  homeassistant:
    min_version: 2025.6.0
  input:
    inc_areas:
      name: Included Areas
      description: If used, only windows or doors in the selected Areas will be included.
      default: []
      selector:
        area:
          multiple: true
    door:
      name: Track Doors
      description: Select whether doors should be included in this sensor. 
      default: false
      selector:
        boolean:
    window:
      name: Track Windows
      description: Select whether windows should be included in this sensor. 
      default: true
      selector:
        boolean:
    excluded_doors:
      name: Excluded Doors
      description: Any door entities selected will be excluded from the sensor's calculations.
      default: []
      selector:
        entity:
          multiple: true
          filter:
            - device_class: door
    excluded_windows:
      name: Excluded Windows
      description: Any window entities selected will be excluded from the sensor's calculations.
      default: []
      selector:
        entity:
          multiple: true
          filter:
            - device_class: window
variables:
  door: !input door
  ex_doors: !input excluded_doors
  window: !input window
  ex_windows: !input excluded_windows
  in_areas: !input inc_areas
  area_ents: |
    {% set in_areas = areas() if in_areas == [] else in_areas %}
    {{in_areas|map('area_entities')|flatten|select('match', 'binary_sensor.')|list}}
  ex_d: "{{[ex_doors] if ex_doors is string else ex_doors|default([],1)}}"
  ex_w: "{{[ex_windows] if ex_windows is string else ex_windows|default([],1)}}"
  area_doors: |
    {{[] if not door else area_ents|select('is_state_attr','device_class', 'door')|list}}
  area_windows: |
    {{[] if not window else area_ents|select('is_state_attr','device_class', 'window')|list}}
sensor:
  state: "{{ this.attributes.open|count|default(0,1) }}"
  attributes:
    open: |
      {% set exclusions = union(ex_w,ex_d) %}
      {{ expand(union(area_windows, area_doors)|reject('in', exclusions))
      |rejectattr('attributes.entity_id', 'defined')
      |map(attribute='entity_id')|select('is_state','on')
      |list }}  
    open_areas: "{{ this.attributes.open | map('area_name')|reject('eq', none) | unique | list }}"
  availability: "{{ true }}"
1 Like

Template Blueprints are currently (2025.06) only available through YAML configuration. You can find more details about how to use them at:

HA Docs - Templates - Using Blueprints

Once you have installed the blueprint, use the following examples to help set up your own sensors in your configuration files.


Configuration Examples:

#Generic Configuration
template:
  - name: Blueprint Open Windows
    unique_id: bp_window_count_000001
    use_blueprint:
      path: Didgeridrew/area-based-open-windows-and-doors-sensor.yaml
      input:
        inc_areas: []
        door: false
        excluded_doors: []
        window: true
        excluded_windows: []
All Windows (Default)
template:
  - name: Blueprint All Windows
    unique_id: bp_all_window_count_0001
    use_blueprint:
      path: Didgeridrew/area-based-open-windows-and-doors-sensor.yaml
All Windows and Doors
template:
  - name: Blueprint All Windows and Doors
    unique_id: bp_all_window_door_count_0001
    use_blueprint:
      path: Didgeridrew/area-based-open-windows-and-doors-sensor.yaml
      input:
        doors: true
Single Area Windows
template:
  - name: Blueprint Living Room Windows
    unique_id: bp_lr_window_count_0001
    use_blueprint:
      path: Didgeridrew/area-based-open-windows-and-doors-sensor.yaml
      input:
        inc_areas:
          - "Living Room"
Multiple Area Windows and Doors with Excluded Doors
template:
  - name: Blueprint LR and Kitchen Windows and Doors 
    unique_id: bp_lr_window_count_0001
    use_blueprint:
      path: Didgeridrew/area-based-open-windows-and-doors-sensor.yaml
      input:
        inc_areas:
          - "Living Room"
          - "Kitchen"
        door: true
        excluded_doors:
          - binary_sensor.half_bathroom_door
          - binary_sensor.kitchen_pantry_door



  • This Post has been set to Wiki Mode. Please feel free edit this post to add configuration examples if you think they are needed