Notifications to close an open door or window after a set number of minutes

Tags: #<Tag:0x00007f326d9ee138> #<Tag:0x00007f326d9ee070> #<Tag:0x00007f326d9edf30>

Sends two reminders as notifications to a mobile device to close a window or door after opening it, if the temperature outside is below a certain degree.

Thanks to @KTibow for the improvement.

# 
# Home Assistant Automation Blueprint
#
# Sends two notifications to close a window or door after opening it, 
# if the temperature outside is below a certain degree. 
#
# Revision 2
# Roozbeh Farahbod, Jan. 2021
#

blueprint:
  name: Notification to Close a Window 
  description: Notification to close windows if it is cold outside
  domain: automation
  input: 
    contact_sensor: 
      name: Contact Sensor
      description: 'The window or door sensor that triggers the automation.'
      selector: 
        entity:
          domain: binary_sensor
    first_timer:
      name: 'First timer'
      description: 'The first notification timer (in minutes).'
      default: 10
      selector: 
        number:
          min: 1
          step: 1
          max: 60
          mode: slider
    second_timer:
      name: 'Second timer'
      description: 'The second notification timer (in minutes).'
      default: 15
      selector: 
        number:
          min: 1
          step: 1
          max: 60
          mode: slider
    temperature:
      name: 'Temperature'
      description: 'The outside temperature below which the notification should be sent.'
      default: 20
      selector: 
        number:
          min: 0
          step: 1
          max: 25
          mode: slider
    device_identifier:
      name: Device to notify
      description: >
        The device to receive the notification; it needs to run the official 
        Home Assistant app to receive notifications.
      selector: 
        device:
          integration: mobile_app

# We will have two triggers, for the two different reminders. 
# However, a reminder will be ignored if the door or window is already closed by then. 
trigger:
- platform: state
  entity_id: !input contact_sensor
  from: 'off'
  to: 'on'
  for:
    hours: 0
    minutes: !input first_timer
    seconds: 0
- platform: state
  entity_id: !input contact_sensor
  from: 'off'
  to: 'on'
  for:
    hours: 0
    minutes: !input second_timer
    seconds: 0

# Two conditions:
# 1. The door or window should still be open. 
# 2. The temperature reading must be below the set value. 
condition:
- condition: state
  entity_id: !input contact_sensor
  state: 'on'
- condition: numeric_state
  entity_id: weather.pihome
  attribute: temperature
  below: !input temperature

# Send a notification to the mobile device. 
action:
- device_id: !input device_identifier
  domain: mobile_app
  type: notify
  message: 'Time to close {{trigger.to_state.attributes.friendly_name}}.'
  title: 'Close {{trigger.to_state.attributes.friendly_name}}!'

mode: single

GitHub: https://github.com/home-IoT/hass-blueprints/blob/main/reminder_to_close_window.yaml

3 Likes
    notify_device:
      name: Device to notify
      description: Device needs to run the official Home Assistant app to receive notifications.
      selector:
        device:
          integration: mobile_app
1 Like

Nice work. Was looking after something like this.

Instead of notification on phone, my plan is to use this setup


and have an announcement saying ‘windows xxx has now been open for 10 minutes’.

/Jorn

1 Like

Thank you! I did try integration: 'Mobile App' which was wrong apparently.

Where does it get the outside temperature from?

It’s hardcoded as weather.pihome.

Could you make it configurable so the user can choose the most apropriate sensor?

1 Like

That would be greate, or even choose a sensor if its rainy or not (binary)

@NKH Yes, sure; I can share a different version in a bit (in the middle of a busy workday now). I assume that you mean a sensor with a temperature reading, correct?

@r100gs anything is possible and I will be happy to help; however, in my view we will end up with a too generic of a blueprint. For me, the core point of a blueprint is to capture a pattern and reduce cost of creating similar automations by fixing the logic and common structure. To offer the freedom of choosing a temperature sensor or a binary sensor (and then with values), will make the blueprint too generic.

We can create a version that depends on the state of a binary sensor, and for example remove the temperature choice.

1 Like

Yeah, that’s perfect (and there’s no rush :smile:)!

@roozbeh. Everything ist ok THX about the very nice blueprint

Hi @NKH , here is a version I made for a custom temperature sensor. Keep in mind that I set the class of the selector to limit the choices to temperature devices. Depending on your setup it may not list your device. If you find any problems, let me know and we can debug it together.

# 
# Home Assistant Automation Blueprint
#
# Two Notifications to close a window or door after opening it, 
# if the temperature reading of a given sensor is below a certain degree. 
#
# Revision 1
# Roozbeh Farahbod, Jan. 2021
#

blueprint:
  name: 'Notification to Close a Window (custom sensor)'
  description: Notification to close windows if it is cold outside
  domain: automation
  input: 
    contact_sensor: 
      name: Contact Sensor
      description: 'The window or door sensor that triggers the automation.'
      selector: 
        entity:
          domain: binary_sensor
    first_timer:
      name: 'First timer'
      description: 'The first notification timer (in minutes).'
      default: 10
      selector: 
        number:
          min: 1
          step: 1
          max: 60
          mode: slider
    second_timer:
      name: 'Second timer'
      description: 'The second notification timer (in minutes).'
      default: 15
      selector: 
        number:
          min: 1
          step: 1
          max: 60
          mode: slider
    temperature_sensor: 
      name: Temperature Sensor
      description: 'The sensor used for reading the temperature.'
      selector: 
        entity:
          domain: sensor
          device_class: temperature
    temperature:
      name: 'Temperature'
      description: 'The outside temperature below which the notification should be sent.'
      default: 20
      selector: 
        number:
          min: 0
          step: 1
          max: 25
          mode: slider
    device_identifier:
      name: Device to notify
      description: >
        The device to receive the notification; it needs to run the official 
        Home Assistant app to receive notifications.
      selector: 
        device:
          integration: mobile_app

# We will have two triggers, for the two different reminders. 
# However, a reminder will be ignored if the door or window is already closed by then. 
trigger:
- platform: state
  entity_id: !input contact_sensor
  from: 'off'
  to: 'on'
  for:
    hours: 0
    minutes: !input first_timer
    seconds: 0
- platform: state
  entity_id: !input contact_sensor
  from: 'off'
  to: 'on'
  for:
    hours: 0
    minutes: !input second_timer
    seconds: 0

# Two conditions:
# 1. The door or window should still be open. 
# 2. The outside temperature must be below the set value. 
condition:
- condition: state
  entity_id: !input contact_sensor
  state: 'on'
- condition: numeric_state
  entity_id: !input temperature_sensor
  below: !input temperature

# Send a notification to the mobile device. 
action:
- device_id: !input device_identifier
  domain: mobile_app
  type: notify
  message: 'Time to close {{trigger.to_state.attributes.friendly_name}}.'
  title: 'Close {{trigger.to_state.attributes.friendly_name}}!'

mode: single

Cheers!

1 Like

Hi I’m not getting any notifications, have tried all mobiles in HA

@soylant let’s see where the root cause is.

Do you receive notifications from any other automation on this instance of HA?

So sorry my bad​:pensive::grimacing: it’s working perfect

No sorries! :slight_smile: I’m happy that it’s working.

Thanks for the update! It looks like it works, at least the config/setup part 'cos I’m not home to actually open windows to check the function yet :smiley:

1 Like

This is a better solution for those that want to use a specific temperature sensor