-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjottick_automations.yaml
More file actions
924 lines (897 loc) · 38.6 KB
/
jottick_automations.yaml
File metadata and controls
924 lines (897 loc) · 38.6 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
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
# =============================================================================
# JotTick HOME ASSISTANT INTEGRATION VIA HACS
# Copy and paste this at the bottom of automations.yaml
#
# =============================================================================
- id: jottick_auto_update_note_picker_fixed
alias: 'JotTick: Auto Update Note Picker'
trigger:
- platform: state
entity_id:
- sensor.jottick_total_notes
- platform: homeassistant
event: start
action:
- service: input_select.set_options
target:
entity_id: input_select.jottick_note_picker
data:
options: "{%- set ns = namespace(items=['-- Pick a note --'], titles={}) -%}
{%- set notes = states.sensor | selectattr('name', 'search', '^JotTick Note:')
| rejectattr('state', 'eq', 'unavailable') | list -%} {%- for state in notes
-%}\n {%- set title = state.state -%}\n {%- if title in ns.titles -%}\n
\ {%- set ns.titles = dict(ns.titles, **{title: ns.titles[title] + 1}) -%}\n
\ {%- else -%}\n {%- set ns.titles = dict(ns.titles, **{title: 1}) -%}\n
\ {%- endif -%}\n{%- endfor -%} {%- set ns2 = namespace(counts={}) -%} {%-
for state in notes | sort(attribute='attributes.updated', reverse=true) -%}\n
\ {%- set title = state.state -%}\n {%- set note_id = state_attr(state.entity_id,
'note_id') -%}\n {%- if ns.titles[title] > 1 -%}\n {%- set current_count
= ns2.counts.get(title, 0) + 1 -%}\n {%- set ns2.counts = dict(ns2.counts,
**{title: current_count}) -%}\n {%- set display_title = title ~ ' (' ~
note_id[-6:] ~ ')' -%}\n {%- else -%}\n {%- set display_title = title
-%}\n {%- endif -%}\n {%- set ns.items = ns.items + [display_title] -%}\n{%-
endfor -%} {{ ns.items }}"
- id: jottick_auto_update_checklist_picker_fixed
alias: 'JotTick: Auto Update Checklist Picker'
trigger:
- platform: state
entity_id:
- sensor.jottick_total_checklists
- platform: homeassistant
event: start
action:
- service: input_select.set_options
target:
entity_id: input_select.jottick_checklist_picker
data:
options: "{%- set ns = namespace(items=['-- Pick a checklist --'], titles={})
-%} {%- set lists = states.sensor | selectattr('name', 'search', '^JotTick List:')
| rejectattr('state', 'eq', 'unavailable') | list -%} {%- for state in lists
-%}\n {%- set title = state_attr(state.entity_id, 'title') -%}\n {%- if
title -%}\n {%- if title in ns.titles -%}\n {%- set ns.titles = dict(ns.titles,
**{title: ns.titles[title] + 1}) -%}\n {%- else -%}\n {%- set ns.titles
= dict(ns.titles, **{title: 1}) -%}\n {%- endif -%}\n {%- endif -%}\n{%-
endfor -%} {%- set ns2 = namespace(counts={}) -%} {%- for state in lists |
sort(attribute='attributes.updated', reverse=true) -%}\n {%- set title =
state_attr(state.entity_id, 'title') -%}\n {%- if title -%}\n {%- set
list_id = state_attr(state.entity_id, 'checklist_id') -%}\n {%- if ns.titles[title]
> 1 -%}\n {%- set current_count = ns2.counts.get(title, 0) + 1 -%}\n
\ {%- set ns2.counts = dict(ns2.counts, **{title: current_count}) -%}\n
\ {%- set display_title = title ~ ' (' ~ list_id[-6:] ~ ')' -%}\n {%-
else -%}\n {%- set display_title = title -%}\n {%- endif -%}\n {%-
set ns.items = ns.items + [display_title] -%}\n {%- endif -%}\n{%- endfor
-%} {{ ns.items }}"
- id: jottick_load_note_when_picked
alias: 'JotTick: Load Note When Picked'
trigger:
- platform: state
entity_id: input_select.jottick_note_picker
condition:
- condition: template
value_template: '{{ trigger.to_state.state not in [''unknown'', ''unavailable'',
''-- Pick a note --''] }}'
action:
- variables:
selected_option: '{{ states(''input_select.jottick_note_picker'') }}'
selected_title: "{%- if '(' in selected_option and selected_option.endswith(')')
-%}\n {{ selected_option.split(' (')[0] }}\n{%- else -%}\n {{ selected_option
}}\n{%- endif -%}"
note_id_hint: "{%- if '(' in selected_option and selected_option.endswith(')')
-%}\n {{ selected_option.split('(')[-1].rstrip(')') }}\n{%- else -%}\n \n{%-
endif -%}"
note_entity: "{%- for s in states.sensor -%}\n {%- if s.name.startswith('JotTick
Note:') -%}\n {%- if note_id_hint and state_attr(s.entity_id, 'note_id')
and state_attr(s.entity_id, 'note_id').endswith(note_id_hint) -%}\n {{
s.entity_id }}\n {%- elif not note_id_hint and s.state == selected_title
-%}\n {{ s.entity_id }}\n {%- endif -%}\n {%- endif -%}\n{%- endfor
-%}"
- condition: template
value_template: '{{ note_entity | trim != '''' }}'
- service: input_text.set_value
target:
entity_id: input_text.jottick_note_id
data:
value: '{{ state_attr(note_entity, ''note_id'') or '''' }}'
- service: input_text.set_value
target:
entity_id: input_text.jottick_edit_note_title
data:
value: '{{ states(note_entity) }}'
- service: input_text.set_value
target:
entity_id: input_text.jottick_edit_note_content
data:
value: '{{ state_attr(note_entity, ''content'') or '''' }}'
- id: jottick_load_checklist_when_picked
alias: 'JotTick: Load Checklist When Picked'
trigger:
- platform: state
entity_id: input_select.jottick_checklist_picker
condition:
- condition: template
value_template: '{{ trigger.to_state.state not in [''unknown'', ''unavailable'',
''-- Pick a checklist --''] }}'
action:
- variables:
selected_option: '{{ states(''input_select.jottick_checklist_picker'') }}'
selected_title: "{%- if '(' in selected_option and selected_option.endswith(')')
-%}\n {{ selected_option.split(' (')[0] }}\n{%- else -%}\n {{ selected_option
}}\n{%- endif -%}"
list_id_hint: "{%- if '(' in selected_option and selected_option.endswith(')')
-%}\n {{ selected_option.split('(')[-1].rstrip(')') }}\n{%- else -%}\n \n{%-
endif -%}"
list_entity: "{%- for s in states.sensor -%}\n {%- if s.name.startswith('JotTick
List:') -%}\n {%- set title = state_attr(s.entity_id, 'title') -%}\n {%-
set list_id = state_attr(s.entity_id, 'checklist_id') -%}\n {%- if list_id_hint
and list_id and list_id.endswith(list_id_hint) -%}\n {{ s.entity_id }}\n
\ {%- elif not list_id_hint and title == selected_title -%}\n {{ s.entity_id
}}\n {%- endif -%}\n {%- endif -%}\n{%- endfor -%}"
- condition: template
value_template: '{{ list_entity | trim != '''' }}'
- service: input_text.set_value
target:
entity_id: input_text.jottick_selected_checklist_id
data:
value: '{{ state_attr(list_entity, ''checklist_id'') or '''' }}'
- service: input_text.set_value
target:
entity_id: input_text.jottick_selected_checklist_title
data:
value: '{{ state_attr(list_entity, ''title'') or '''' }}'
- service: input_text.set_value
target:
entity_id: input_text.jottick_selected_checklist_type
data:
value: '{{ state_attr(list_entity, ''type'') or ''simple'' }}'
- id: jottick_load_checklist_items
alias: 'JotTick: Load Checklist Items'
trigger:
- platform: state
entity_id: input_text.jottick_selected_checklist_id
condition:
- condition: template
value_template: '{{ states(''input_text.jottick_selected_checklist_id'') not in
['''', ''unknown'', ''unavailable''] }}'
action:
- variables:
checklist_id: '{{ states(''input_text.jottick_selected_checklist_id'') }}'
list_entity: "{%- for s in states.sensor -%}\n {%- if s.name.startswith('JotTick
List:') -%}\n {%- if state_attr(s.entity_id, 'checklist_id') == checklist_id
-%}\n {{ s.entity_id }}\n {%- endif -%}\n {%- endif -%}\n{%- endfor
-%}"
- condition: template
value_template: '{{ list_entity | trim != '''' }}'
- service: input_select.set_options
target:
entity_id: input_select.jottick_item_picker
data:
options: "{%- set items = state_attr(list_entity, 'items') or [] -%}\n{%- set
ns = namespace(options=['-- Select item --']) -%}\n{%- for item in items -%}\n
\ {%- set text = item.text | default('') -%}\n {%- if text -%}\n {%- set
display = '[✓] ' ~ text if item.completed else '[ ] ' ~ text -%}\n {%- set
ns.options = ns.options + [display] -%}\n {%- endif -%}\n{%- endfor -%}\n{{
ns.options }}"
- id: jottick_check_reminder_notifications
alias: "JotTick: Check Reminder Notifications"
mode: single
trigger:
- platform: time_pattern
minutes: "/5"
condition:
- condition: template
value_template: "{{ (state_attr('sensor.jottick_reminders', 'configs') or {}) | length > 0 }}"
action:
- variables:
configs: "{{ state_attr('sensor.jottick_reminders', 'configs') or {} }}"
current_hour: "{{ now().hour }}"
current_minute: "{{ now().minute }}"
current_day: "{{ now().strftime('%A') }}"
is_weekday: "{{ current_day in ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] }}"
- repeat:
for_each: "{{ configs.keys() | list if configs is mapping else [] }}"
sequence:
- variables:
item_id: "{{ repeat.item }}"
config: "{{ configs[item_id] if configs[repeat.item] is defined else {} }}"
item_type: "{{ config.type | default('checklist') }}"
days: "{{ config.days | default('every_day') }}"
start_time: "{{ config.start | default('08:00') }}"
end_time: "{{ config.end | default('20:00') }}"
interval_str: "{{ config.interval | default('1 hour') }}"
last_sent: "{{ config.last_sent | default(0) }}"
interval_minutes: >
{% set i = interval_str %}
{% if i == '30 minutes' %}30
{% elif i == '1 hour' %}60
{% elif i == '2 hours' %}120
{% elif i == '4 hours' %}240
{% elif i == '8 hours' %}480
{% elif i == '12 hours' %}720
{% elif i == 'Once a day' %}1440
{% else %}60{% endif %}
should_run_today: >
{% if days == 'weekdays' %}
{{ is_weekday }}
{% elif days == 'weekends' %}
{{ not is_weekday }}
{% else %}
true
{% endif %}
start_parts: "{{ start_time.split(':') }}"
end_parts: "{{ end_time.split(':') }}"
start_minutes: "{{ (start_parts[0] | int) * 60 + (start_parts[1] | int) }}"
end_minutes: "{{ (end_parts[0] | int) * 60 + (end_parts[1] | int) }}"
current_minutes: "{{ current_hour * 60 + current_minute }}"
in_time_window: "{{ current_minutes >= start_minutes | int and current_minutes <= end_minutes | int }}"
minutes_since_last: "{{ ((as_timestamp(now()) - (last_sent | float(0))) / 60) | int if last_sent else 9999 }}"
should_send: "{{ should_run_today and in_time_window and minutes_since_last >= interval_minutes | int }}"
- condition: template
value_template: "{{ should_send }}"
- variables:
sensor_entity: >
{% set ns = namespace(found='') %}
{% if item_type == 'task' %}
{% for s in states.sensor %}
{% if s.attributes.task_id is defined and s.attributes.task_id == item_id %}
{% set ns.found = s.entity_id %}
{% endif %}
{% endfor %}
{% else %}
{% for s in states.sensor %}
{% if s.attributes.checklist_id is defined and s.attributes.checklist_id == item_id %}
{% set ns.found = s.entity_id %}
{% endif %}
{% endfor %}
{% endif %}
{{ ns.found }}
- condition: template
value_template: "{{ sensor_entity | trim != '' }}"
- variables:
total_items: "{{ state_attr(sensor_entity, 'total') | int(0) }}"
completed_items: "{{ state_attr(sensor_entity, 'completed') | int(0) }}"
has_incomplete: "{{ total_items > completed_items }}"
item_title: "{{ state_attr(sensor_entity, 'title') | default('Reminder') }}"
incomplete_count: "{{ total_items - completed_items }}"
- condition: template
value_template: "{{ has_incomplete }}"
- variables:
custom_title: "{{ config.custom_title | default('') }}"
custom_message: "{{ config.custom_message | default('') }}"
targets: "{{ config.targets | default(config.target | default('')) }}"
target_list: "{{ targets.split(',') if targets else [] }}"
notification_title: "{% if custom_title != '' %}{{ custom_title }}{% else %}{{ item_title }}{% endif %}"
incomplete_items_list: >
{% if item_type == 'task' %}
{% set items = (state_attr(sensor_entity, 'flat_items') or []) %}
{% set incomplete = items | rejectattr('status', 'eq', 'completed') | map(attribute='text') | list %}
{% else %}
{% set items = (state_attr(sensor_entity, 'items') or []) %}
{% set incomplete = items | selectattr('completed', 'eq', false) | map(attribute='text') | list %}
{% endif %}
{{ incomplete | join('\n• ') }}
notification_message: >
{% if custom_message != '' %}
{{ custom_message }}
{% else %}
• {{ incomplete_items_list | trim }}
{% endif %}
- repeat:
count: "{{ target_list | length }}"
sequence:
- service: "{{ target_list[repeat.index - 1] }}"
data:
title: "{{ notification_title }}"
message: "{{ notification_message }}"
data:
tag: "jottick_{{ item_id }}"
actions:
- action: "JotTick_OPEN_{{ item_id }}"
title: "Open"
- action: "JotTick_SNOOZE_{{ item_id }}"
title: "Snooze"
- service: script.jottick_update_last_sent
data:
item_id: "{{ item_id }}"
- id: jottick_handle_notification_actions
alias: "JotTick: Handle Notification Actions"
trigger:
- platform: event
event_type: mobile_app_notification_action
condition:
- condition: template
value_template: "{{ trigger.event.data.action.startswith('JotTick_') }}"
action:
- variables:
action: "{{ trigger.event.data.action }}"
item_id: "{{ action.split('_', 2)[2] if action.split('_') | length > 2 else '' }}"
- choose:
- conditions: "{{ 'SNOOZE' in action }}"
sequence:
- service: script.jottick_update_last_sent
data:
item_id: "{{ item_id }}"
- conditions: "{{ 'OPEN' in action }}"
sequence:
- service: persistent_notification.create
data:
title: "JotTick Item"
message: "Open your JotTick dashboard to view this item."
notification_id: "jottick_open_{{ item_id }}"
- id: jottick_check_recurring_resets
alias: "JotTick: Check Recurring Resets"
trigger:
- platform: time_pattern
minutes: "/1"
action:
- variables:
configs: "{{ state_attr('sensor.jottick_recurring', 'configs') or {} }}"
current_time: "{{ now().strftime('%H:%M') }}"
current_day: "{{ now().strftime('%A') }}"
current_dom: "{{ now().day }}"
current_month: "{{ now().month }}"
is_weekday: "{{ current_day in ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] }}"
is_last_day_of_month: "{{ (now() + timedelta(days=1)).day == 1 }}"
is_quarterly_month: "{{ current_month in [1, 4, 7, 10] }}"
- condition: template
value_template: "{{ configs is mapping and configs | length > 0 }}"
- repeat:
for_each: "{{ configs.keys() | list if configs is mapping else [] }}"
sequence:
- variables:
item_id: "{{ repeat.item }}"
config: "{{ configs[item_id] if configs[repeat.item] is defined else {} }}"
item_type: "{{ config.type | default('checklist') }}"
days: "{{ config.days | default('every_day') }}"
monthly_day: "{{ config.monthly_day | default(1) | int }}"
yearly_month: "{{ config.get('yearly_month', 1) | int }}"
yearly_day: "{{ config.get('yearly_day', 1) | int }}"
reset_times: "{{ config.reset_times | default([]) if config.reset_times is defined else [] }}"
should_run_today: >
{% if days == 'weekdays' %}
{{ is_weekday }}
{% elif days == 'weekends' %}
{{ not is_weekday }}
{% elif days == 'monthly' %}
{{ current_dom | int == monthly_day }}
{% elif days == 'monthly_last' %}
{{ is_last_day_of_month }}
{% elif days == 'quarterly' %}
{{ is_quarterly_month and current_dom | int == monthly_day }}
{% elif days == 'quarterly_last' %}
{{ is_quarterly_month and is_last_day_of_month }}
{% elif days == 'yearly' %}
{{ current_month | int == yearly_month and current_dom | int == yearly_day }}
{% elif days.startswith('specific:') %}
{% set specific_days = days.replace('specific:', '').split(',') %}
{{ current_day[:3] in specific_days }}
{% else %}
true
{% endif %}
time_matches: "{{ current_time in reset_times }}"
- condition: template
value_template: "{{ should_run_today and time_matches }}"
- choose:
- conditions: "{{ item_type == 'task' }}"
sequence:
- service: script.jottick_reset_task
data:
task_id: "{{ item_id }}"
- conditions: "{{ item_type == 'checklist' }}"
sequence:
- service: script.jottick_reset_checklist
data:
checklist_id: "{{ item_id }}"
- conditions: "{{ item_type == 'checklist_item' }}"
sequence:
- service: script.jottick_reset_checklist_item
data:
checklist_id: "{{ config.parent_id }}"
item_index: "{{ config.item_index }}"
- conditions: "{{ item_type == 'task_item' }}"
sequence:
- service: script.jottick_reset_task_item
data:
task_id: "{{ config.parent_id }}"
item_index: "{{ config.item_index }}"
- id: jottick_process_scheduled_notes
alias: "JotTick Process Scheduled Notes"
mode: single
trigger:
- platform: time_pattern
minutes: "/1"
condition:
- condition: template
value_template: "{{ (state_attr('sensor.jottick_scheduled_notes', 'schedules') or {}) | length > 0 }}"
action:
- variables:
schedules: "{{ state_attr('sensor.jottick_scheduled_notes', 'schedules') or {} }}"
now_ts: "{{ as_timestamp(now()) }}"
- repeat:
for_each: "{{ schedules.keys() | list }}"
sequence:
- variables:
sched_id: "{{ repeat.item }}"
sched: "{{ schedules[sched_id] }}"
sched_time: "{{ sched.scheduled_time | default('') }}"
sched_ts: "{{ as_timestamp(sched_time) if sched_time else 0 }}"
- condition: template
value_template: "{{ sched_ts > 0 and sched_ts <= now_ts }}"
- service: script.jottick_send_scheduled_note
data:
schedule_id: "{{ sched_id }}"
title: "{{ sched.title | default('Reminder') }}"
message: "{{ sched.message | default('') }}"
targets: "{{ sched.targets | default('') }}"
auto_delete: "{{ sched.auto_delete | default(false) }}"
- id: jottick_process_quick_action
alias: "JotTick: Process Quick Action"
trigger:
- platform: state
entity_id: input_text.jottick_quick_action_data
condition:
- condition: template
value_template: "{{ trigger.to_state.state not in ['', 'unknown', 'unavailable'] }}"
action:
- variables:
parts: "{{ trigger.to_state.state.split('|||') }}"
list_id: "{{ parts[0] }}"
action: "{{ parts[1] }}"
- choose:
- conditions: "{{ action == 'delete' }}"
sequence:
- service: jottick.delete_checklist
data:
checklist_id: "{{ list_id }}"
- conditions: "{{ action == 'add' }}"
sequence:
- variables:
list_entity: >
{% for s in states.sensor %}
{% if s.name.startswith('JotTick List:') %}
{% if state_attr(s.entity_id, 'checklist_id') == list_id %}
{{ s.entity_id }}
{% endif %}
{% endif %}
{% endfor %}
current_items: "{{ state_attr(list_entity | trim, 'items') | default([]) | length }}"
item_text: "{{ parts[2] }}"
due_date: "{{ parts[3] | default('') }}"
due_time: "{{ parts[4] | default('') }}"
item_points: "{{ parts[5] | default('') }}"
assigned_to: "{{ parts[6] | default('') }}"
- service: jottick.add_checklist_item
data:
checklist_id: "{{ list_id }}"
text: "{{ item_text }}"
points: >
{% if item_points != '' %}{{ item_points | int }}{% endif %}
assigned_to: >
{% if assigned_to != '' %}{{ assigned_to }}{% endif %}
- condition: template
value_template: "{{ due_date != '' }}"
- delay:
milliseconds: 500
- service: jottick.set_checklist_item_due_date
data:
checklist_id: "{{ list_id }}"
item_index: "{{ current_items }}"
due_date: "{{ due_date }}"
due_time: "{{ due_time if due_time != '' else none }}"
- conditions: "{{ action == 'check' }}"
sequence:
- service: jottick.check_item
data:
checklist_id: "{{ list_id }}"
item_index: "{{ parts[2] }}"
- conditions: "{{ action == 'uncheck' }}"
sequence:
- service: jottick.uncheck_item
data:
checklist_id: "{{ list_id }}"
item_index: "{{ parts[2] }}"
default:
- variables:
item_index: "{{ action }}"
check_action: "{{ parts[2] }}"
- choose:
- conditions: "{{ check_action == 'check' }}"
sequence:
- service: jottick.check_item
data:
checklist_id: "{{ list_id }}"
item_index: "{{ item_index }}"
- conditions: "{{ check_action == 'uncheck' }}"
sequence:
- service: jottick.uncheck_item
data:
checklist_id: "{{ list_id }}"
item_index: "{{ item_index }}"
- service: input_text.set_value
target:
entity_id: input_text.jottick_quick_action_data
data:
value: ""
- id: jottick_process_quick_task_action
alias: "JotTick: Process Quick Task Action"
trigger:
- platform: state
entity_id: input_text.jottick_quick_task_action_data
condition:
- condition: template
value_template: "{{ trigger.to_state.state not in ['', 'unknown', 'unavailable'] }}"
action:
- variables:
parts: "{{ trigger.to_state.state.split('|||') }}"
task_id: "{{ parts[0] }}"
action: "{{ parts[1] }}"
- choose:
- conditions: "{{ action == 'delete' }}"
sequence:
- service: jottick.delete_task
data:
task_id: "{{ task_id }}"
- conditions: "{{ action == 'add' }}"
sequence:
- variables:
task_entity: >
{% for s in states.sensor %}
{% if s.name.startswith('JotTick Task:') %}
{% if state_attr(s.entity_id, 'task_id') == task_id %}
{{ s.entity_id }}
{% endif %}
{% endif %}
{% endfor %}
current_items: "{{ (state_attr(task_entity | trim, 'items') or []) | length }}"
item_text: "{{ parts[2] }}"
item_status: "{{ parts[3] | default('todo') }}"
due_date: "{{ parts[4] | default('') }}"
due_time: "{{ parts[5] | default('') }}"
item_points: "{{ parts[6] | default('') }}"
assigned_to: "{{ parts[7] | default('') }}"
- service: jottick.add_task_item
data:
task_id: "{{ task_id }}"
text: "{{ item_text }}"
status: "{{ item_status }}"
points: >
{% if item_points != '' %}{{ item_points | int }}{% endif %}
assigned_to: >
{% if assigned_to != '' %}{{ assigned_to }}{% endif %}
- condition: template
value_template: "{{ due_date != '' }}"
- delay:
milliseconds: 500
- service: jottick.set_task_item_due_date
data:
task_id: "{{ task_id }}"
item_index: "{{ current_items }}"
due_date: "{{ due_date }}"
due_time: "{{ due_time if due_time != '' else none }}"
- conditions: "{{ action == 'add_sub' }}"
sequence:
- variables:
item_text: "{{ parts[2] }}"
item_status: "{{ parts[3] | default('todo') }}"
parent_index: "{{ parts[4] }}"
- service: jottick.add_task_item
data:
task_id: "{{ task_id }}"
text: "{{ item_text }}"
status: "{{ item_status }}"
parent_index: "{{ parent_index }}"
- conditions: "{{ parts[2] | default('') == 'status' }}"
sequence:
- service: jottick.update_task_item_status
data:
task_id: "{{ task_id }}"
item_index: "{{ action }}"
status: "{{ parts[3] }}"
- conditions: "{{ parts[2] | default('') == 'delete_item' }}"
sequence:
- service: jottick.delete_task_item
data:
task_id: "{{ task_id }}"
item_index: "{{ action }}"
- service: input_text.set_value
target:
entity_id: input_text.jottick_quick_task_action_data
data:
value: ""
- id: jottick_process_due_date_action
alias: "JotTick: Process Due Date Action"
trigger:
- platform: state
entity_id: input_text.jottick_due_date_action_data
condition:
- condition: template
value_template: "{{ trigger.to_state.state not in ['', 'unknown', 'unavailable'] }}"
action:
- variables:
parts: "{{ trigger.to_state.state.split('|||') }}"
item_type: "{{ parts[0] }}"
item_id: "{{ parts[1] }}"
item_index: "{{ parts[2] }}"
action: "{{ parts[3] }}"
due_date: "{{ parts[4] | default('') }}"
due_time: "{{ parts[5] | default('') }}"
- choose:
- conditions: "{{ item_type == 'list' and action == 'set' }}"
sequence:
- service: jottick.set_checklist_item_due_date
data:
checklist_id: "{{ item_id }}"
item_index: "{{ item_index }}"
due_date: "{{ due_date }}"
due_time: "{{ due_time if due_time != '' else none }}"
- conditions: "{{ item_type == 'list' and action == 'clear' }}"
sequence:
- service: jottick.clear_checklist_item_due_date
data:
checklist_id: "{{ item_id }}"
item_index: "{{ item_index }}"
- conditions: "{{ item_type == 'task' and action == 'set' }}"
sequence:
- service: jottick.set_task_item_due_date
data:
task_id: "{{ item_id }}"
item_index: "{{ item_index }}"
due_date: "{{ due_date }}"
due_time: "{{ due_time if due_time != '' else none }}"
- conditions: "{{ item_type == 'task' and action == 'clear' }}"
sequence:
- service: jottick.clear_task_item_due_date
data:
task_id: "{{ item_id }}"
item_index: "{{ item_index }}"
- service: input_text.set_value
target:
entity_id: input_text.jottick_due_date_action_data
data:
value: ""
- id: jottick_process_kanban_action
alias: "JotTick: Process Kanban Action"
trigger:
- platform: state
entity_id: input_text.jottick_kanban_action_data
condition:
- condition: template
value_template: "{{ trigger.to_state.state not in ['', 'unknown', 'unavailable'] }}"
action:
- variables:
parts: "{{ trigger.to_state.state.split('|||') }}"
action: "{{ parts[0] }}"
task_id: "{{ parts[1] }}"
- choose:
- conditions: "{{ action == 'create_status' }}"
sequence:
- service: jottick.create_task_status
data:
task_id: "{{ task_id }}"
status_id: "{{ parts[2] }}"
label: "{{ parts[3] }}"
color: "{{ parts[4] | default('#6b7280') }}"
- conditions: "{{ action == 'update_status' }}"
sequence:
- service: jottick.update_task_status
data:
task_id: "{{ task_id }}"
status_id: "{{ parts[2] }}"
label: "{{ parts[3] }}"
- conditions: "{{ action == 'delete_status' }}"
sequence:
- service: jottick.delete_task_status
data:
task_id: "{{ task_id }}"
status_id: "{{ parts[2] }}"
- service: input_text.set_value
target:
entity_id: input_text.jottick_kanban_action_data
data:
value: ""
- id: jottick_process_quick_delete_item
alias: "JotTick: Process Quick Delete Item"
trigger:
- platform: state
entity_id: input_text.jottick_quick_delete_item_data
condition:
- condition: template
value_template: "{{ trigger.to_state.state not in ['', 'unknown', 'unavailable'] }}"
action:
- variables:
parts: "{{ trigger.to_state.state.split('|||') }}"
list_id: "{{ parts[0] }}"
item_index: "{{ parts[1] }}"
- service: jottick.delete_checklist_item
data:
checklist_id: "{{ list_id }}"
item_index: "{{ item_index }}"
- service: input_text.set_value
target:
entity_id: input_text.jottick_quick_delete_item_data
data:
value: ""
- id: jottick_refresh_ical_imports
alias: 'JotTick: Auto Refresh iCal Imports'
trigger:
- platform: time_pattern
minutes: "/30"
- platform: homeassistant
event: start
condition:
- condition: template
value_template: "{{ (state_attr('sensor.jottick_imported_events', 'sources') or []) | length > 0 }}"
action:
- service: jottick.refresh_ical_imports
- id: jottick_regenerate_ical_export
alias: 'JotTick: Regenerate iCal Export on Changes'
trigger:
- platform: state
entity_id:
- sensor.jottick_total_notes
- sensor.jottick_total_checklists
- sensor.jottick_total_tasks
action:
- delay: "00:00:02"
- service: jottick.export_ical
- id: jottick_init_calendar_date
alias: 'JotTick: Initialize Calendar Date'
trigger:
- platform: homeassistant
event: start
action:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.jottick_calendar_selected_date
data:
date: "{{ now().strftime('%Y-%m-%d') }}"
- id: jottick_auto_update_task_picker_fixed
alias: 'JotTick: Auto Update Task Picker'
trigger:
- platform: state
entity_id:
- sensor.jottick_total_tasks
- platform: homeassistant
event: start
action:
- service: input_select.set_options
target:
entity_id: input_select.jottick_task_picker
data:
options: >
{%- set ns = namespace(items=['-- Pick a task list --'], titles={}) -%}
{%- set tasks = states.sensor | selectattr('name', 'search', '^JotTick Task:')
| rejectattr('state', 'eq', 'unavailable') | list -%}
{%- for state in tasks -%}
{%- set title = state_attr(state.entity_id, 'title') -%}
{%- if title -%}
{%- if title in ns.titles -%}
{%- set ns.titles = dict(ns.titles, **{title: ns.titles[title] + 1}) -%}
{%- else -%}
{%- set ns.titles = dict(ns.titles, **{title: 1}) -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- set ns2 = namespace(counts={}) -%}
{%- for state in tasks | sort(attribute='attributes.updated', reverse=true) -%}
{%- set title = state_attr(state.entity_id, 'title') -%}
{%- if title -%}
{%- set task_id = state_attr(state.entity_id, 'task_id') -%}
{%- if ns.titles[title] > 1 -%}
{%- set current_count = ns2.counts.get(title, 0) + 1 -%}
{%- set ns2.counts = dict(ns2.counts, **{title: current_count}) -%}
{%- set display_title = title ~ ' (' ~ task_id[-6:] ~ ')' -%}
{%- else -%}
{%- set display_title = title -%}
{%- endif -%}
{%- set ns.items = ns.items + [display_title] -%}
{%- endif -%}
{%- endfor -%}
{{ ns.items }}
- id: jottick_load_task_when_picked
alias: 'JotTick: Load Task When Picked'
trigger:
- platform: state
entity_id: input_select.jottick_task_picker
condition:
- condition: template
value_template: '{{ trigger.to_state.state not in [''unknown'', ''unavailable'', ''-- Pick a task list --''] }}'
action:
- variables:
selected_option: '{{ states(''input_select.jottick_task_picker'') }}'
selected_title: >
{%- if '(' in selected_option and selected_option.endswith(')') -%}
{{ selected_option.split(' (')[0] }}
{%- else -%}
{{ selected_option }}
{%- endif -%}
task_id_hint: >
{%- if '(' in selected_option and selected_option.endswith(')') -%}
{{ selected_option.split('(')[-1].rstrip(')') }}
{%- else -%}
{%- endif -%}
task_entity: >
{%- for s in states.sensor -%}
{%- if s.name.startswith('JotTick Task:') -%}
{%- set title = state_attr(s.entity_id, 'title') -%}
{%- set task_id = state_attr(s.entity_id, 'task_id') -%}
{%- if task_id_hint and task_id and task_id.endswith(task_id_hint) -%}
{{ s.entity_id }}
{%- elif not task_id_hint and title == selected_title -%}
{{ s.entity_id }}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
- condition: template
value_template: '{{ task_entity | trim != '''' }}'
- service: input_text.set_value
target:
entity_id: input_text.jottick_selected_task_id
data:
value: '{{ state_attr(task_entity, ''task_id'') or '''' }}'
- service: input_text.set_value
target:
entity_id: input_text.jottick_selected_task_title
data:
value: '{{ state_attr(task_entity, ''title'') or '''' }}'
- id: jottick_load_task_items
alias: 'JotTick: Load Task Items'
trigger:
- platform: state
entity_id: input_text.jottick_selected_task_id
condition:
- condition: template
value_template: '{{ states(''input_text.jottick_selected_task_id'') not in ['''', ''unknown'', ''unavailable''] }}'
action:
- variables:
task_id: '{{ states(''input_text.jottick_selected_task_id'') }}'
task_entity: >
{%- for s in states.sensor -%}
{%- if s.name.startswith('JotTick Task:') -%}
{%- if state_attr(s.entity_id, 'task_id') == task_id -%}
{{ s.entity_id }}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
- condition: template
value_template: '{{ task_entity | trim != '''' }}'
- service: input_select.set_options
target:
entity_id: input_select.jottick_task_item_picker
data:
options: >
{%- set items = state_attr(task_entity, 'items') or [] -%}
{%- set ns = namespace(opts=['-- Select task item --']) -%}
{%- for item in items -%}
{%- set ns.opts = ns.opts + [item.text | default('Item ' ~ loop.index)] -%}
{%- endfor -%}
{{ ns.opts }}
- id: jottick_refresh_calendar_on_settings_change
alias: 'JotTick: Refresh Calendar on Settings Change'
mode: restart
trigger:
- platform: state
entity_id:
- input_boolean.jottick_calendar_show_note_created
- input_boolean.jottick_calendar_show_note_edited
- input_boolean.jottick_calendar_show_note_reminders
- input_boolean.jottick_calendar_show_list_created
- input_boolean.jottick_calendar_show_list_edited
- input_boolean.jottick_calendar_show_list_due
- input_boolean.jottick_calendar_show_task_due
- input_boolean.jottick_calendar_show_imported
- input_boolean.jottick_calendar_show_overdue
- input_boolean.jottick_calendar_show_completed
- input_text.jottick_calendar_color_note_created
- input_text.jottick_calendar_color_note_edited
- input_text.jottick_calendar_color_note_reminder
- input_text.jottick_calendar_color_list_created
- input_text.jottick_calendar_color_list_edited
- input_text.jottick_calendar_color_list_due
- input_text.jottick_calendar_color_task_due
- input_text.jottick_calendar_color_task_overdue
- input_text.jottick_calendar_color_completed
- input_text.jottick_calendar_color_imported
action:
- service: homeassistant.update_entity
target:
entity_id: sensor.jottick_calendar_events