DEV Community

Marco
Marco

Posted on โ€ข Originally published at blog.disane.dev

Switching heaters on and off automatically

Want to control your heating thermostats automatically via door and window contacts in Home Assistant? I'll show you how to do it ๐ŸŽ‰


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
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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

If you like my posts, it would be nice if you follow my Blog for more tech stuff.

Image of Timescale

๐Ÿš€ pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applicationsโ€”without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Image of Docusign

๐Ÿ› ๏ธ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more