Home Assistant

Open doors and windows count by area

A template sensor counts open door and window contacts in the areas you pick, or in the whole home, and lists the open names, areas, and entity ids. Two automations use that count.

Difficulty · BeginnerSetup · 15–30 minutesHA · 2024.10 or newer
Get the pack · from $19Have us set it up

Some hardware links on this page are affiliate links. As an Amazon Associate I earn from qualifying purchases. We may earn a commission if you buy through them, at no extra cost to you. See the affiliate disclosure.

A group of every contact in the house tells you that something is open. It does not tell you how many, which rooms, or which entity. This pack is a template sensor that counts binary sensors currently on, filtered by device class and by area. The state is the count. Three attributes list the open entity ids, the friendly names, and the area names.

Two automations sit on that sensor. One turns a climate entity off after the count has stayed above zero. The other sends the open list when someone leaves.

A notification for a single opening, with a close time, is door and window open notify. Pausing heat and restoring the setpoint when the sash shuts is window-open climate pause. A battery reed you build yourself is battery reed door sensor.

What problem it solves

You want one number for the open doors and windows in a floor, a wing, or the whole home, and a list you can drop into a notification or a climate lockout.

How it works

  1. What counts. The sensor walks binary_sensor entities. A sensor counts when its state is on, its device class is one you picked, and it is not on the exclude list. The default classes are door, window, opening, and garage_door. A contact that is on when closed will count backwards. Invert that sensor first.
  2. Areas. Pick one or more areas, and only sensors in those areas count. Leave areas empty and the whole home counts, including sensors that have no area yet. A sensor with no area is skipped once you have picked at least one area.
  3. Attributes. open_entity_ids, open_names, and open_areas are comma-separated text, in the same order. A sensor with no area is listed as unassigned. Names that contain a comma will look like an extra item. The entity id list does not have that problem.
  4. Climate. The lockout automation turns the climate entity off when the count has been above zero for N minutes (default 5). It does not restore the mode when the count returns to zero. That restore, with a saved setpoint, is the window-open climate pause pack. This one only blocks.
  5. Leaving. The second automation runs when a person, device tracker, zone, or input boolean changes to the away state you set (default not_home). If the count is above zero, the notification includes the names, the areas, and the entity ids. A change from unknown or unavailable does not count as leaving.

The count updates when any binary sensor changes, because the template reads the binary sensor domain.

Snippet

The count, trimmed. The same filter fills the three attributes.

variables:
  areas: !input areas
  device_classes: !input device_classes
  exclude: !input exclude

sensor:
  state: >
    {% set ns = namespace(n=0) %}
    {% for s in states.binary_sensor %}
      {% if s.state == 'on' and s.attributes.device_class in device_classes %}
        {% set ns.n = ns.n + 1 %}
      {% endif %}
    {% endfor %}
    {{ ns.n }}

The area test and the exclude list are in the pack file. They are omitted here so the loop is readable.

Setup outline

  1. Copy blueprints/template/area_open_doors_windows.yaml into config/blueprints/template/edotdev/. Copy the two files from blueprints/automation/ into config/blueprints/automation/edotdev/. Reload blueprints.
  2. Create a template entity from Open doors and windows by area. Name it. Leave areas empty for a first test, or pick the rooms you care about. Leave the device classes, or clear garage_door if the garage should not count.
  3. Open a door. Developer tools → States should show the count increase, and the three attributes should list that contact.
  4. Create an automation from Turn climate off when openings stay open. Pick the count sensor, the climate entity, and the minutes. Open a contact, wait out the minutes, and confirm the climate entity turns off.
  5. Create an automation from List open doors and windows when leaving. Pick the count sensor and the presence entity. For a person, leave the away state at not_home. For an input boolean you turn on when you leave, set the away state to on.
  6. With something still open, change that presence entity to the away state. The notification should name what is open.

Troubleshooting

  • The count stays at zero. The contacts use a device class that is not selected, or they are off when open. Check device_class in Developer tools. Invert a backwards contact. A sensor with no device class never counts.
  • The whole home is empty after you pick an area. Those contacts are not assigned to an area, or they are assigned to a different one. Assign them under Settings → Areas, or clear the area input.
  • A group and its members both count. Exclude the group, or exclude the members. The blueprint does not know which entities are groups.
  • The climate entity turns off once and then stays available to turn back on. The trigger is the count crossing above zero and staying there. It does not repeat while the count remains high. Close everything and open again, or turn the climate off yourself. Restoring heat when the last sash closes is the other pack.
  • Leaving notified while you were already away. The presence entity flipped through unknown or unavailable and then back to not_home. The blueprint ignores a change that comes from those two states. A tracker that drops to not_home from home will still notify, which is what you asked for.
  • The attribute looks like one long string. It is comma-separated text, which a notification can print as-is. Split on , in your own template if you need a list.

Credits

The area filter and the open-list attributes follow Area-based open windows and doors sensor.

Changelog

v1.0 · Nov 1, 2026: First publish.