-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotify_me.yaml
More file actions
150 lines (145 loc) · 4.17 KB
/
notify_me.yaml
File metadata and controls
150 lines (145 loc) · 4.17 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
alias: Notify Me
fields:
service:
selector:
select:
options:
- Home Assistant
- Home Assistant Persistent
- Pushover
- WhatsApp
multiple: true
name: Service
default: Home Assistant
required: true
message:
selector:
template: {}
name: Message
required: true
title:
selector:
template: {}
name: Title
data:
selector:
object: {}
name: Data
url:
selector:
template: {}
name: URL
description: ""
sequence:
- data:
Notify_Me: debug
action: logger.set_level
- variables:
service: >-
{% set valid_services = ['Home Assistant', 'Home Assistant Persistent',
'Pushover', 'WhatsApp'] %} {% if service is not defined or service == []
%}
{% set service = ['Home Assistant'] %}
{% elif service is string %}
{% set service = [service] %}
{% endif %}
{% set ns = namespace(result=[]) %} {% for s in service %}
{% if s in valid_services %}
{% set ns.result = ns.result + [s] %}
{% endif %}
{% endfor %}
{% if ns.result | length == 0 %}
{% set ns.result = ['Home Assistant'] %}
{% endif %}
{{ ns.result }}
- data:
level: debug
message: |-
service: {{ service }}
message: {{ message }}
title: {{ title }}
data: {{ data }}
url: {{ url }}
logger: Notify_Me
action: system_log.write
- alias: Home Assistant
if:
- condition: template
value_template: |-
{{
'Home Assistant' in service
}}
then:
- variables:
data: |-
{% set data = data if data is defined and data is mapping else {} %}
{% if url is defined and url is string %}
{% set actions = data['actions'] if (data['actions'] is defined and data['actions'] is list) else [] %}
{% set actions = actions + [ {'action': 'URI', 'title': 'Open URL', 'url': url} ] %}
{% set data = dict.from_keys(data.items() | rejectattr('0', 'in', ['actions'] ) | list + [ ['actions', actions] ] ) %}
{% endif %}
{{ data }}
- action: notify.group_my_ha_companion_app_s
metadata: {}
data:
message: "{{ message }}"
title: "{{ title }}"
data: "{{ data }}"
- alias: Home Assistant Persistent
if:
- condition: template
value_template: "{{ 'Home Assistant Persistent' in service }}"
then:
- variables:
message: |-
{% if url is defined and url is string %}
{{ message + '\n\n' + url }}
{% else %}
{{ message }}
{% endif %}
- action: notify.persistent_notification
metadata: {}
data:
message: "{{ message }}"
title: "{{ title }}"
- alias: Pushover
if:
- condition: template
value_template: "{{ 'Pushover' in service }}"
then:
- variables:
data: |-
{% set temp = [] %}
{% if data['priority'] is defined %}
{% set temp = [ ['priority', data['priority']] ] %}
{% if data['priority'] | int == 2 %}
{% set temp = temp + [ ['retry', 60], ['expire', 300] ] %}
{% endif %}
{% endif %}
{% if url is defined and url is string %}
{% set temp = temp + [ ['url', url] ] %}
{% endif %}
{{ dict.from_keys(temp) }}
- action: notify.pushover
metadata: {}
data:
message: "{{ message }}"
title: "{{ title }}"
data: "{{ data }}"
- alias: WhatsApp
if:
- condition: template
value_template: "{{ 'WhatsApp' in service }}"
then:
- variables:
message: |-
{% if url is defined and url is string %}
{{ message + '\n\n' + url }}
{% else %}
{{ message }}
{% endif %}
- action: script.send_whatsapp_message_to_me
metadata: {}
data:
message: "{{ message }}"
title: "{{ title }}"