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
- What counts. The sensor walks
binary_sensorentities. A sensor counts when its state ison, its device class is one you picked, and it is not on the exclude list. The default classes aredoor,window,opening, andgarage_door. A contact that isonwhen closed will count backwards. Invert that sensor first. - 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.
- Attributes.
open_entity_ids,open_names, andopen_areasare comma-separated text, in the same order. A sensor with no area is listed asunassigned. Names that contain a comma will look like an extra item. The entity id list does not have that problem. - 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.
- 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 fromunknownorunavailabledoes 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
- Copy
blueprints/template/area_open_doors_windows.yamlintoconfig/blueprints/template/edotdev/. Copy the two files fromblueprints/automation/intoconfig/blueprints/automation/edotdev/. Reload blueprints. - 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_doorif the garage should not count. - Open a door. Developer tools → States should show the count increase, and the three attributes should list that contact.
- 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.
- 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 toon. - 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
offwhen open. Checkdevice_classin 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
unknownorunavailableand then back tonot_home. The blueprint ignores a change that comes from those two states. A tracker that drops tonot_homefromhomewill 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.