Skip to content

Instantly share code, notes, and snippets.

@JohnONolan
Last active December 23, 2021 15:38
Show Gist options
  • Select an option

  • Save JohnONolan/a8e96a0a66c2dc6ede6b9e07654848b1 to your computer and use it in GitHub Desktop.

Select an option

Save JohnONolan/a8e96a0a66c2dc6ede6b9e07654848b1 to your computer and use it in GitHub Desktop.
blueprint:
name: Send a notification when vibration is detected
description: >
This automation blueprint creates a notifications if vibration is detected and sends a notification to your phone.
Optionally you can define a binary sensor that will block the automation from running when state is ON.
For Example do not run when somebody is home (you can use the people_home template example).
Furthermore you have the option to make the notification critical or high priority and to collapse/overwrite or not.
Required entities:
- Vibration sensor (binary_sensor)
- Notify device entity (mobile_app).
Optional entities:
- Blocking entity (any entity with state on/off), example people home or not. Entity in state ON will block the automation. If needed you can create a template sensor to inverse states.
- Notification title & message
- URI for clickAction on the notification. For example a lovelace view such as /lovelace/cctv, this will open in the app.
- Name for the channel, different channels can have different notifications settings, such as sound etc.
- Name for group (Android) or grouping name (iOS), to group similar notifications together
- Overwrite (collapse) similar notifications (iOS): Yes/No
- Should the notification be critical (iOS) or High Priority / TTL 0 (Android)? Yes/No (However on iOS this will defeat the collapse of grouping)
domain: automation
input:
vibration_sensor:
name: Vibration sensor
description: The sensor wich triggers the notification (domain binary_sensor).
selector:
entity:
domain: binary_sensor
notify_device:
name: Device to notify
description: Device that runs the official Home Assistant app to receive notifications.
selector:
device:
integration: mobile_app
is_ios:
name: Is it an iOS device?
description: Toggle if your selected device runs iOS, default is Android
selector:
boolean:
default: false
blocker_entity:
name: '(OPTIONAL) Blocking entity'
description: If this entity state is on, it will prevent the automation from running. E.g. somebody is home (binary_sensor.people_home).
default:
selector:
entity:
notification_title:
name: Notification title (Optional)
description: 'Default: "Vibration alert!"'
default: "Vibration alert!"
notification_message:
name: Notification message (Optional)
description: 'Default: "{{ vibration_sensor_name }} detected vibration!"'
default: "{{ vibration_sensor_name }} detected vibration!"
clickAction:
name: ClickAction URI (Optional)
description: An URI to open when you click on the notification, can be an external URI (https://www.google.com) or an internal URI to a lovelace dashboard or view (/lovelace/cctv).
default: ""
group_name:
name: Name of the group
description: To group notifications together for 1 automation. For instance if you want to have multiple automations but seperate them use unique names per automation.
default: "alarm_vibration"
channel_name:
name: Name of the channel
description: Different channels can have different notifications settings, such as sound etc.
default: "alarm_vibration"
overwrite_similar:
name: Overwrite similar
description: Toggle on if you want to a new notification in the same group to overwrite the previous one (iOS).
selector:
boolean:
default: false
is_critical:
name: Should the notification be critical (iOS) or High Priority (Android)?
description: Toggle off it you don't want critical or high priority notifications.
selector:
boolean:
default: true
trigger:
platform: state
entity_id: !input vibration_sensor
from: "off"
to: "on"
variables:
vibration_sensor: !input vibration_sensor
vibration_sensor_name: "{{ states[vibration_sensor].name }}"
notify_device: !input notify_device
is_ios: !input is_ios
notification_title: !input notification_title
notification_message: !input notification_message
blocker_entity: !input blocker_entity
clickAction: !input clickAction
is_critical: !input is_critical
overwrite_similar: !input overwrite_similar
channel_name: !input channel_name
group_name: !input group_name
condition:
- condition: template
value_template: >
{{ (blocker_entity == none) or (states[blocker_entity].state == 'off') }}
action:
- device_id: !input notify_device
domain: mobile_app
type: notify
title: "{{ notification_title }}"
message: "{{ notification_message }}"
data: >
{% if is_ios %}
{% if is_critical %}
{% set platform_data = { "channel": "%s", "url": "%s", "push": { "category": "%s", "sound": { "name": "default", "critical": 1, "volume": 1.0 } } } | format(channel_name, clickAction, group_name) %}
{% else %}
{% if overwrite_similar %}
{% set platform_data = { "channel": "%s", "url": "%s", "apns_headers": { "apns-collapse-id": "%s" }, "push": { "category": "%s", "sound": { "name": "default", "volume": 1.0 } } } | format(channel_name, clickAction, group_name, group_name) %}
{% else %}
{% set platform_data = { "channel": "%s", "url": "%s", "push": { "category": "%s", "sound": { "name": "default", "volume": 1.0 } } } | format(channel_name, clickAction, group_name) %}
{% endif %}
{% endif %}
{% else %}
{% if is_critical %}
{% if overwrite_similar %}
{% set platform_data = { "tag": "%s", "channel": "%s", "group": "%s", "ttl": 0, "priority": "high", "clickAction": "%s"} | format(group_name, channel_name, group_name, clickAction) %}
{% else %}
{% set platform_data = { "channel": "%s", "ttl": 0, "priority": "high", "clickAction": "%s"} | format(channel_name, clickAction) %}
{% endif %}
{% else %}
{% if overwrite_similar %}
{% set platform_data = { "tag": "%s", "channel": "%s", "group": "%s", "clickAction": "%s"} | format(group_name, channel_name, group_name, clickAction) %}
{% else %}
{% set platform_data = { "channel": "%s", "clickAction": "%s"} | format(channel_name, clickAction) %}
{% endif %}
{% endif %}
{% endif %}
{{ platform_data }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment