Repository navigation
Expand file tree
/
Copy pathnotify_engine.yaml
More file actions
executable file
·188 lines (183 loc) · 10.3 KB
/
Copy pathnotify_engine.yaml
File metadata and controls
executable file
·188 lines (183 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
######################################################################
# @CCOSTAN - Follow Me on X
# For more info visit https://www.vcloudinfo.com/click-here
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# -------------------------------------------------------------------
# Notification Engine Scripts - Flexible push helpers for family devices.
# Related Issue: 1773
# Compose messages from value1/value2/value3 with optional actions.
# -------------------------------------------------------------------
# Notes: Optional notification tags let recovery actions target a specific push.
# Tags control replacement; groups remain visual notification categories.
# Notes: Known groups receive colored MDI icons; other callers retain their payload.
# Explicit notification_icon/icon_url overrides are shared by both helpers.
# An empty notification_icon disables the group preset; iOS icons require a title.
# Notes: Only supplied actions become buttons; one-button callers omit the second.
# Docs: https://companion.home-assistant.io/docs/notifications/notifications-basic/#notification-icon-and-color
# Video Tutorial: https://youtu.be/mK1wdpxhLbM
# Notification icons video: https://youtu.be/TMfdxv-WprM
# Notification icons blog: https://www.vcloudinfo.com/2026/10/home-assistant-ios-notification-icons.html
######################################################################
### Script for Sending Notifications to Mobile Phones
# This script (`notify_engine`) and its variant (`notify_engine_two_button`) are designed to send
# customized notifications to specified recipients in Home Assistant.
# - The script dynamically chooses the notification service based on the 'who' parameter,
# allowing targeting individuals like Stacey, Carlo, or groups like family or parents.
# - Notifications include a title and a composite message from 'value1', 'value2', and 'value3'.
# - The script can optionally attach camera snapshots, specify notification groups, and set interruption levels.
# Usage:
# To call this script, specify the action as `script.notify_engine` or `script.notify_engine_two_button`
# and provide the necessary data parameters:
# - 'title': The notification title.
# - 'value1', 'value2', 'value3': Components of the message.
# - 'who': Recipient identifier (e.g., 'stacey', 'carlo', 'paige', 'family', 'parents').
# - 'camera_entity': Camera entity ID for snapshots (optional).
# - 'group': Notification group (optional, defaults to 'information').
# - 'tag': Stable notification identity for replacement or clearing (optional).
# - 'level': Interruption level for the notification (optional, defaults to 'active').
# - 'notification_icon': MDI icon override (optional; empty disables the group preset).
# - 'icon_url': Public or /local/ icon image (optional; takes precedence over MDI).
# - 'notification_icon_color': MDI glyph hex color (optional; app defaults to white).
# - 'color': MDI background hex color (optional; defaults to the group's color).
# Known groups: Medicine, Garbage_Reminders, Welcome_Home, maintenance, Phyn,
# Tesla_Model_Y, Tesla_Tire_Pressure, Printer, vacation, royal_caribbean_price_drop.
# Also: 360_alerts, Battery_Alert, water_heater, RemoteLR,
# Tesla_Charge_Rate_Alarm, JuiceBox_Proxy_Offline.
# clear_notification commands do not receive icon fields.
# The 'notify_engine_two_button' variant includes additional parameters for two interactive buttons:
# - 'title1', 'title2': Titles for the action buttons.
# - 'action1', 'action2': Actions to be performed when buttons are pressed.
# - 'icon1', 'icon2': Icons for the buttons (optional).
# - 'destructive1', 'destructive2': Boolean flags to mark buttons as destructive (optional).
notify_engine:
alias: Notify Engine
mode: parallel
max: 20
sequence:
- condition: state
entity_id: input_boolean.text_notifications
state: 'on'
- variables:
notify_service: >-
{% if who | default('family', true) == 'stacey' %}
notify.mobile_app_stacey_iphone11
{% elif who | default('family', true) == 'carlo' %}
notify.mobile_app_carlo_maxpro
{% elif who | default('family', true) == 'parents' %}
notify.ios_parents
{% else %}
notify.ios_family
{% endif %}
notify_message: >-
{{ ' '.join([
value1 | default('', true),
value2 | default('', true),
value3 | default('', true)
]) | trim }}
has_actions: >-
{{ action1 | default('', true) | length > 0
or action2 | default('', true) | length > 0 }}
notify_data: >-
{% set payload = {
'group': group | default('information', true),
'entity_id': camera_entity | default('', true),
'push': {'interruption-level': level | default('active', true)}
} %}
{% set notification_tag = tag | default('', true) | string | trim %}
{% set payload = dict(payload, tag=notification_tag) if notification_tag else payload %}
{% set styles = {
'360_alerts': {'notification_icon': 'mdi:map-marker-radius', 'color': '#1565C0'},
'battery_alert': {'notification_icon': 'mdi:battery-alert-variant-outline', 'color': '#C2410C'},
'water_heater': {'notification_icon': 'mdi:water-boiler-alert', 'color': '#C2410C'},
'remotelr': {'notification_icon': 'mdi:remote', 'color': '#6A1B9A'},
'tesla_charge_rate_alarm': {'notification_icon': 'mdi:ev-station', 'color': '#C62828'},
'juicebox_proxy_offline': {'notification_icon': 'mdi:ev-station', 'color': '#C2410C'},
'medicine': {'notification_icon': 'mdi:pill', 'color': '#6A1B9A'},
'garbage_reminders': {'notification_icon': 'mdi:trash-can-outline', 'color': '#2E7D32'},
'welcome_home': {'notification_icon': 'mdi:home-heart', 'color': '#00796B'},
'maintenance': {'notification_icon': 'mdi:tools', 'color': '#455A64'},
'phyn': {'notification_icon': 'mdi:water-alert', 'color': '#C62828'},
'tesla_model_y': {'notification_icon': 'mdi:car-electric', 'color': '#1565C0'},
'tesla_tire_pressure': {'notification_icon': 'mdi:car-tire-alert', 'color': '#C2410C'},
'printer': {'notification_icon': 'mdi:printer', 'color': '#455A64'},
'vacation': {'notification_icon': 'mdi:palm-tree', 'color': '#00796B'},
'royal_caribbean_price_drop': {'notification_icon': 'mdi:ferry', 'color': '#0277BD'}
} %}
{% set style = styles.get(group | default('information', true) | string | lower | trim, {}) %}
{% set icon = (notification_icon if notification_icon is defined and notification_icon is not none
else style.get('notification_icon', '')) | default('', true) | string | trim %}
{% set image_icon = icon_url | default('', true) | string | trim %}
{% if (icon or image_icon) and title | default('', true) | string | trim
and notify_message != 'clear_notification' %}
{% if icon %}
{% set payload = dict(payload, notification_icon=icon) %}
{% set glyph_color = notification_icon_color | default('', true) | string | trim %}
{% set background_color = color | default(style.get('color', ''), true) | string | trim %}
{% if glyph_color %}
{% set payload = dict(payload, notification_icon_color=glyph_color) %}
{% endif %}
{% if background_color %}
{% set payload = dict(payload, color=background_color) %}
{% endif %}
{% endif %}
{% if image_icon %}
{% set payload = dict(payload, icon_url=image_icon) %}
{% endif %}
{% endif %}
{{ payload }}
- choose:
- conditions: "{{ has_actions }}"
sequence:
- service: "{{ notify_service }}"
data:
title: "{{ title | default('', true) }}"
message: "{{ notify_message }}"
data: >-
{{ dict(notify_data, actions=[
{
'title': title1 | default('', true),
'action': action1 | default('', true),
'icon': icon1 | default('sfsymbols:house.circle', true),
'destructive': destructive1 | default(false, true)
},
{
'title': title2 | default('', true),
'action': action2 | default('', true),
'icon': icon2 | default('sfsymbols:house.circle', true),
'destructive': destructive2 | default(false, true)
}
] | rejectattr('action', 'eq', '') | list) }}
default:
- service: "{{ notify_service }}"
data:
title: "{{ title | default('', true) }}"
message: "{{ notify_message }}"
data: "{{ notify_data }}"
notify_engine_two_button:
alias: Notify Engine Two Button
mode: parallel
max: 20
sequence:
- service: script.notify_engine
data:
title: "{{ title | default('', true) }}"
value1: "{{ value1 | default('', true) }}"
value2: "{{ value2 | default('', true) }}"
value3: "{{ value3 | default('', true) }}"
who: "{{ who | default('family', true) }}"
group: "{{ group | default('information', true) }}"
tag: "{{ tag | default('', true) }}"
level: "{{ level | default('active', true) }}"
camera_entity: "{{ camera_entity | default('', true) }}"
notification_icon: "{{ notification_icon | default(none) }}"
icon_url: "{{ icon_url | default('', true) }}"
notification_icon_color: "{{ notification_icon_color | default('', true) }}"
color: "{{ color | default('', true) }}"
title1: "{{ title1 | default('', true) }}"
action1: "{{ action1 | default('', true) }}"
icon1: "{{ icon1 | default('sfsymbols:house.circle', true) }}"
destructive1: "{{ destructive1 | default(false, true) }}"
title2: "{{ title2 | default('', true) }}"
action2: "{{ action2 | default('', true) }}"
icon2: "{{ icon2 | default('sfsymbols:house.circle', true) }}"
destructive2: "{{ destructive2 | default(false, true) }}"