I believe it happened to everyone at least once – you leave your apartment and forget to close a window. It happened to me once when going on a trip and I was looking for a solution to notify me if any window is still open when no one is at home.
I use the following hardware:
- Raspberry Pi running Home Assistant
- ConBee II from Dresden Elektronik as Zigbee Gateway
- Door and window sensors from Aqara. They use ZigBee to communicate.
- UniFi Wifi Lite 6 as the access point
Setup
The blog post is divided into four steps:
Door and window sensors
The sensors are connected via ZigBee and are battery-powered. They suppose to last a few years before I have to replace the batteries.

The ConBee II shows up as an integration in Home Assistant. To add new devices you don’t need any additional plugins. Click on “Configure > Add Device” and put the device in pairing mode. It will show up and you can name it.


Device tracker
Next, the device tracker is configured. If no known device is connected I assume nobody is home. Settings are stored in the configuration.yaml file.
device_tracker:
- platform: unifi_direct
host: ip_address_access_point
username: username_access_point
password: password_access_point
new_device_defaults:
track_new_devices: true
Once the device tracker is configured you assign users their device with the corresponding MAC address. This makes it easier to be included in any automation. Click on “Settings > People” and choose a person. In the menu set the field track device. Now the device is assigned to the user.
AWS setup
The only solution to reach everyone reliably for me seems to be via SMS. So I decided to use Amazon SNS to send out notifications. First, you need an account if don’t have one yet. Second, add the phone number you want to contact. Last, create a topic and add the phone numbers.
As a final step configure the AWS integration in the configuration.yaml file. Choose the region of your choice.
aws:
credentials:
- name: project_account
aws_access_key_id: your_access_key
aws_secret_access_key: your_secret_key
notify:
- service: sns
region_name: eu-central-1
name: sns_eu_central_1
Now everything is set up and ready to be used in a home assistant automation.
Automation configuration
The automation is triggered as soon as the device tracker detects a device leaving the network and if a window opens if no one is home. As soon as this happens home assistant checks two things – 1) is no one else still connected and 2) is any window open. If both are true the notification is sent to AWS and as a result to all phones set as recipients.
During the first few nights, we received many notifications because our phones kept disconnecting while sleeping. So I added a timer to only trigger the notifications when a device disconnects if it’s between 6 am and 11 pm.
Here is a simplified configuration I use:
alias: notify everybody if everybody left
and window open(s) - day
description: ""
trigger:
- platform: state
entity_id:
- person.person1
- person.person2
from: home
- type: opened
platform: device
device_id: device_id
entity_id: entity_id
domain: binary_sensor
[ + other sensors]
condition:
- condition: or
conditions:
- type: is_open
condition: device
device_id: device_id
entity_id: entity_id
domain: binary_sensor
[ + other sensors]
- condition: not
conditions:
- condition: state
entity_id: person.person1
state: home
- condition: state
entity_id: person.person2
state: home
- condition: time
before: "23:00:00"
after: "06:00:00"
action:
- service: notify.sns_eu_central_1
data:
message: >-
[WARNING] nobody home and window open
target: arn_sns_topic
mode: single
Conclusion
This setup works great for us. It saved us from leaving the apartment while a window is still open a couple of times. I use the device tracker for two additional automations:
- turn off my led clock
- turn off all running Chromecast audios via media player integration when no one is home. Here is an example action configuration.
action:
- service: media_player.turn_off
data: {}
target:
device_id:
- device_id1
- device_id2
In the future, I plan to install a LED on the way leaving the apartment so you know right away if any window is still open. So far my plan is to use ESPHome to trigger a LED in combination with another automation script.