Central heating automation turn off if a window and door have been left open

HI there,

I have a few door and window sensors that i would like to help control my HVAC system. I have controllable vents in each main room. This more so applies to bedrooms / bathrooms however.

I would like to create an automation that if a bedroom window and corresponding door has been left open it will turn off the HVAC system until they have been closed.

Do i create a seperate automation per room or would it be possible to have all in one automation?

Thank you!

You could set the entity for the hvac as the trigger id for each door sensor trigger. Then in the action you can use a service call with a template for the entity to control the hvac in that room.

For multiple windows, use a group to bundle window/door sensors first. and just add more triggers to support multiple rooms.

Something like this to give you an idea:

description: ""
mode: single
trigger:
  - platform: state
    entity_id:
      - binary_sensor.openclose_bedroom_window
    to: 
      - "on"
      - "off"
    from:
      - "off"
      - "on"
    id: climate.bedroom
  - platform: state
    entity_id:
      - group.openclose_kitchen_windows
    to: 
      - "on"
      - "off"
    from:
      - "off"
      - "on"
    id: climate.kitchen
condition: []
action:
  - service: climate.set_hvac_mode
    target:
      entity_id: "{{ trigger.id }}"
    data:
      hvac_mode: "{{ trigger.from_state.state | replace('on','auto') }}"

Just for fun, I also used the window sensor state to determine the hvac state too.

2 Likes

Yeah, can do all in one. Please provide a list of the entity IDs for the door and window sensors for each room, and the climate entity.

Both door and window in a room, or just one?

In other words: HVAC on unless any room has both its door and its window open?

Hey mate.

both door an window.

other words: HVAC on unless any room has both its door and its window open?

Yes please.

Ids as below:

climate.daikinap60215 < HVAC

Master bedroom:
binary_sensor.master_bedroom_window_sensor_door_2
binary_sensor.master_bedroom_door_sensor_door

Polly Bedroom:
binary_sensor.contact_sensor_door
binary_sensor.polly_door_sensor_door

sorry the ID’s are a bit shit. I havent gotten around to cleaning them up

I edited my post above with some sample code for one hvac/sensor combo.

1 Like

ps, when you have multiple windows it is best to place them in a group, so that will take care of the fact that one window will turn off the hvac, but all windows must be closed before you turn it back on.

I dont quite underastand as i am still quite new. i do struggle with some things. ill see how i go and repoirt back!

1 Like

Haven’t tested this, so I may have made some small errors. I just fixed one, because turning the hvac on is not called “on” but “auto”.

this is what i have put in, i struggle if its not in visual lol.

description: "HVAC test"
mode: single
trigger:
  - platform: state
    entity_id:
      - binary_sensor.polly_door_sensor_door
      - binary_sensor.contact_sensor_door
    to: 
      - "on"
      - "off"
    from:
      - "off"
      - "on"
    id: climate.bedroom
  - platform: state
    entity_id:
      - group. *insert group of windows and doors?*
    to: 
      - "on"
      - "off"
    from:
      - "off"
      - "on"
    id: climate.kitchen
condition: []
action:
  - service: climate.set_hvac_mode
    target:
      entity_id: "{{ trigger.id }}"
    data:
      hvac_mode: "{{ trigger.from_state.state | replace('on','auto') }}"

The trigger id should be the exactly the same as the entity_id for the hvac that you want to control with it (assuming each valve has it own climate entity in HA so you can control each room separately).

As for creating groups, you do not do it in the automation, but you create a helper entity. You can do that in the GUI in settings:

This should work for climate entity states of off or heat. Triggers off any change to the door & window sensors.

Condition block then checks:

  • if the climate is in heat mode, are any of the rooms’ door and window open?
  • if the climate is in off mode, do all of the rooms have a door or window closed?

If it gets through those tests, we need to toggle the climate.

trigger:
  - platform: state
    entity_id:
      - binary_sensor.master_bedroom_window_sensor_door_2
      - binary_sensor.master_bedroom_door_sensor_door
      - binary_sensor.contact_sensor_door
      - binary_sensor.polly_door_sensor_door
condition:
  - or:
    - and:
      - "{{ is_state('climate.daikinap60215', 'heat') }}"
      - or:
        - and:
          - "{{ is_state('binary_sensor.master_bedroom_window_sensor_door_2', 'on') }}"
          - "{{ is_state('binary_sensor.master_bedroom_door_sensor_door', 'on') }}"
        - and:
          - "{{ is_state('binary_sensor.contact_sensor_door', 'on') }}"
          - "{{ is_state('binary_sensor.polly_door_sensor_door', 'on') }}"
    - and:
      - "{{ is_state('climate.daikinap60215', 'off') }}"
      - and:
        - or:
          - "{{ is_state('binary_sensor.master_bedroom_window_sensor_door_2', 'off') }}"
          - "{{ is_state('binary_sensor.master_bedroom_door_sensor_door', 'off') }}"
        - or:
          - "{{ is_state('binary_sensor.contact_sensor_door', 'off') }}"
          - "{{ is_state('binary_sensor.polly_door_sensor_door', 'off') }}"
action:
  - service: climate.turn_{{ ('off','on')[is_state('climate.daikinap60215', 'off')] }}
    target:
      entity_id: climate.daikinap60215

EDIT: now tested as a mock-up, works as expected:

image

Climate goes off if either door/window pair are both on, climate goes back on when that’s no longer the case.

Just edit-as-YAML and paste the above over the trigger/condition/action of an already-existing (blank?) automation. If you switch back to visual, it should look like this:

and you can expand each of the steps, although the UI won’t do anything clever for the templates.

Reading the above solution it seems that I missed a bit in the description about door and window both being open. As an alternative to the above I still think groups will make things easier to understand. You can have a group that tests if all members are on (door and window open together). You can also have a group that tests if any of the members are on (any window open). Combine those the rigt way, and you’ll have one sensor to test and the automation will be very straightforward.

Based on OP’s description they likely need a trigger for the climate entity turning to “heat” as well as for doors/windows opening and closing.

Maybe: if there are other things turning it on and off. Easy to add if that is the case:

trigger:
  - platform: state
    entity_id:
      - binary_sensor.master_bedroom_window_sensor_door_2
      - binary_sensor.master_bedroom_door_sensor_door
      - binary_sensor.contact_sensor_door
      - binary_sensor.polly_door_sensor_door
      - climate.daikinap60215

and the rest as before. Might need mode:queued as this would trigger again as soon as one of the switch triggers changed the climate.

I am planning on going down this path. My HVAC is normally set to Auto. I would want to change it to Off if any window is open and put it back to Auto when all windows are closed. I am thinking that this would be a good use of labels. All the window sensors could be labeled with something like HVAC_Sensor. Then, the Auto to Off would be triggered when any window goes from Closed to Open. The Off to Auto would be triggered by all windows being closed. Is this doable with labels?

Absolute Ledge! Ill pop this one in and report back possibly tonight if i have time.

thank you!

could we add a time delay on for x minutes before the actions triggers?

thanks!

Yes, — you’d need to duplicate the trigger and have one trigger to: 'on' and for: "00:05" (for example) and the other trigger to: 'off' with no delay.

Thanks mate, how would that fit in to the YAML?
could i have an example or a guide on where it would sit in the lines?

thank you!

trigger:
  - platform: state
    entity_id:
      - binary_sensor.master_bedroom_window_sensor_door_2
      - binary_sensor.master_bedroom_door_sensor_door
      - binary_sensor.contact_sensor_door
      - binary_sensor.polly_door_sensor_door
    to: 'on'
    for:
      minutes: 5

  - platform: state
    entity_id:
      - binary_sensor.master_bedroom_window_sensor_door_2
      - binary_sensor.master_bedroom_door_sensor_door
      - binary_sensor.contact_sensor_door
      - binary_sensor.polly_door_sensor_door
    to: 'off'

  - platform: state
    entity_id: climate.daikinap60215

All covered here:

I split out the climate state trigger as it’s not just on or off but I’m sure you can figure out how to adjust that to your preference.

Seems to be all working well. I haven’t yet put a time delay in.
Another quirk that has popped up is that if i already have the heater off and then the automation triggers the heater will then turn on when its not required.

Can it have a rule to only turn on if it was previously on?