-
Notifications
You must be signed in to change notification settings - Fork 14
/
notifiers.yaml
143 lines (139 loc) · 4.07 KB
/
notifiers.yaml
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
# General notification engine that adds timestamps
notify:
alias: Notify
fields:
format:
description: The timestamp format for persistent notifications & notifications. Annoucements do not have a timestamp.
example: "%-I:%M:%S %p"
default: "%-I:%M:%S %p"
selector:
text:
type: text
persistent_notification:
description: On/Off for Persistent Notifications
default: on
example: on
required: false
selector:
boolean:
title:
description: Title of the persistent notification.
example: "Title"
default: ""
selector:
text:
type: text
message:
description: Message to be sent/annouced.
example: "Hello"
required: true
selector:
text:
type: text
image:
description: Local image.
example: "local\\images\\home.jpg"
default: None
selector:
text:
type: url
notify: ¬ify_homeowners
description: Devices to notify.
example: notify.mobile_app_petro
selector:
select:
options:
- label: Petro
value: notify.mobile_app_petro
- label: Lambo
value: notify.mobile_app_lindsays_iphone
- label: Home Owners
value: notify.homeowners
variables:
timestamp: >
{% set t = now() %}
{% if format is defined %}
{{ None if format is none else t.strftime(format) }}
{% else %}
{{ t.strftime("%-I:%M:%S %p") }}
{% endif %}
persistent_notification: >
{{ persistent_notification | default(true) }}
out_notify: "{{ notify | default('notify.homeowners') }}"
external_url: !secret external_url
url: >
{% if image | default %}
{{ external_url }}/{{ image.replace('\\', '/') }}
{% endif %}
persistent_notification_data: >
{% set ret = namespace(data=[]) %}
{% if title | default %}
{% set ret.data = ret.data +[('title', title)] %}
{% endif %}
{% if message | default %}
{% set ret.data = ret.data +[('message', '[{}] {}'.format(timestamp, message) if timestamp else message)] %}
{% endif %}
{{ dict.from_keys(ret.data) or {'message': 'No Message Provided'} }}
notification_data: >
{% if image | default %}
{{ dict(data={'attachment': {'url': url}}, **persistent_notification_data)}}
{% else %}
{{ persistent_notification_data }}
{% endif %}
sequence:
- choose:
- conditions: "{{ persistent_notification }}"
sequence:
- service: persistent_notification.create
data: "{{ persistent_notification_data }}"
- choose:
- conditions: "{{ out_notify.startswith('notify.') }}"
sequence:
- service: "{{ out_notify }}"
data: "{{ notification_data }}"
event:
alias: Event
fields:
card:
description: The timestamp format for persistent notifications & notifications. Annoucements do not have a timestamp.
notify: *notify_homeowners
variables:
service_data:
format: None
title: >
{{ card.primary | default('Unknown') }}
message: >
{{ card.secondary | default('Unknown') }}
image: >
{{ card.picture | default('local/images/home.jpg') }}
sequence:
- service: script.notify
data: "{{ service_data }}"
events:
alias: Events
fields:
test:
description: Test days ahead
example: 50
selector:
number:
min: 0
max: 730
mode: box
notify: *notify_homeowners
variables:
days_ahead: [183, 90, 60, 30, 14, 7, 1]
targets: >
{{ days_ahead + [ test ] if test is defined else days_ahead }}
events: >
{{ state_attr('sensor.lambosino_s_random_events', 'events') | selectattr('days', 'in', targets) | list }}
sequence:
- condition: template
value_template: "{{ events | count > 0 }}"
- repeat:
for_each: "{{ events }}"
sequence:
- service: script.event
data:
card: "{{ repeat.item.card }}"
notify: "{{ notify | default }}"