Last active
November 15, 2024 11:38
-
-
Save Raukze/27fe0c6bf6d91b8ae2ab5e11880509ba to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Contact Sensor Left Open Notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: 🚪 Contact Sensor Left Open Notification by Malte | |
description: | | |
📲 Notifies you when a door or window is left open. | |
🚀 Version 2024.04.23.1 | |
Are you tired of worrying about open doors or windows? This blueprint has got you covered! It's designed to send you a prompt notification when a door or window remains open for a specified duration. | |
📖 For Details see this [Blog post](https://community.home-assistant.io/t/contact-sensor-door-or-window-left-open-notification/652571) | |
domain: automation | |
source_url: https://gist.github.com/Raukze/27fe0c6bf6d91b8ae2ab5e11880509ba | |
input: | |
trigger_entity: | |
name: 🤖 Entity | |
description: | | |
The entity that will trigger the automation. This must be a `binary_sensor` or `input_boolean`. (e.g., `binary_sensor.fridge`) | |
selector: | |
entity: | |
domain: | |
- binary_sensor | |
- input_boolean | |
friendly_name: | |
name: 🏷️ Custom Device Friendly Name | |
description: What should we call the entity in the notification? (e.g. Fridge). Defaults the entities `friendly_name` if left empty. This also supports enumeration with [`binary_sensor` groups](https://www.home-assistant.io/integrations/group/#binary-sensor-light-and-switch-groups). | |
default: "" | |
selector: | |
text: | |
issue_state: | |
name: ⚠️ Issue State | |
description: | | |
The state that triggers the automation. Because this is a `binary_sensor`/`input_boolean`, it can only be on or off. Use the [developer tools](https://www.home-assistant.io/docs/tools/dev-tools/#states) to find the correct setting. | |
default: "on" | |
selector: | |
select: | |
options: | |
- "on" | |
- "off" | |
duration_issue_state: | |
name: ⏰ Time before alert | |
description: The amount of time that the device can be in the issue state before an alert is triggered. | |
default: | |
minutes: 10 | |
selector: | |
duration: | |
enable_day: true | |
condition_send_notification: | |
name: 🔍 Additional condition | |
description: Define a condition that is checked after the initial trigger before the notification is sent. | |
default: [] | |
selector: | |
condition: | |
delete_notification: | |
name: 🗑️ Delete notification when not in issue state anymore. | |
description: | | |
Do you want the notification to be deleted automatically when the device state is not in the issue state anymore. | |
default: true | |
selector: | |
boolean: | |
duration_from_issue_state: | |
name: ⏰ Time from issue state before alert removal | |
description: | | |
The amount of time that the device has not been in the issue state before the alert gets removed. | |
default: | |
seconds: 5 | |
selector: | |
duration: | |
enable_day: true | |
notify_services_string: | |
name: 📲 Notify Services | |
description: | | |
The service that will be called to deliver the notification. (e.g., `notify.mobile_app_my_phone`). | |
It also supports multiple services, separated by a comma. (e.g., `notify.mobile_app_my_phone,notify.mobile_app_my_spouse_phone`). | |
default: "notify.mobile_app_<your_device_id_here>" | |
selector: | |
text: | |
notification_click_url: | |
name: 🔗 Click URL | |
description: | | |
Where the user will be taken if they tap the notification. (e.g., `/lovelace/kitchen`). See [documentation](https://companion.home-assistant.io/docs/notifications/notifications-basic/#opening-a-url) for details. | |
default: "/lovelace/ROOM" | |
selector: | |
text: | |
notification_title: | |
name: 📢 Notification Title | |
description: The title of the notification. | |
default: "The {{ friendly_name }} was left open" | |
selector: | |
text: | |
notification_message: | |
name: 📬 Notification Message | |
description: | | |
The message of the notification. | |
default: "The {{ friendly_name }} was left open at {{ as_timestamp(initially_triggered_at) | timestamp_custom('%T', True) }}." | |
selector: | |
text: | |
repeat_notification: | |
name: 🔁 Repeat Notification | |
description: Whether or not a notification should be repeated after a certain time. | |
default: false | |
selector: | |
boolean: | |
time_between_repeat_notification: | |
name: ⏳ Time Between Repeat | |
description: Time period after which the repeat notification is triggered. | |
default: | |
minutes: 10 | |
selector: | |
duration: | |
enable_day: true | |
notification_icon_warning: | |
name: 🚨 Notification Icon (Android Only) | |
description: | | |
The icon that is shown when the issue is reported. (e.g., `mdi:fridge-alert`) See [documentation](https://companion.home-assistant.io/docs/notifications/notifications-basic/#opening-a-url) for details. | |
default: "alert" | |
selector: | |
select: | |
options: | |
- alert | |
- alert-circle | |
- door | |
- door-open | |
- motion-sensor | |
- fridge | |
- fridge-alert | |
- home | |
- home-alert | |
- home-assistant | |
- window-closed | |
- window-open | |
- window-open-variant | |
notification_color: | |
name: 🌈 Notification Color (Android Only) | |
description: The color of the notification. See [documentation](https://companion.home-assistant.io/docs/notifications/notifications-basic/#notification-color) for details. | |
default: "red" | |
selector: | |
select: | |
options: | |
- "red" | |
- "orange" | |
- "yellow" | |
- "green" | |
- "blue" | |
- "purple" | |
notification_persistent: | |
name: 📌 Persistent Notification (Android Only) | |
description: The notification cannot be closed manually. See [documentation](https://companion.home-assistant.io/docs/notifications/notifications-basic/#persistent-notification) for details. | |
default: false | |
selector: | |
boolean: | |
notification_interruption_level: | |
name: 🔔 Interruption Level (iOS Only) | |
description: | | |
The intrusiveness of the notification received. This also determines whether the notification will be delivered while the device is in a focus mode. See [documentation](https://companion.home-assistant.io/docs/notifications/notifications-basic/#interruption-level) for details. | |
default: "active" | |
selector: | |
select: | |
options: | |
- passive | |
- active | |
- time-sensitive | |
- critical | |
custom_action_issue_state: | |
name: ⚙️ Custom Action Issue State | |
description: Custom actions that are executed when the device state enters the issue state. | |
default: [] | |
selector: | |
action: | |
custom_action_from_issue_state: | |
name: ⚙️ Custom Action From Issue State | |
description: Custom actions that are executed when the device state exits the issue state. | |
default: [] | |
selector: | |
action: | |
mode: restart | |
max_exceeded: silent | |
variables: | |
custom_friendly_name: !input friendly_name | |
trigger_entity: !input trigger_entity | |
issue_state: !input issue_state | |
duration_issue_state: !input duration_issue_state | |
condition_send_notification: !input condition_send_notification | |
delete_notification: !input delete_notification | |
duration_from_issue_state: !input duration_from_issue_state | |
notify_services_string: !input notify_services_string | |
notification_click_url: !input notification_click_url | |
notification_title: !input notification_title | |
repeat_notification: !input repeat_notification | |
time_between_repeat_notification: !input time_between_repeat_notification | |
notification_icon_warning: !input notification_icon_warning | |
notification_color: !input notification_color | |
notification_interruption_level: !input notification_interruption_level | |
custom_action_issue_state: !input custom_action_issue_state | |
custom_action_from_issue_state: !input custom_action_from_issue_state | |
trigger: | |
- platform: state | |
entity_id: !input trigger_entity | |
to: !input issue_state | |
for: !input duration_issue_state | |
id: send_notification | |
- platform: state | |
entity_id: !input trigger_entity | |
from: !input issue_state | |
for: !input duration_from_issue_state | |
id: delete_notification | |
action: | |
- variables: | |
notify_services_list: "{{ notify_services_string.split(',') }}" | |
number_of_notify_services: "{{ notify_services_list | count }}" | |
notification_tag: "{{ trigger_entity[-20:] }}-{{ custom_friendly_name[-20:] }}-{{ notify_services_string[-20:] }}" | |
initially_triggered_at: "{{ now() }}" | |
- choose: | |
- conditions: | |
- condition: trigger | |
id: send_notification | |
- condition: !input condition_send_notification | |
sequence: | |
- repeat: | |
sequence: | |
- variables: | |
friendly_name: > | |
{% if custom_friendly_name != '' %} | |
{{ custom_friendly_name }} | |
{% else %} | |
{% set expanded_trigger_entity_list = expand(trigger_entity) | selectattr('state', 'eq', issue_state) | map(attribute='name') | join(', ') %} | |
{{ ' & '.join(expanded_trigger_entity_list.rsplit(', ', 1)) }} | |
{% endif %} | |
- parallel: | |
- repeat: | |
count: "{{ number_of_notify_services }}" | |
sequence: | |
- service: "{{ notify_services_list[repeat.index-1] }}" | |
data: | |
message: !input notification_message | |
title: !input notification_title | |
data: | |
clickAction: !input notification_click_url | |
url: !input notification_click_url | |
tag: "{{ notification_tag }}" | |
color: !input notification_color | |
notification_icon: "mdi:{{ notification_icon_warning }}" | |
push: | |
interruption-level: !input notification_interruption_level | |
persistent: !input notification_persistent | |
sticky: !input notification_persistent | |
- choose: [] | |
default: !input custom_action_issue_state | |
- if: | |
- "{{ repeat_notification }}" | |
then: | |
- delay: "{{ time_between_repeat_notification }}" | |
until: | |
- "{{ not repeat_notification }}" | |
- conditions: | |
- condition: trigger | |
id: delete_notification | |
- "{{ delete_notification }}" | |
sequence: | |
- parallel: | |
- repeat: | |
count: "{{ number_of_notify_services }}" | |
sequence: | |
- service: "{{ notify_services_list[repeat.index-1] }}" | |
data: | |
message: "clear_notification" | |
data: | |
tag: "{{ notification_tag }}" | |
- choose: [] | |
default: !input custom_action_from_issue_state |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment