---
title: "The air conditioner in the rental apartment stops by itself when a window is open and starts when it's closed"
description: "A window sensor and an automation in Home Assistant stop the AC when the window stays open, and bring it back when it closes, unless you or the guest stopped it."
canonical: "https://realhomeautomations.com/en/projects/rental-ac-stops-when-window-open/"
language: en-US
updated: 2026-11-25T15:20:36+00:00
---

# The air conditioner in the rental apartment stops by itself when a window is open and starts when it's closed

A window sensor and an automation in Home Assistant stop the AC when the window stays open, and bring it back when it closes, unless you or the guest stopped it.

> Canonical HTML page: https://realhomeautomations.com/en/projects/rental-ac-stops-when-window-open/

- **Difficulty:** Intermediate
- **Build time:** 45–90 minutes
- **Reading time:** 3 minutes

## Tools required

- A window sensor (Sonoff SNZB-04PR1, 1 unit per window)
- An AC in Home Assistant (already added as a climate entity; not included in the product)
- A Zigbee hub or adapter (or Home Assistant with a Zigbee adapter)
- Home Assistant (with a Zigbee integration (ZHA) or Zigbee2MQTT)


## What readers will learn

- Stop the AC when a window is open after a short wait
- Bring it back only if it was stopped by the automation
- Not take control away from the guest
- Get a notification when a window is forgotten


## Skill requirements

- Add a Zigbee sensor to Home Assistant
- Paste YAML into an automation

## 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)

A guest turns on the AC and opens the balcony to air the room. The AC runs all day against an open window. The electricity bill is yours, and the room does not cool. A window sensor can stop the AC while it is open and bring it back after it closes.

 ## What you will get

 The AC switches off when the window has been open for more than a set time, and returns to its previous state when the window closes. If the guest or you have stopped it by hand during that time, the automation **does not start it by itself**. A notification tells you that the window was open.

 ## What we need

- 1 unit [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/) for every window you want to track: Zigbee 3.0, CR2477 battery.
- An AC that has already been added to Home Assistant as a `climate` entity. The AC is not part of the product.
- A working Home Assistant and a phone with the Home Assistant app.

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

 Time: 45–90 minutes. No electrical installation is touched and the AC is not changed.

 ## How it works

 The first trigger is "the window is open for N minutes" (at Simeon's apartment it is 2 hours). The automation saves the AC's state with `scene.create`, then switches it off. The second trigger is "the window is closed". If the AC is off, it restores the saved state. If the guest has started it by hand, it does not interfere.

 At Simeon's apartment the air conditioners are Mitsubishi Electric units controlled through MELCloud Home (the cloud); Home Assistant shows the current temperature and the monthly consumption. A window or a terrace door that stays open for 2 hours stops the air conditioner of that room, and its old mode comes back when everything in the room has been closed for 1 minute.

 ## Steps

- Fit the sensor on the sash and the frame of the window. Pair it. You expect `binary_sensor`, which is `on` when the window is open.
- Check that the AC is a `climate` entity and that the switch-off and switch-on commands work.
- The automation (the entity IDs are examples):

 ```
alias: AC - stop when a window is open
mode: restart
triggers:
  - trigger: state
    entity_id: binary_sensor.window_living
    to: "on"
    for: "02:00:00"
    id: open
  - trigger: state
    entity_id: binary_sensor.window_living
    to: "off"
    id: closed
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: open
          - condition: not
            conditions:
              - condition: state
                entity_id: climate.living_ac
                state: "off"
        sequence:
          - action: scene.create
            data:
              scene_id: ac_before_window
              snapshot_entities:
                - climate.living_ac
          - action: climate.turn_off
            target:
              entity_id: climate.living_ac
          - action: notify.mobile_app_your_phone
            data:
              message: The window is open. The AC has been stopped.
      - conditions:
          - condition: trigger
            id: closed
          - condition: state
            entity_id: climate.living_ac
            state: "off"
        sequence:
          - action: scene.turn_on
            target:
              entity_id: scene.ac_before_window
```

- Save and try it with a window, temporarily reducing `for` to 20 seconds.

 ## Checking the result

- Start the AC, open the window and wait: the AC stops and a notification arrives.
- Close the window: the AC returns to the saved mode.
- Stop the AC by hand while the window is closed, then open and close it: the AC must not start.

 ## If it does not work

- Nothing triggers → a different entity name → check the entity ID.
- The AC returns in a different mode → `scene.create` has not saved everything → check the AC's attributes.
- It comes back when the guest switched it off → the state condition did not trigger → review the second block.

 ## Limitations

- If Home Assistant goes down while the AC is stopped, it stays stopped until you start it.
- If you restart Home Assistant, the saved scene is lost (`scene.create` is temporary).
- The automation does not know whether the AC was stopped by the automation or by the guest, except by its state after closing. Review the logic for your case.
- Warn the guests in the check-in instructions that the AC stops when a window is open.

 ## Sources and verification status

 Checked against the documentation on 22.11.2026.

- [Home Assistant: Scene (scene.create)](https://www.home-assistant.io/integrations/scene/#create-a-scene-on-the-fly)
- [Home Assistant: Climate](https://www.home-assistant.io/integrations/climate/)
- [Home Assistant: Trigger condition (id)](https://www.home-assistant.io/docs/scripts/conditions/#trigger-condition)