---
title: "An alarm that tells you why it won't arm: an open window or door stops it"
description: "A script in Home Assistant checks all the door and window sensors before arming. If something is open or has lost connection, the alarm stays off and you get a message saying what is stopping it."
canonical: "https://realhomeautomations.com/en/projects/alarm-explains-why-it-wont-arm/"
language: en-US
updated: 2026-11-23T16:24:03+00:00
---

# An alarm that tells you why it won't arm: an open window or door stops it

A script in Home Assistant checks all the door and window sensors before arming. If something is open or has lost connection, the alarm stays off and you get a message saying what is stopping it.

> Canonical HTML page: https://realhomeautomations.com/en/projects/alarm-explains-why-it-wont-arm/

- **Difficulty:** Beginner
- **Build time:** 30–45 minutes
- **Reading time:** 3 minutes

## Tools required

- Home Assistant
- Door or window sensor (Sonoff SNZB-04PR1, one per door or window)
- Alarm panel (alarm_control_panel in Home Assistant)
- Zigbee hub or adapter (or Home Assistant with a Zigbee adapter; not included in the product)
- Phone with the Home Assistant app (with notifications allowed)


## What readers will learn

- Check all doors and windows with a script
- Get the names of the open ones
- Count a sensor with no connection as a problem


## Skill requirements

- Edit a script in YAML in Home Assistant
- Add a Button card to the dashboard

## Project kit

- [Smart Door and Window Sensor Sonoff SNZB-04PR1 – Zigbee 3.0 Protocol, CR2477 Battery Powered, Real-Time Opening Alerts, eWeLink &#038; Home Assistant](https://realhomeautomations.com/en/product/smart-door-and-window-sensor-sonoff-snzb-04pr1-zigbee-3-0-protocol-cr2477-battery-powered-real-time-opening-alerts-ewelink-home-assistant/index.md)

You press "arm" and leave, and in the evening you find out the bedroom window was open. Here is a script that checks all the doors and windows before arming and tells you what is stopping it.

 ## What you will get

 A button "Arm if everything is closed". If all the sensors are closed, the alarm arms. If any is open or doesn't respond, the alarm stays off and you get a message with the names of the problem doors and windows.

 The project complements the alarm from [the alarm project in Home Assistant](https://realhomeautomations.com/bg/projects/home-assistant-kato-ohranitelna-alarma-vaorazhavane-zabavyane-na-vhoda-i-izvestie-pri-srabotvane/). It also works with any other `alarm_control_panel`.

 ## What we need

- [Door sensor Sonoff SNZB-04PR1](https://realhomeautomations.com/bg/produkt/smart-door-and-window-sensor-sonoff-snzb-04pr1-zigbee-3-0-protocol-cr2477-battery-powered-real-time-opening-alerts-ewelink-home-assistant/): one for each door or window you want to check. How many depends on your home.
- Home Assistant, an alarm panel (`alarm_control_panel`) and a phone with the app.

 You need a Zigbee hub or Home Assistant with a Zigbee adapter.

- **Setup time:** about 30–45 minutes.
- **Skills:** you edit a script in YAML and add a card to the dashboard.
- **Installation:** the sensors are stuck on, with no connection to mains voltage.

 ## How it works

 The script makes a list of the sensors whose state is not `off` (closed). That includes `on` (open) and `unavailable` or `unknown`: a sensor with no connection doesn't prove that the door is closed, so it also stops arming.

 If the list is empty, the script calls `alarm_control_panel.alarm_arm_away`. Otherwise it sends a notification with the names from the list. The name is the name of the device, so name the sensors clearly: "Front door", "Bedroom window".

 ## Steps

- **Add and name the sensors.** Pair each sensor through ZHA or Zigbee2MQTT. Give it the name of the place where it is stuck. Write down the entity IDs of the `binary_sensor` for the doors and windows.
- **Check the notifications.** In Developer tools → Actions try `notify.mobile_app_…` for your phone with a test message.
- **Create the script.** Settings → Automations &amp; scenes → Scripts → Create script → three dots → Edit in YAML. Paste the example. All the entity IDs are examples: replace them with your own.

 ```
alias: "Arm if everything is closed"
mode: single
variables:
  not_closed: >
    {{ expand('binary_sensor.front_door_contact',
              'binary_sensor.bedroom_window_contact',
              'binary_sensor.kitchen_window_contact')
       | rejectattr('state', 'eq', 'off')
       | map(attribute='name') | list }}
sequence:
  - if:
      - condition: template
        value_template: "{{ not_closed | count == 0 }}"
    then:
      - action: alarm_control_panel.alarm_arm_away
        target:
          entity_id: alarm_control_panel.home_alarm
        data:
          code: "1234"
    else:
      - action: notify.mobile_app_telefon
        data:
          title: "The alarm is not armed"
          message: "Open or no connection: {{ not_closed | join(', ') }}"
```

 `code` is needed only if the panel has an arming code. The script is not a master key to the alarm: replace the code with your own and don't keep it where guests can see it.

- **Put a button on the dashboard.** Add a Button card for the script and use it instead of arming the panel directly.

 ## Checking the result

- **Everything closed.** The script arms the alarm. The panel goes into `arming`.
- **An open window.** Open one window and start the script: the alarm stays off, and the notification contains the name of the window.
- **Two open.** Both names are in the message.
- **A sensor with no connection.** Take the battery out of one sensor: the script counts it as a problem.

 ## If it doesn't work

- **It always says "open".** Check in Developer tools → States: the state is `off` when closed. If it is something else, for example `closed`, change `rejectattr('state','eq','off')`.
- **The names are not clear.** Rename the devices in Settings → Devices &amp; services.
- **It arms despite an open door.** You armed directly from the panel, not from the button. The script is not involved.
- **An error with the code.** The panel requires a code: add `code` or use the panel's setting.

 ## Limitations and turning it off

- The script checks only the sensors you list. A door without a sensor is not watched.
- Arming directly from the panel bypasses the check. Hide it from the dashboard or explain to the household to use the button.
- An empty list `expand()` means nothing is checked: add at least one sensor.
- If Home Assistant is not running, there is neither a check nor an alarm.
- Turning off: delete the button and the script or use the panel directly.

 ## Sources and verification status

 The material follows the Home Assistant documentation, read on 22.11.2026. The topic is from Simeon's list of ideas.

- [Home Assistant: Manual alarm control panel](https://www.home-assistant.io/integrations/manual/), 22.11.2026
- [Home Assistant: scripts and actions](https://www.home-assistant.io/docs/scripts/), 22.11.2026
- [Home Assistant: templates (`expand`, `selectattr`)](https://www.home-assistant.io/docs/configuration/templating/), 22.11.2026
- [Home Assistant: Zigbee Home Automation](https://www.home-assistant.io/integrations/zha/), 22.11.2026
- Real Home Automations catalog: Sonoff SNZB-04PR1, 22.11.2026