5 min read

Open window: the AC stops and comes back on its own

If the window stays open for a few minutes, the AC stops or drops to standby, and when it closes it returns to its previous settings. Three automations per room and a reminder on your phone.

Level
Intermediate
Active time
60–120 minutes

My wife likes to air the place out. She opens the bedroom window to let in fresh air, leaves the room and forgets that the AC is still running. It keeps cooling or heating the street. Nobody needs to nag: Home Assistant sees it, warns you, turns the AC down, and when the window closes it puts everything back the way it was.

What you will get

  • A notification on your phone when a window has been open for half an hour while the AC is running.
  • An AC that goes into standby by itself: in cooling mode it switches off, and in heating mode it lowers the target temperature to 20 °C and so barely runs.
  • A return to the previous mode and temperature as soon as all the windows in the room are closed.

No new air conditioners needed: contact sensors on the windows and an AC visible in Home Assistant are enough.

What you need

  • Sonoff SNZB-04PR1: Zigbee contact sensor (sensor and magnet), one per window. We have six windows in total across three rooms.
  • An AC that Home Assistant controls as a climate. Ours are Mitsubishi Electric through the MELCloud integration. We don’t sell air conditioners.
  • A phone with the Home Assistant app for the notifications.

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

Setup time: about an hour for the first room, less for the others.

How it works

Each room gets three automations. Each answers one question:

  1. Is the window staying open? If it has been open for 5 minutes and the AC is running, Home Assistant saves its current settings and puts it into standby.
  2. Is someone turning on the AC with the window open? The automation stops it again.
  3. Are the windows closed? If the AC was stopped by an automation, its settings are restored.

Between the first and the third sits a helper switch “restore pending”. It means “I stopped it”. Without it, closing a window would also turn on an AC that you switched off by hand.

When a room has several windows, you combine them into one group. That way the automations look at one value: “at least one is open” or “all are closed”.

A separate automation, one for all rooms, sends a reminder after a window has been open for 30 minutes with the AC running, repeats it every 30 minutes, and after 2 hours itself turns the AC down and says in the notification that it will return when the window closes.

Steps

  1. Combine the room’s windows: Settings → Devices & services → Helpers → Create helper → Group → Binary sensor group. Add the sensors, choose Opening as the type and leave All entities off. That way binary_sensor.bedroom_windows is on, whenever at least one window is open.
  2. Create a Toggle helper “Bedroom AC restore pending” (input_boolean.bedroom_ac_restore_pending) and leave it off.
  3. Add the first automation (below). Replace binary_sensor.bedroom_windows, climate.bedroom and the switch with your own.
  4. Add the second and third automations.
  5. Optionally add the reminder.

The entity names and the numbers (5 minutes, 20 °C, 30 minutes) are examples. Change them to suit the room. Each automation is added as new, through the three-dot menu and “Edit in YAML”.

alias: Bedroom AC off when windows stay open
mode: single
triggers:
  - trigger: state
    entity_id: binary_sensor.bedroom_windows
    to: "on"
    for:
      minutes: 5
conditions:
  - condition: not
    conditions:
      - condition: state
        entity_id: climate.bedroom
        state: "off"
actions:
  - action: scene.create
    data:
      scene_id: bedroom_ac_before_windows
      snapshot_entities:
        - climate.bedroom
  - action: input_boolean.turn_on
    target:
      entity_id: input_boolean.bedroom_ac_restore_pending
  - choose:
      - conditions:
          - condition: state
            entity_id: climate.bedroom
            state: heat
        sequence:
          - if:
              - condition: numeric_state
                entity_id: climate.bedroom
                attribute: temperature
                above: 20
            then:
              - action: climate.set_temperature
                target:
                  entity_id: climate.bedroom
                data:
                  temperature: 20
    default:
      - action: climate.set_hvac_mode
        target:
          entity_id: climate.bedroom
        data:
          hvac_mode: "off"

scene.create with snapshot_entities saves the AC’s current state. The condition “not off” makes it so that if you have already stopped it by hand, the automation touches nothing.

alias: Bedroom AC off if turned on while windows are open
mode: single
triggers:
  - trigger: state
    entity_id: climate.bedroom
    from: "off"
    to:
      - cool
      - dry
      - fan_only
      - heat
      - heat_cool
conditions:
  - condition: state
    entity_id: binary_sensor.bedroom_windows
    state: "on"
actions:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state == 'heat' }}"
        sequence:
          - delay:
              seconds: 3
          - action: scene.create
            data:
              scene_id: bedroom_ac_before_windows
              snapshot_entities:
                - climate.bedroom
          - action: input_boolean.turn_on
            target:
              entity_id: input_boolean.bedroom_ac_restore_pending
          - if:
              - condition: numeric_state
                entity_id: climate.bedroom
                attribute: temperature
                above: 20
            then:
              - action: climate.set_temperature
                target:
                  entity_id: climate.bedroom
                data:
                  temperature: 20
    default:
      - action: climate.set_hvac_mode
        target:
          entity_id: climate.bedroom
        data:
          hvac_mode: "off"

In heating mode we wait 3 seconds before saving, so the integration has picked up the new settings.

alias: Bedroom AC restore when windows close
mode: single
triggers:
  - trigger: state
    entity_id: binary_sensor.bedroom_windows
    to: "off"
conditions:
  - condition: state
    entity_id: input_boolean.bedroom_ac_restore_pending
    state: "on"
actions:
  - action: scene.turn_on
    target:
      entity_id: scene.bedroom_ac_before_windows
  - action: input_boolean.turn_off
    target:
      entity_id: input_boolean.bedroom_ac_restore_pending

Restoring only happens if the switch is on. That is why closing a window does not turn on an AC that you didn’t stop through this automation.

The reminder, shortened for one room:

alias: Bedroom window open reminders
mode: single
triggers:
  - trigger: state
    entity_id: binary_sensor.bedroom_windows
    to: "on"
    for:
      minutes: 30
conditions:
  - condition: not
    conditions:
      - condition: state
        entity_id: climate.bedroom
        state: "off"
actions:
  - repeat:
      sequence:
        - action: notify.mobile_app_telefon  # replace with your phone
          data:
            title: Window open
            message: The bedroom window is open and the AC is running. Close it so electricity isn't wasted.
        - wait_template: "{{ not is_state('binary_sensor.bedroom_windows', 'on') }}"
          timeout:
            minutes: 30
          continue_on_timeout: true
      until:
        - condition: state
          entity_id: binary_sensor.bedroom_windows
          state: "off"

You find the service on your phone in Developer tools → Actions by entering notify.mobile_app.

Check the result

  • Temporarily reduce minutes: 5 to 1, open a window with the AC running. After a minute the AC should be in standby, and the switch: on.
  • Close the window. The AC returns with its previous mode and temperature, and the switch becomes off.
  • Stop the AC by hand, open and close the window. Nothing turns on.
  • Open a window and turn the AC on. It switches off, and in heating mode drops to 20 °C.

If it doesn’t work

  • The AC doesn’t stop → the group has not been on for the full 5 minutes → check its history; if the window is closed and opened, the countdown starts over.
  • It doesn’t come back → scene.bedroom_ac_before_windows no longer exists → check it in Developer tools → States.
  • An old temperature comes back → the settings were changed by hand while the window was open → the restore overwrites them.

How to stop it

Stop the room’s three automations from Settings → Automations & scenes. The reminder is a separate automation and is stopped separately.

Our ACs go through the MELCloud cloud service, so commands only work with internet. The sensors are Zigbee and work locally. The reminder is lost if Home Assistant restarts while a window is open.

Sources and verification status

The automations were read in Marto’s Home Assistant on 23.11.2026 (read-only): three each for the bedroom, kids’ room and living room, plus the shared reminder. The examples are anonymised and shorter versions.

At home

Marto

My wife likes to air out the rooms and often forgets the AC is running. In our three rooms (bedroom, kids' room, living room) there are three automations each and a shared reminder: after 5 minutes of an open window the AC stops (in heating mode it drops to 20 °C), and when we close it, it returns to its previous settings. The windows are watched by Zigbee sensors Tuya TS0203 and HOBEIAN ZG-102Z, and the ACs are Mitsubishi Electric through MELCloud.

Need a hand?

We can set up and install everything in this project. In some regions we install it ourselves — ask us.

Contact us

Related projects

Smart Door and Window Sensor Sonoff SNZB-04PR1 – Zigbee 3.0 Protocol, CR2477 Battery Powered, Real-Time Opening Alerts, eWeLink & Home Assistant

15,70 €
View parts

What you need

Added to cart

Real Home Automations

Sign in to your account

With a code sent to your email

Continue with Google
or

By continuing, you accept the Terms and Conditions and the Privacy Policy.