Window/Door controlled heater - saves now previous temp - also groups of windows sensors can be added

Just a small blueprint to switch heater on or off bepending on window or door sensor:

2 Likes

I updatet the blueprint. The previous et temperature is now saved and will be set after window is closed again.

that’s very useful and thx for sharing. Also would it be possible to add conditions based on presence detection that can turn on and off the heater.

Very nice and useful blueprint, I was looking for this kind of function for a long time.
I’ve extended the blueprint with a configurable timer.
With this timer, the heater is not turned off and on many times if you open/close the door/window more often in a short time.
This saves the battery of your heater thermostat.

The extension is inspired by this blueprint example.

Hi, thanks for the reply. Unfortenately I have no usecase for that ans also not the right setup for testing.

I extended your blueprint with a second timer.
As I am using sensors on my windows and door to the balcony, I wanted the heating to wait X seconds before turning off (for walking through the door and closing after a few seconds). This saves closing cycles of the valve in the first place. Otherwise on every opening event the valve would move instantly.

3 Likes

It’s wonderfull solution but there is not heater previous state control. If heater was powered off and you close window, always will power on…

2 Likes

Hello,
Yes i just came here to point out that. if the heater was already turned off, then once we close the window, it will turn it on

I like it!

Is there a way to add more heater? I have 2 heat pump to control with a sensor group.

i realy like it.
the only thing that bothers me is that when the window is closed, the hvac turns on the heat.
is there a way to set the hvac to auto mode when a window is closed?

There is ,

blueprint:
  name: window controlled heater Summer GAVEAS
  description: Raise heater temp to 26 when opening window and bring back with delay
  domain: automation
  source_url: https://gist.github.com/govido/4aaa213e6209d3b76ec0e65d576e3701
  input:
    heating_target:
      name: Heater
      selector:
        entity:
          domain: climate
    window_entity:
      name: Window Sensor
      selector:
        entity: {}
    window_closed_wait:
      name: Wait time open
      description: Time to leave the heating on after window or door is opened.
      default: 120
      selector:
        number:
          min: 0.0
          max: 3600.0
          unit_of_measurement: seconds
          mode: slider
          step: 1.0
    window_opened_wait:
      name: Wait time closed
      description: Time to leave the heating off after window or door is closed.
      default: 120
      selector:
        number:
          min: 0.0
          max: 3600.0
          unit_of_measurement: seconds
          mode: slider
          step: 1.0
mode: restart
max_exceeded: silent
variables:
  heating_target: !input 'heating_target'
  heating_temperature: '{{ state_attr(heating_target, ''temperature'') }}'
trigger:
  platform: state
  entity_id: !input 'window_entity'
  from: 'off'
  to: 'on'
action:
- delay: !input 'window_opened_wait'
- service: climate.set_temperature
  entity_id: !input 'heating_target'
  data:
    temperature: 26
- wait_for_trigger:
    platform: state
    entity_id: !input 'window_entity'
    from: 'on'
    to: 'off'
- delay: !input 'window_closed_wait'
- service: climate.set_temperature
  entity_id: !input 'heating_target'
  data:
    temperature: 22
- service: climate.set_temperature
  entity_id: !input 'heating_target'
  data:
    temperature: '{{heating_temperature}}'

ive addapted mine to only raise or lower the temp.

i have made an edit to the script (forked?) to set HVAC mode.
it kinda works, with an warning in the log about data set value.

here is mine, pherhaps i am missing something or did it totaly wrong.
but hey, i have hass running for 2 months now on a Pi3b so i am a newby to al of this and working on trail and error base here :crazy_face:

blueprint:
  name: window controlled heater
  description: turn off heater when opening window and turn on with delay
  domain: automation
  source_url: https://gist.github.com/govido/4aaa213e6209d3b76ec0e65d576e3701
  #forked 2nd time from  https://gist.github.com/gresie/476f1169ddd4a1bbbb12662f5b20e383
  #forked from https://gist.github.com/dirkk1980/8ba849b480844b32e9ca484e6de5d552
  #inspired by https://github.com/home-assistant/core/blob/973f59e42305fba73ec3da5986eb3639afa373c9/homeassistant/components/automation/blueprints/motion_light.yaml
  input:
    heating_target:
      name: Heater
      selector:
        entity:
          domain: climate
    window_entity:
      name: Window Sensor
      selector:
        entity: {}
    window_closed_wait:
      name: Wait time open
      description: Time to leave the heating on after window or door is opened.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds
    window_opened_wait:
      name: Wait time closed
      description: Time to leave the heating off after window or door is closed.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds
# If window or door is closed within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

variables:
  heating_target: !input 'heating_target'
  heating_temperature: '{{ state_attr(heating_target, ''temperature'') }}'
trigger:
  platform: state
  entity_id: !input 'window_entity'
  from: 'off'
  to: 'on'
action:
# timer waiting for door or window being open for X seconds (not turning the heater off if just walking through a door)
- delay: !input window_opened_wait
- service: climate.set_hvac_mode
  entity_id: !input 'heating_target'
  data:
    hvac_mode: 'off'
- wait_for_trigger:
    platform: state
    entity_id: !input 'window_entity'
    from: 'on'
    to: 'off'
# timer is reset is door is closed within this delay
- delay: !input window_closed_wait
- service: climate.set_hvac_mode
  entity_id: !input 'heating_target'
  data:
    hvac_mode: auto

Hi all,

Just starting this thread into life again this works really well for me using a Nest thermostat. What is a problem though is that the family know they only need to adjust the thermostat and the heating starts with the back door wide open.
Is there a way of stopping this from happening?

Hi Mates,

I’ve tried and re-thinked some blueprints here but they didn’t work for me.

  1. I use Homematic HM-CC-RT-DN which does not restore the previous temperature with turn_on. They use 4.5°C as OFF. If a turn_on gets fired they set the target temp to 5°C.
  2. I do want to trigger the thermostat as rarely as possible.
  3. I need longer delays for switch off/on .

Problem:

  • The heater was turned off

  • The window is closed and the delay to turn heater back on is currently running

  • Now, while the delay runs, the window gets opened again and the automation gets restarted
    => The previous-Tempereratur helper fetches the current setTemp which is 4.5°C (off in my case)

  • The window gets closed but the heater does not turns on again because prevTemp is 4.5 now.

To fix this I only update the prevTemp helper if the automation has been executed sum(delays) ago.

blueprint:
  name: Heater off on window open (Homematic)
  description: Turns off the heater when a window is open and restores it after close and delay.
  domain: automation
  input:
    binary_sensor:
      name: Binary Sensor
      description: The binary sensor that triggers the automation. Ie a window contact.
      selector:
        entity:
          domain: binary_sensor
    heater:
      name: Heater
      description: "The climate device to control."
      selector:
        entity:
          domain: climate
    heater_off_delay:
      name: Heater off delay
      description: "Time that the sensor has to report open befor switching off the heater."
      default: 0.5
      selector:
        number:
          min: 0
          max: 1440 # Maximum of 24 hours in minutes
          step: 0.5
          mode: box
          unit_of_measurement: minutes
    heater_on_delay:
      name: Heater on delay
      description: "Time to wait after the sensor is low before restoring the heater."
      default: 15
      selector:
        number:
          min: 1
          max: 1440 # Maximum of 24 hours in minutes
          step: 0.5
          mode: box
          unit_of_measurement: minutes
    previous_temperature_helper:
      name: Previous Temperature Helper
      description: "An input_number helper to store the heater's previous temperature setting."
      selector:
        entity:
          domain: input_number

# Restart the automation to reset/abort delays
mode: restart
max_exceeded: silent

variables:
  heater: !input heater
  binary_sensor: !input binary_sensor
  previous_temperature_helper: !input previous_temperature_helper
  heater_on_delay: !input heater_on_delay
  heater_off_delay: !input heater_off_delay

# Start the automation when the window gets opened
trigger:
  - platform: state
    entity_id: !input binary_sensor
    from: "off"
    to: "on"
    for:
      minutes: !input heater_off_delay

action:
  #  - service: logbook.log
  #    data:
  #      name: devtest automation
  #      message: "{{ (now() - this.attributes.last_triggered).total_seconds() }} > {{ heater_on_delay * 60  }} | {{ heater_on_delay }}"
  - alias: Update setTemp helper value if the automation was not triggered a longer time
    if:
      condition: template
      value_template: "{{ this.attributes.last_triggered is none or (now() - this.attributes.last_triggered).total_seconds() > (heater_off_delay + heater_on_delay) * 60 }}"
    then:
      - alias: Store setTemperature before tunring the heater off
        service: input_number.set_value
        target:
          entity_id: !input previous_temperature_helper
        data:
          value: "{{ state_attr(heater, 'temperature') }}"
  - alias: Turn heater of if it is not already off
    if:
      condition: template
      value_template: "{{ state_attr(heater, 'temperature') > 5 }}"
    then:
      - alias: trigger climate.turn_off
        service: climate.turn_off
        target:
          entity_id: !input heater
  # Wait for window close
  - alias: Wait for window close
    wait_for_trigger:
      platform: state
      entity_id: !input binary_sensor
      from: "on"
      to: "off"
  # Wait for on delay
  - alias: Delay heater turn on
    delay:
      minutes: !input heater_on_delay
  # Switch heater back on (if it was on)
  - alias: Check if prevTemp is above 5°C
    if:
      condition: numeric_state
      entity_id: !input previous_temperature_helper
      above: 5
    then:
      - alias: Turn heater on
        service: climate.set_temperature
        target:
          entity_id: !input heater
        data:
          temperature: "{{ states(previous_temperature_helper) }}"

Hope this helps someone :wink: