Control a climate area by a window sensor and reset it to the previous state after closing

I created an updated blueprint based on https://gist.github.com/sotatech/500b53ee64ca5ad5299c22cde47407ed by @sotatech for controlling a climate area by a window binary_sensor.

I added support for controlling a climate area instead of selecting the climate entities one by one, thanks @firestrife for the nice idea from Entities from area in template - #2 by firestrife

Blueprint screenshot (empty example)

Blueprint to import

blueprint:
  name: Turn off climate if window is opened, reset to same scene after closing
  description: Supports control of the climate of an area by a window sensor entity
    or group entity. Turns the climate devices in this area off and saves their state.
    Turns them back on again ans resets their states after closing the window
  domain: automation
  source_url: https://community.home-assistant.io/t/control-a-climate-area-by-a-window-sensor-and-reset-it-to-the-previous-state-after-closing/386900
  input:
    window_entity:
      name: Window Sensor
      description: The window sensor that will control the climate area.
      selector:
        entity:
          domain: binary_sensor
          device_class: window
    minimum_open_time:
      name: Windows Open Wait Time
      description: Time to delay after window opens before turning off the climate devices.
      default: 25
      selector:
        number:
          min: 0.0
          max: 120.0
          unit_of_measurement: seconds
          mode: slider
          step: 1.0
    minimum_close_time:
      name: Windows Close Wait Time
      description: Time to delay after window was closed before turning on the climate devices again.
      default: 10
      selector:
        number:
          min: 0.0
          max: 120.0
          unit_of_measurement: seconds
          mode: slider
          step: 1.0
    climate_area:
      name: Climate area
      description: The climate area that is controlled by the window sensor.
      selector:
        area:
          entity:
            domain: climate
variables:
  area_name: !input 'climate_area'
  entity_list: '{{ expand(states.climate) |selectattr(''entity_id'', ''in'', area_entities(area_name))
    |map(attribute=''entity_id'') |list }}'
trigger:
  - platform: state
    entity_id: !input 'window_entity'
    to: 'on'
    for: !input 'minimum_open_time'
action:
  - service: scene.create
    data:
      scene_id: '{{area_name}}_before'
      snapshot_entities: '{{entity_list}}'
  - service: climate.turn_off
    target:
      area_id: !input 'climate_area'
  - wait_for_trigger:
    - platform: state
      entity_id: !input 'window_entity'
      to: 'off'
      for: !input 'minimum_close_time'
    continue_on_timeout: false
  - service: climate.turn_on
    target:
      area_id: !input 'climate_area'
  - service: scene.turn_on
    target:
      entity_id: scene.{{area_name}}_before

History

  • 2022-02-01: Initial version
  • 2022-02-18: Add delay after closing the window (e.g. swap window from open to tilt)