-
Notifications
You must be signed in to change notification settings - Fork 1
/
HomeAssistant_template_tasks.yaml
228 lines (227 loc) · 10.7 KB
/
HomeAssistant_template_tasks.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
- trigger:
- platform: time_pattern
minutes: /3
action:
- service: todo.get_items
data:
status: needs_action
target:
entity_id:
- todo.to_do
- todo.car
response_variable: mylist
- service: calendar.get_events
data:
start_date_time: "{{today_at().strftime('%Y-%m-%d %H:%M')}}"
end_date_time: "{{now().date() + timedelta(days=29)}}"
target:
entity_id:
- calendar.family
- calendar.holidays_in_south_korea
- calendar.bills
response_variable: mycalendar
sensor:
- name: eInk TasksBoard Data
unique_id: eink_tasksboard_data
state: "OK"
attributes:
today: >
{%- set counter = namespace(total = 0) -%}
{%- set list = namespace(todo = []) -%}
{# -- search todo lists and calendars below this point -- #}
{# search calendar #}
{%- for events in mycalendar["calendar.family"]["events"] -%}
{%- if "start" in events and (now().date()|string) in events.start -%}
{%- set list.todo = list.todo + [(events.summary)] -%}
{%- set counter.total = counter.total + 1 -%}
{%- endif -%}
{%- endfor -%}
{# search calendar and add a note#}
{%- for events in mycalendar["calendar.holidays_in_south_korea"]["events"] -%}
{%- if "start" in events and (now().date()|string) in events.start -%}
{%- set list.todo = list.todo + ["Korea: " + (events.summary)] -%}
{%- set counter.total = counter.total + 1 -%}
{%- endif -%}
{%- endfor -%}
{# search todo list #}
{%- for items in mylist["todo.to_do"]["items"] -%}
{%- if "due" in items and items.due <= states('sensor.date') -%}
{%- set list.todo = list.todo + [(items.summary)] -%}
{%- set counter.total = counter.total + 1 -%}
{%- endif -%}
{%- endfor -%}
{# search todo list and add a note #}
{%- for items in mylist["todo.car"]["items"] -%}
{%- if "due" in items and items.due <= states('sensor.date') -%}
{%- set list.todo = list.todo + ["Car: " + (items.summary)] -%}
{%- set counter.total = counter.total + 1 -%}
{%- endif -%}
{%- endfor -%}
{# search calendar and add a note #}
{%- for events in mycalendar["calendar.bills"]["events"] -%}
{%- if "start" in events and (now().date()|string) in events.start -%}
{%- set list.todo = list.todo + ["Bills: " + (events.summary)] -%}
{%- set counter.total = counter.total + 1 -%}
{%- endif -%}
{%- endfor -%}
{# -- end searching -- #}
{{list.todo | default('') }}
upcoming: >
{%- set latest_date = 64 -%}
{%- set counter = namespace(total = 0) -%}
{%- set list = namespace(todo = []) -%}
{%- for v in range(latest_date) -%}
{# -- search todo lists and calendars below this point -- #}
{# search calendar #}
{%- for events in mycalendar["calendar.family"]["events"] -%}
{%- if "start" in events and ((now().date() + timedelta(days=v+1))|string) in events.start -%}
{%- set list.todo = list.todo + [(as_datetime(events.start).strftime('%A %B %-d'))] -%}
{%- set list.todo = list.todo + [(events.summary)] -%}
{%- set counter.total = counter.total + 1 -%}
{%- endif -%}
{%- endfor -%}
{# search todo list #}
{%- for items in mylist["todo.to_do"]["items"] -%}
{%- if "due" in items and ((now().date() + timedelta(days=v+1))|string) in items.due -%}
{%- set list.todo = list.todo + [(as_datetime(items.due).strftime('%A %B %-d'))] -%}
{%- set list.todo = list.todo + [(items.summary)] -%}
{%- set counter.total = counter.total + 1 -%}
{%- endif -%}
{%- endfor -%}
{# -- end searching -- #}
{%- if counter.total >= 20 -%}
{%- break -%}
{%- endif -%}
{%- endfor -%}
{{list.todo | default('') }}
today_0: >
{{ state_attr(this.entity_id, 'today')[0] | default('') }}
today_1: >
{{ state_attr(this.entity_id, 'today')[1] | default('') }}
today_2: >
{{ state_attr(this.entity_id, 'today')[2] | default('') }}
today_3: >
{{ state_attr(this.entity_id, 'today')[3] | default('') }}
today_4: >
{{ state_attr(this.entity_id, 'today')[4] | default('') }}
today_5: >
{{ state_attr(this.entity_id, 'today')[5] | default('') }}
today_6: >
{{ state_attr(this.entity_id, 'today')[6] | default('') }}
today_7: >
{{ state_attr(this.entity_id, 'today')[7] | default('') }}
today_8: >
{{ state_attr(this.entity_id, 'today')[8] | default('') }}
today_9: >
{{ state_attr(this.entity_id, 'today')[9] | default('') }}
upcoming_date_0: >
{{ state_attr(this.entity_id, 'upcoming')[0] | default('') }}
upcoming_item_0: >
{{ state_attr(this.entity_id, 'upcoming')[1] | default('') }}
upcoming_date_1: >
{{ state_attr(this.entity_id, 'upcoming')[2] | default('') }}
upcoming_item_1: >
{{ state_attr(this.entity_id, 'upcoming')[3] | default('') }}
upcoming_date_2: >
{{ state_attr(this.entity_id, 'upcoming')[4] | default('') }}
upcoming_item_2: >
{{ state_attr(this.entity_id, 'upcoming')[5] | default('') }}
upcoming_date_3: >
{{ state_attr(this.entity_id, 'upcoming')[6] | default('') }}
upcoming_item_3: >
{{ state_attr(this.entity_id, 'upcoming')[7] | default('') }}
upcoming_date_4: >
{{ state_attr(this.entity_id, 'upcoming')[8] | default('') }}
upcoming_item_4: >
{{ state_attr(this.entity_id, 'upcoming')[9] | default('') }}
upcoming_date_5: >
{{ state_attr(this.entity_id, 'upcoming')[10] | default('') }}
upcoming_item_5: >
{{ state_attr(this.entity_id, 'upcoming')[11] | default('') }}
upcoming_date_6: >
{{ state_attr(this.entity_id, 'upcoming')[12] | default('') }}
upcoming_item_6: >
{{ state_attr(this.entity_id, 'upcoming')[13] | default('') }}
upcoming_date_7: >
{{ state_attr(this.entity_id, 'upcoming')[14] | default('') }}
upcoming_item_7: >
{{ state_attr(this.entity_id, 'upcoming')[15] | default('') }}
upcoming_date_8: >
{{ state_attr(this.entity_id, 'upcoming')[16] | default('') }}
upcoming_item_8: >
{{ state_attr(this.entity_id, 'upcoming')[17] | default('') }}
upcoming_date_9: >
{{ state_attr(this.entity_id, 'upcoming')[18] | default('') }}
upcoming_item_9: >
{{ state_attr(this.entity_id, 'upcoming')[19] | default('') }}
upcoming_date_10: >
{{ state_attr(this.entity_id, 'upcoming')[20] | default('') }}
upcoming_item_10: >
{{ state_attr(this.entity_id, 'upcoming')[21] | default('') }}
upcoming_date_11: >
{{ state_attr(this.entity_id, 'upcoming')[22] | default('') }}
upcoming_item_11: >
{{ state_attr(this.entity_id, 'upcoming')[23] | default('') }}
upcoming_date_12: >
{{ state_attr(this.entity_id, 'upcoming')[24] | default('') }}
upcoming_item_12: >
{{ state_attr(this.entity_id, 'upcoming')[25] | default('') }}
upcoming_date_13: >
{{ state_attr(this.entity_id, 'upcoming')[26] | default('') }}
upcoming_item_13: >
{{ state_attr(this.entity_id, 'upcoming')[27] | default('') }}
upcoming_date_14: >
{{ state_attr(this.entity_id, 'upcoming')[28] | default('') }}
upcoming_item_14: >
{{ state_attr(this.entity_id, 'upcoming')[29] | default('') }}
upcoming_date_15: >
{{ state_attr(this.entity_id, 'upcoming')[30] | default('') }}
upcoming_item_15: >
{{ state_attr(this.entity_id, 'upcoming')[31] | default('') }}
upcoming_date_16: >
{{ state_attr(this.entity_id, 'upcoming')[32] | default('') }}
upcoming_item_16: >
{{ state_attr(this.entity_id, 'upcoming')[33] | default('') }}
upcoming_date_17: >
{{ state_attr(this.entity_id, 'upcoming')[34] | default('') }}
upcoming_item_17: >
{{ state_attr(this.entity_id, 'upcoming')[35] | default('') }}
upcoming_date_18: >
{{ state_attr(this.entity_id, 'upcoming')[36] | default('') }}
upcoming_item_18: >
{{ state_attr(this.entity_id, 'upcoming')[37] | default('') }}
- trigger:
- platform: time_pattern
minutes: /1
variables:
waketime: >
{# Edit and order the schedule from midnight 00:00 to 23:59 as needed #}
{%- set waketimes = [] %}
{%- set waketimes = waketimes + ["01:01"] %}
{%- set waketimes = waketimes + ["10:01"] %}
{%- set waketimes = waketimes + ["14:01"] %}
{%- set waketimes = waketimes + ["18:01"] %}
{%- set waketime = namespace(next = "") %}
{%- set waketime_all = [] %}
{%- for test in waketimes %}
{%- set waketime.next = (now().strftime('%Y-%m-%d')|string) + " " + (test|string) %}
{%- if (now().strftime('%Y-%m-%d %H:%M:%S')|string|as_datetime) < (waketime.next|as_datetime) %}
{%- break %}
{%- endif %}
{%- endfor %}
{%- if (now().strftime('%Y-%m-%d %H:%M:%S')|string|as_datetime) > (waketime.next|as_datetime) %}
{%- set waketime.next = (now().strftime('%Y-%m-%d')|string) + " " + (waketimes[0]|string) %}
{%- set waketime_helper = ((as_timestamp(waketime.next|as_datetime + timedelta(days=1)) - as_timestamp(now()|as_datetime))|int(0)) %}
{%- else %}
{%- set waketime_helper = ((as_timestamp(waketime.next|as_datetime) - as_timestamp(now()|as_datetime))|int(0)) %}
{%- endif %}
{%- set waketime_all = [waketime.next] + [waketime_helper] + [waketimes] %}
{{waketime_all}}
sensor:
- name: eInk TasksBoard Wake Times
unique_id: eink_tasksboard_wake_times
state: "{{ this.attributes.next_wake_time | default('Not Available') }}"
attributes:
wake_times: "{{ waketime[2] | default('Not Available') }}"
next_wake_time: "{{ waketime[0] | default(999999) }}"
wake_time_helper: "{{ waketime[1] | default('Not Available') }}"