Skip to content

Instantly share code, notes, and snippets.

@SeanCline
Last active July 9, 2023 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeanCline/5242d47e7b82dfa21c3f2739fffb682a to your computer and use it in GitHub Desktop.
Save SeanCline/5242d47e7b82dfa21c3f2739fffb682a to your computer and use it in GitHub Desktop.
A pair of scripts to provide a consistent API around sending and clearing notifications on Android, iPhone, and Dashboard.
alias: "Notification: Clear Notification"
mode: queued
max: 10
icon: mdi:bell-minus
fields:
tag:
name: Tag
description: A string identifying the message to clear/dismiss.
example: laundry_done_0F14AB
required: true
selector:
text: null
recipients:
name: Recipients
description: For which recipients the message is cleared.
required: true
selector:
select:
multiple: true
options:
- Dashboard
- Sean
- Joy
sequence:
- if:
- condition: template
value_template: "{{'Dashboard' in recipients}}"
then:
- service: persistent_notification.dismiss
data:
notification_id: "{{ tag }}"
alias: Dismiss persistent notification if "Dashboard" in recipients
- if:
- condition: template
value_template: "{{'Sean' in recipients}}"
then:
- service: notify.mobile_app_pixel_5
data:
message: clear_notification
data:
tag: "{{ tag }}"
alias: Clear for Sean if "Sean" in recipients
- if:
- condition: template
value_template: "{{ \"Joy\" in recipients }}"
then:
- service: notify.mobile_app_joys_iphone
data:
message: clear_notification
data:
tag: "{{ tag }}"
alias: Clear for Joy if "Joy" in recipients
alias: "Notifcation: Notify"
mode: queued
max: 10
icon: mdi:bell-plus
fields:
message:
name: Message
description: The message text.
example: Washing machine is done!
required: true
selector:
text: null
title:
name: Title
description: The title of the message.
example: Laundry
required: false
selector:
text: null
tag:
name: Tag
description: A string identifying the message for replacing/clearing later.
example: laundry_done_0F14AB
selector:
text: null
recipients:
name: Recipients
description: To whom the message is sent.
required: true
selector:
select:
multiple: true
options:
- Dashboard
- Sean
- Joy
icon:
name: Icon
description: Icon for supported platforms. (Android)
required: false
selector:
icon: null
sequence:
- if:
- condition: template
value_template: "{{'Dashboard' in recipients}}"
then:
- service: persistent_notification.create
data: >
{% set params = [('message', message)] %}
{% if title is defined %}
{% set params = params + [('title', title)] %}
{% endif %}
{% if tag is defined %}
{% set params = params + [('notification_id', tag)] %}
{% endif %}
{{ dict.from_keys(params) }}
alias: Create persistent notification if "Dashboard" in recipients
- if:
- condition: template
value_template: "{{'Sean' in recipients}}"
then:
- service: notify.mobile_app_pixel_5
data: >
{% set params = [('message', message)] %}
{% if title is defined %}
{% set params = params + [('title', title)] %}
{% endif %}
{% set data = [] %}
{% if tag is defined %}
{% set data = data + [('tag', tag)] %}
{% endif %}
{% if icon is defined %}
{% set data = data + [('notification_icon', icon)] %}
{% endif %}
{% if data|count > 0 %}
{% set params = params + [('data', dict.from_keys(data))] %}
{% endif %}
{{ dict.from_keys(params) }}
alias: Send to Sean if "Sean" in recipients
- if:
- condition: template
value_template: "{{ \"Joy\" in recipients }}"
then:
- service: notify.mobile_app_joys_iphone
data: >
{% set params = [('message', message)] %}
{% if title is defined %}
{% set params = params + [('title', title)] %}
{% endif %}
{% if tag is defined %}
{% set params = params + [('data', {'tag': tag})] %}
{% endif %}
{{ dict.from_keys(params) }}
alias: Send to Joy if "Joy" in recipients
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment