Turn off HVAC/thermostat when window/ door open

Simple automation that pauses the climate entity when doors or windows are open and resumes last state once they are closed.

Features:

  • Ability to set the time delay that doors/windows must be open or closed prior to automation triggering.
  • If HVAC is off when door/windows open automation will not cause any changes.
  • If HVAC is turned on while windows/doors open, automation will not override any settings once windows/doors are closed.
  • Ability to trigger additional actions when HVAC is Paused or Resumed, including notifications or triggering other automations.
  • Ability to run multiple instances of the blueprint at once to control multiple HVAC systems by utilizing separate automations which use this blueprint.
  • Ability to set a timeout in which the HVAC will not auto resume if doors/windows have been opened for more than a specified duration.
  • Ability to set timeout actions if the timeout period has elapsed. (Useful for sending notifications)
  • Choose whether you want custom actions to occur either before or after the HVAC system has been turned off.

Needed to work

  • Climate entity
  • Group entity or binary_sensor that you want to trigger the climate entity.
  • Automation assumes that when the group entity or binary_sensor is ‘on’ the HVAC system should be paused.

Information on setting up a group entity: Group - Home Assistant (home-assistant.io)

Release Notes

1.1

  • Used climate state value instead of Hvac action attribute to determine if automation should resume HVAC.

1.2

  • Re-wrote to include a condition to prevent automation from firing when HVAC is already off.
  • Uses “climate.set_hvac_mode” instead of “climate.turn_off”

1.3

  • Added ability to use both new style and old style groups.
  • Changed the delay selector to use a typed number selector giving the interface a cleaner look.

1.4

  • Added ability to trigger optional additional actions when the climate entity is paused and/or resumed.

1.5

  • Blueprint now names the climate snapshot based off of the climate entity friendly name. This means you can now run multiple instances of the same blueprint for different climate entities without the snapshots overriding each other. Snapshot naming accounts for spaces and special characters that may be included in the friendly name so no name changes should be necessary.

1.6

  • Automation will no longer restore previous settings if thermostat is adjusted while HVAC is off.
  • 1.6.1 Added source_url into blueprint to allow easier updating and sharing.

Latest

1.7

  • Added in timeout and timeout actions! If the timeout is set then the system will remain in its off state after the set timeout value even if the door/window sensors are closed. If the door/window sensors are closed prior to the timeout value elapsing then the system will restore as normal.
  • Timeout actions are optional actions that will run if the system does timeout.
  • Action First toggle: this feature if set to on will cause any user defined pause actions to happen after the pause delay and before the thermostat is turned off. This is useful if you want to create a notification prior to actually shutting off the system. To make these actions happen instantly set the pause delay to 0.

Feel free to keep me updated on your experience with this automation if you choose to use it!

If you have feature requests that someone has already requested, please chime in! That lets me know what to work on next!

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Code
#ver. 1.7
blueprint:
  name: HVAC Pause V1.7
  description: Pauses HVAC when windows/doors open; resumes last state once closed
  domain: automation
  source_url: https://gist.github.com/raffy-ops/2bdf967036d8d274fb1f62572ed5e545
  input:
    climate_device:
      description: Climate entity used for climate control.
      name: Climate Device
      selector:
        entity:
          domain:
          - climate
          multiple: false
    doors_windows:
      description: Group of entities that will activate automation. (Assumes 'on'
        means 'open')
      name: Door and window sensors.
      selector:
        entity:
          domain:
          - group
          - binary_sensor
          multiple: false
    pause_delay:
      description: Time to wait before pausing the HVAC system.
      name: Pause Delay
      default:
        hours: 0
        minutes: 5
        seconds: 0
      selector:
        duration: {}
    resume_delay:
      description: Time to wait before resuming the HVAC system.
      name: Resume Delay
      default:
        hours: 0
        minutes: 0
        seconds: 30
      selector:
        duration: {}
    timeout:
      description: If set HVAC will ramain off if door/window is not closed prior to timeout value elapsing.
        Set to 0 to disable timeout.
      name: Timeout (optional)
      default:
        hours: 0
        minutes: 0
        seconds: 0
      selector:
        duration: {}
    action_first:
      description: When set to On any defined 'Pause Actions' will occur after the pause delay and prior to
        any other actions.
      name: Action First
      selector:
        boolean:
    pause_action:
      description: Optional additional action to perform when climate entity is paused.
      name: Pause Action (Optional)
      default: []
      selector:
        action: {}
    resume_action:
      description: Optional additional action to perform when climate entity resumes.
      name: Resume Action (Optional)
      default: []
      selector:
        action: {}
    timeout_action:
      description: Optional additional action to perform if the timeout value elapses.
      name: Timeout Action (Optional)
      default: []
      selector:
        action: {}
variables:
  action_first: !input action_first
  pause_action: !input pause_action
  resume_action: !input resume_action
  timeout_action: !input timeout_action
  climate_device: !input climate_device
  doors_windows: !input doors_windows
  timeout: !input timeout
  timeout_empty: {'hours':00, 'minutes':00, 'seconds':00}
  name_id: '{{ state_attr( climate_device ,''friendly_name'')|lower |replace('' '',''_'')
    | regex_replace(find=''[^\w]'', replace='''') ~ ''_snapshot'' }}'

mode: single
trigger:
- platform: state
  entity_id: !input doors_windows
  from: 'off'
  to: 'on'
  for: !input pause_delay
  id: group_open
condition:
- condition: not
  conditions:
  - condition: state
    entity_id: !input climate_device
    state: 'off'
action:
- choose:
  - conditions: '{{ pause_action is defined and action_first == true }}'
    sequence: !input pause_action
- service: scene.create
  data:
    scene_id: '{{ name_id }}'
    snapshot_entities: !input climate_device
- service: climate.set_hvac_mode
  target:
    entity_id: !input climate_device
  data:
    hvac_mode: 'off'
- choose:
  - conditions: '{{ pause_action is defined and action_first == false }}'
    sequence: !input pause_action
- if:
  - condition: template
    value_template: '{{ timeout != timeout_empty }}'
  then:
    - wait_for_trigger:
      - platform: state
        entity_id: !input doors_windows
        from: 'on'
        to: 'off'
        for: !input resume_delay
      continue_on_timeout: true
      timeout: !input timeout
    - choose:
      - conditions: '{{ wait.trigger == none and timeout_action is defined }}'
        sequence: !input timeout_action
    - stop: ''
  else:
    - wait_for_trigger:
      - platform: state
        entity_id: !input doors_windows
        from: 'on'
        to: 'off'
        for: !input resume_delay
      continue_on_timeout: false
- condition: not
  conditions:
  - condition: state
    entity_id: !input climate_device
    attribute: fan_mode
    state: 'on'
- condition: state
  entity_id: !input climate_device
  state: 'off'
- service: scene.turn_on
  target:
    entity_id: '{{ ''scene.'' ~ name_id }}'
- choose:
  - conditions: '{{ resume_action is defined }}'
    sequence: !input resume_action

5 Likes

Thanks, this is excellent.

Is it possible to put in a condition that it only fires if the HVAC is turned on?

My air conditioner can be off but the trigger is still firing.

I wrote this in a way that it uses a snapshot to be able to apply all of the thermostat settings like temperature and hopefully any fan settings without the use of any template sensors as opposed to just a simple ‘on’ or ‘off’ command. Because of this it still needs to create a snapshot even if your HVAC system is already off to prevent it from causing a fault due to a missing snapshot, however when it goes to resume it should simply reapply the ‘off’ settings and not turn anything back on.
Is this actually turning your system back on when it was previously off or is it keeping it off as you had it?

Edit: I might be able to figure something out though. Give me some time.

It’s not turning it back on, it’s just slightly annoying because it will cause my air con to make a ping sound. (Actually it makes three sounds, as if the remote is sending an ‘off’ message three times).

I really do love it though, super clever.

Very good to know! Thank you for making me aware!
There is a simple way for me to make this work without triggering the automation, however I am attempting to come up with something slightly more complex that will allow me to work on implementing a different feature I’ve been trying to tackle.
I will get you set up though, and I would love to hear your feedback once I push the update!

Edit: As for the 3 beeps that is probably caused by this using a scene as opposed to just an ‘on’ or ‘off’ command. So it is probably sending it an ‘on/off’ command, ‘temperature setpoint’ and another command for the mode. I don’t know if all devices would automatically resume to their last state and I have read of issues of some equipment not working with “climate.turn_on” so that’s why I went this route.

1 Like

Awesome, happy to be patient.

Had another weird issue where I went out of sync. Eg., the AC would turn on when the door is opened, and would turn off when the door is closed. Turning it on and off did the trick I think.

When your door is open does the group entity read as ‘on’?
If not, I may know another trick that I will implement either way.

Yep, when a door is opened the group is on.

Any luck with your updates?

Version 1.2 is written to prevent the automation from triggering if the system is already off. Give it a try if you haven’t already

Thanks mate, it’s great and working a treat! Great job.

1 Like

Hey I really appreciate the follow through, and I’m glad it’s working better for you now! Don’t hesitate to make any suggestions!

Hi,

This is working nicely for me. Is it possible to add a timeout where it won’t resume the previous state. My use case for this is that in my office, it gets hot when the weather is warm and so I put the AC on, but want it to pause when the door opens. This is working now with this blueprint.

I’d like it to timeout so if I leave there door open overnight as an example, it doesn’t automatically turn on the next day when the door is closed. I want to explicitly turn it on before this blueprint will automatically turn it on again after the door is closed. I may forget to turn it off because it went off when the door opened and I don’t want it to turn on again the next day when the door closes every time.

Hope this explanation makes sense. Thanks so much for this. It works beautifully!

1 Like

Very nice blueprints, works like a charm for me. Great thanks.

First of all, thanks a lot for this great blueprint.

On the other hand I would suggest if it could be possible to add an automation to turn of the HVAC when 1 or more people from the house go away and resume when people arrive again to the house.

Thanks for all

I’m fairly new to HA. I imported this Blueprint, but it doesn’t recognize any available option for me in the Door and window sensors dropdown list. I had already created a “Door and Window Sensors” group in my config file (see below), and my configuration check passed and this group shows up in my list of entities on the Devices & Services page. But can’t figure out why I can’t add it in the Blueprint. What am I doing wrong?

binary_sensor:
  - platform: group
    name: Door and Window Sensors
    device_class: opening
    entities:
      - binary_sensor.back_door
      - binary_sensor.front_door
      - binary_sensor.kitchen_side_window
      - binary_sensor.living_room_side_window
      - binary_sensor.living_room_front_window
      - binary_sensor.dining_room_front_window
      - binary_sensor.dining_room_side_window
      - binary_sensor.main_floor_bedroom_side_window
      - binary_sensor.main_floor_bedroom_rear_window
      - binary_sensor.basement_window
      - binary_sensor.basement_bedroom_window

Try adding this to your ‘groups.yaml’

door_and_window_sensors:
  name: Door and Window Sensors
  entities:
    - binary_sensor.back_door
    - binary_sensor.front_door
    - binary_sensor.kitchen_side_window
    - binary_sensor.living_room_side_window
    - binary_sensor.living_room_front_window
    - binary_sensor.dining_room_front_window
    - binary_sensor.dining_room_side_window
    - binary_sensor.main_floor_bedroom_side_window
    - binary_sensor.main_floor_bedroom_rear_window
    - binary_sensor.basement_window
    - binary_sensor.basement_bedroom_window

I can look into adding this with a default of it working as it does now so it doesn’t interfere with others who already are using it. Thanks for the idea!

I can look into making an automation that does this, were you thinking you wanted the same functionality as this automation as well or just a way to pause only based on occupancy?

I believe the best option for this would be to have a separate automation for occupancy and just to use it in conjunction with this automation. I don’t want to make this one become too complex so others don’t struggle with a huge setup menu.

1 Like

That did it, thanks!