Since I have now equipped my home with smart thermostats everywhere and fitted all the windows with corresponding contacts from Aqara, the question now arises as to how I can most cleverly switch the thermostats as soon as a window is opened.

Why all this? 🤔

When I was still in the AVM ecosystem, it made sense to get the corresponding thermostats from AVM too. That also worked very well. However, the "ventilation mode" doesn't work very well with the thermostats in the old building. That's why I had to automate it via Home Assistant.

Prerequisites 📃

For this to work, you should have radiator thermostats and corresponding door and window contacts. It doesn't matter which manufacturer, the main thing is that they are already integrated into Home Assistant.

Then you should create the corresponding rooms as "areas" in Home Assistant and assign the sensors and thermostats to these areas.

The automation 🤖

Once everything is done, create a new automation with the following content. Please adjust the corresponding lines:

- binary_sensor.window_bathroom
- binary_sensor.window_living_room
- binary_sensor.window_kids_room
- binary_sensor.window_bedroom

This list should contain your binary_sensor window and door contacts.

alias: Heating off when window open
description: ""
trigger:
  - platform: state
    to:
      - "on"
      - "off"
    entity_id:
      - binary_sensor.window_bathroom
      - binary_sensor.window_living_room
      - binary_sensor.window_kinderzimmer
      - binary_sensor.window_bedroom
condition: []
action:
  - variables:
      area: "{{ area_name(trigger.entity_id) }}"
      targets: >
        {{ expand(area_entities(area)) | selectattr('domain','eq','climate') |
        map(attribute='entity_id') | join(',') }}
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state == 'on' }}"
        sequence:
          - service: scene.create
            data:
              scene_id: thermostat_settings_{{area | lower}}
              snapshot_entities: "{{ targets }}"
          - delay: 5
          - service: climate.turn_off
            target:
              entity_id: "{{ targets }}"
          - service: notify.notify
            data:
              title: "{{ state_attr(trigger.entity_id, 'friendly_name') }} open"
              message: Heaters in {{ area }} switched off
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state == 'off' }}"
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.thermostat_settings_{{area | lower}}
          - service: notify.notify
            data:
              title: "{{ state_attr(trigger.entity_id, 'friendly_name') }} closed"
              message: Heaters in {{ area }} switched on
mode: parallel
max: 10

The automation is actually quite simple, because it does the following:

  • Variable assignment:
    • area = The triggering area
    • targets = All entities with the domain climate, return only the entity_idand separate with comma
  • condition if the state of the entity is on:
    • Execute the sequence:
      • Create a scene to cache the current state of the thermostat
      • Wait 5 seconds
      • Service climate.turn_off with the determined entity(ies)
      • Send notification
  • Condition if the state of the entity is off:
    • The sequence contains:
      • Turning on the previously saved scene (resetting the state before opening the windows)
  • Service climate.turn_off with the determined entity/entities
  • Send notification

Saving energy through automation

By automating your heating control, you can save significant amounts of energy. Studies show that intelligent heating management can reduce energy consumption by 15-25%. The key is to only heat when it's actually needed – and that's exactly what Home Assistant enables.

Combining multiple sensors is particularly effective: window/door contacts automatically stop heating when ventilating, presence sensors detect whether someone is in the room, and outdoor temperature sensors adjust heating output to the current weather.

Practical tips

Make sure your automations also cover edge cases. What happens if a sensor fails? A fallback mode that sets the heating to a default value when communication is lost prevents your home from cooling down in winter. Also take advantage of temperature profiles for different times of the day.

Further reading

If you enjoyed this article, you might also find these interesting:

Integrating the WEM portal into Home Assistant
Integrate the main gas boiler with the WEM portal into the Home Assistant. We'll do it together! 🪵
Frost warning with Home Assistant 🥶
Do you have a garden and want to be notified when winter is coming? I'll show you how easy it is 🏡
Monitoring non-smart devices 💡
I show you how you can make normal devices smart in a relatively simple way in the article ☝️

Artikel teilen:Share article: