-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
to-do_chore_notifications.yaml
274 lines (269 loc) · 12.6 KB
/
to-do_chore_notifications.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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
blueprint:
name: To-do Chore Notifications
author: birdwing
homeassistant:
min_version: 2024.6.0
description: >
**Create actionable notifications from a Home Assistant To-do list!**
These actionable notifications are sent every day at the time you specify in *Notification Time*.
They are sent to the every device you specify in *Devices to Notify*.
It will generate 1 notification for each passed due item, with the ability to mark the item as completed right from the notification!
**When a Task is marked complete (from the notification):**
- The notifications will be **cleared from all devices it was sent to**!
This way, if a task is marked as done noone has a notification telling them to complete it.
- Through the **When chore is completed.** actions you can specify any actions you would like to happen after a task is marked as done.
domain: automation
input:
section_standard:
name: Standard Options
description: Typical options that all users need to set for the notifications to work.
collapsed: false
input:
input_notification_time:
name: Notification Time
description: Time of day to send the notifications.
selector:
time:
input_use_todo_time:
name: Use To-do Task Times
description: >
If selected notifications will be sent out based on the time on the To-do item.
If the To-do item doesn't have a time it will use the notification time.
By default the blueprint will check every 15 minutes for tasks that are due within the *next* 15 minutes.
So notifications will go out before the task is due.
How often tasks are checked can be altered in the Advanced Notification Options section.
default: false
selector:
boolean:
input_todo_list:
name: To-do List
description: Select the To-do list you want to create Chore notifications from.
selector:
entity:
domain: todo
input_notify_devices:
name: Mobile App Devices to Notify
description: What mobile_app devices do you want to receive the notifications?
default: []
selector:
device:
integration: mobile_app
multiple: true
section_advanced_notification:
name: Advanced Notification Options
description: More advanced options that add complexity and flexibility for less typical setups.
collapsed: true
input:
input_notify_action_names:
name: Names of Notify Actions/Services
description: What custom [Notify Groups](https://www.home-assistant.io/integrations/group/#notify-groups) and other non-mobile-apps do you want to receive the notifications? This should be the group name, which is everything after `notify.` for the corresponding Action.
default: []
selector:
text:
multiline: false
multiple: true
input_list_check_frequency:
name: Time Check Frequency
description: >
How often to check for tasks that are due, in minutes. (Default: 15)
**Use Caution** checking too often can put a strain on your system, especially if you have large To-do lists.
If you have a large To-do list and are having issues, try setting it to a higher value.
default: 15
selector:
number:
min: 1
max: 59
unit_of_measurement: "minutes"
mode: box
section_post_chore_actions:
name: Post-Chore Actions
description: Actions that are run after a chore is completed.
collapsed: true
input:
# This input does not follow the input_* naming convention of the others.
# Perhaps it should be made consistent in a future release,
# but that would be a breaking change.
after_completed:
name: When chore is completed.
description: >
If you need something to happen after a chore is completed you can do so here.
**Note:** These actions will only run if the chore is marked done *via the notification*.
The **todo_item** variable will contain the name of the item on the To-do list that was marked completed.
This way to can use conditions to specify an action for a particular chore. For example you could use a counter helper to keep track of how much of something is "in stock" and when a specific chore is completed increment or decrement the counter.
selector:
action:
default:
variables:
use_todo_time: !input input_use_todo_time
selected_todo_list: !input input_todo_list
notification_group: "{{selected_todo_list ~ ' chores'}}"
notify_mobile_devices: !input input_notify_devices
notify_action_names: !input input_notify_action_names
notify_action_full_names: |
{# If only list comprehensions worked... sigh. #}
{% set result_namespace = namespace(items=[]) %}
{% for mobile_device in notify_mobile_devices %}
{% set result_namespace.items = result_namespace.items + ["notify.mobile_app_" + slugify(device_attr(mobile_device, 'name'))] %}
{% endfor %}
{% for action_name in notify_action_names %}
{% set result_namespace.items = result_namespace.items + ["notify." + action_name] %}
{% endfor %}
{{ result_namespace.items }}
time_triggered: "{{strptime(now().strftime('%Y-%m-%d %H:%M %z'), '%Y-%m-%d %H:%M %z')}}"
list_check_frequency: !input input_list_check_frequency
trigger_variables:
list_check_frequency: !input input_list_check_frequency
trigger:
- platform: time
at: !input input_notification_time
id: Notify
- platform: template
id: TimeNotify
value_template: "{{ now().minute % list_check_frequency == 0 }}"
enabled: !input input_use_todo_time
- platform: event
event_type: mobile_app_notification_action
id: Mark
event_data: {}
condition: []
action:
- choose:
- conditions:
- condition: trigger
id:
- Notify
- TimeNotify
- condition: numeric_state
entity_id: !input input_todo_list
above: 0
sequence:
- service: todo.get_items
metadata: {}
data:
status: needs_action
target:
entity_id: !input input_todo_list
response_variable: chores
- alias: Go through every To-do Item
repeat:
for_each: "{{ chores[selected_todo_list]['items'] }}"
sequence:
- variables:
chore: "{{ repeat.item }}"
chore_has_time: "{{ repeat.item.due | length > 10 }}"
chore_due_datetime: "{{ repeat.item.due | default(0) | as_datetime | as_local }}"
chore_due_date: "{{ strptime((chore_due_datetime | as_datetime).strftime('%Y-%m-%d'), '%Y-%m-%d') | as_local }}"
chore_due_time: "{{ strptime((chore_due_datetime | as_datetime).strftime('%H:%M %z'), '%H:%M %z') }}"
- if:
- condition: or
conditions:
- alias: To-do Task Time Conditions
condition: and
conditions:
- condition: trigger
id:
- TimeNotify
- alias: Task has a time set and we are using task time
condition: template
value_template: "{{ chore_has_time }}"
- alias: Task due date <= Time Triggered
condition: template
value_template: >-
{{ chore_due_date | as_datetime <= time_triggered | as_datetime}}
- alias: Task due time >= Time Triggered
condition: template
value_template: >-
{{ chore_due_time | as_datetime
>= strptime((time_triggered | as_datetime).strftime('%H:%M %z'), '%H:%M %z')
}}
- alias: Task due time < next check time
condition: template
value_template: >-
{{ chore_due_time | as_timestamp
< strptime((time_triggered | as_datetime).strftime('%H:%M %z'), '%H:%M %z') | as_timestamp
+ (list_check_frequency * 60)
}}
- alias: Notification Time Conditions
condition: and
conditions:
- condition: trigger
id:
- Notify
- alias: Task has no date/time or it's <= Time Triggered
condition: template
value_template: >-
{{ chore_due_date | as_datetime <= time_triggered | as_datetime}}
- alias: Task does not have a time set and we are using task time OR we are not using task time
condition: template
value_template: >-
{{ (use_todo_time and chore_has_time == false)
or (use_todo_time == false)
}}
then:
- alias: Send notification to each device
repeat:
for_each: "{{ notify_action_full_names }}"
sequence:
- service: "{{ repeat.item }}"
data:
title: |
{{ 'Chore - ' ~ chore.summary }}
message: >
{{ chore.description | default('You have a chore to complete!') }}
data:
actions:
- action: "{{ selected_todo_list ~ ' ' ~ chore.uid }}"
title: Mark Done!
group: "{{ notification_group }}"
tag: "{{ selected_todo_list ~ ' ' ~ chore.uid }}"
action_data:
group: "{{ notification_group }}"
title: "{{ 'Chore - ' ~ chore.summary }}"
tag: "{{ selected_todo_list ~ ' ' ~ chore.uid }}"
alias: Time to Send Notifications
- conditions:
- condition: trigger
id:
- Mark
- condition: template
value_template: >
{% if 'action_data' in trigger.event.data %}
{{ trigger.event.data.action_data.group == notification_group }}
{% else %}
{{ trigger.event.data.group == notification_group }}
{% endif %}
sequence:
- variables:
todo_item: >
{% if 'action_data' in trigger.event.data %}
{{ trigger.event.data.action_data.title[8:] }}
{% else %}
{{ trigger.event.data.title[8:] }}
{% endif %}
notification_tag: >
{% if 'action_data' in trigger.event.data %}
{{ trigger.event.data.action_data.tag }}
{% else %}
{{ trigger.event.data.tag }}
{% endif %}
- service: todo.update_item
metadata: {}
data:
item: "{{ todo_item }}"
status: completed
target:
entity_id: !input input_todo_list
- alias: Clear All Notifications for this Chore, in case it was sent to more than 1 phone.
repeat:
for_each: "{{ notify_action_full_names }}"
sequence:
- service: "{{ repeat.item }}"
data:
message: clear_notification
data:
tag: "{{ notification_tag }}"
- choose: []
default: !input after_completed
alias: Chore Marked as Completed
mode: queued
max: 10