-
Notifications
You must be signed in to change notification settings - Fork 0
/
templates.yaml
359 lines (359 loc) · 18.2 KB
/
templates.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
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
- sensor:
- unique_id: bad_fade_slutt
state: >-
{{ states.timer.lysfade_bad_aktiv_fade.state }}
icon: >
{{ state_attr("timer.lysfade_bad_aktiv_fade","icon") }}
attributes:
friendly_name: >
Bad: fader til scene {{ states.input_text.lysfade_bad_aktiv_scene.state }}
duration: >
{{ state_attr("timer.lysfade_bad_aktiv_fade","duration") }}
start_time: >
{{ states.timer.lysfade_bad_aktiv_fade.last_changed }}
end_time: >
{{ state_attr("timer.lysfade_bad_aktiv_fade","finishes_at") }}
- unique_id: aktiv_lysfade_hoved
state: >-
{% set ns = namespace(entity_list='') %}
{% for item in states.pyscript %}
{% if 'hue' in item.entity_id and 'hoved' in item.entity_id and item.state == 'on' %}
{% set ns.entity_list = ns.entity_list + ',' + item.name %}
{% endif %}
{% endfor %}
{{ ns.entity_list.split(',') | select("ne", '') | join(', ') }}
icon: >
{{ state_attr("input_select.lysfade_aktiv_gruppe","icon") }}
attributes:
friendly_name: >
{% set ns = namespace(entity_list='') %}
{% for item in states.pyscript %}
{% if 'hue' in item.entity_id and 'hoved' in item.entity_id and item.state == 'on' %}
{% set ns.entity_list = ns.entity_list + ',' + item.name %}
{% endif %}
{% endfor %}
{{ ns.entity_list.split(',') | select("ne", '') | join(', ') }}
- unique_id: aktiv_lysfade_fastelys
state: >-
{% set ns = namespace(entity_list='') %}
{% for item in states.pyscript %}
{% if 'hue' in item.entity_id and 'fastelys' in item.entity_id and item.state == 'on' %}
{% set ns.entity_list = ns.entity_list + ',' + item.name %}
{% endif %}
{% endfor %}
{{ ns.entity_list.split(',') | select("ne", '') | join(', ') }}
icon: >
{{ state_attr("input_select.lysfade_aktiv_gruppe","icon") }}
attributes:
friendly_name: >
{% set ns = namespace(entity_list='') %}
{% for item in states.pyscript %}
{% if 'hue' in item.entity_id and 'fastelys' in item.entity_id and item.state == 'on' %}
{% set ns.entity_list = ns.entity_list + ',' + item.name %}
{% endif %}
{% endfor %}
{{ ns.entity_list.split(',') | select("ne", '') | join(', ') }}
- unique_id: tablet_next_alarm
state: >-
{% if states.sensor.nettbrett1_next_alarm.state == "unavailable" %}
{{ "unknown" }}
{% elif states.sensor.nettbrett1_next_alarm.state == "unknown" %}
{{ "unknown" }}
{% else %}
{{ as_timestamp(states.sensor.nettbrett1_next_alarm.state)|timestamp_custom('%H:%M', true) }}
{% endif %}
attributes:
icon: 'mdi:alarm'
friendly_name: 'Neste alarm på nettbrett'
active: >-
{% if states.sensor.nettbrett1_next_alarm.state == "unavailable" %}
{{ "Off" }}
{% else %}
{{ "On" }}
{% endif %}
- unique_id: wakeup_alarm
state: >-
{{ state_attr('input_datetime.vekking', 'timestamp') | timestamp_custom('%H:%M', false) }}
attributes:
icon: 'mdi:alarm'
friendly_name: 'Vekking'
- unique_id: missing_some_alarm_setting
state: >-
{{ states.sensor.template_tablet_next_alarm.state == "unknown" or states.input_boolean.alarm_aktiv.state == "off" }}
attributes:
friendly_name: 'Alarm inaktiv for HA eller nettbrett'
- unique_id: tablet_alarm_active
state: >-
{% if states.sensor.template_tablet_next_alarm.state == "unknown" %}
{{ "off" }}
{% else %}
{{ "on" }}
{% endif %}
attributes:
icon: 'mdi:alarm'
friendly_name: 'Alarm nettbrett aktiv'
- unique_id: huetrans_vekking_endtime_auto
state: "{{ (states.sensor.vekking_for_lysfade.state|int(0) + (30*60))|timestamp_custom('%H:%M:%S', false) }}"
attributes:
friendly_name: 'LysFade: Slutt Vekking (beregnet)'
editable: "{{ false }}"
has_date: "{{ false }}"
has_time: "{{ true }}"
hour: "{{ ((states.sensor.vekking_for_lysfade.state|int(0) + (30*60))/(60*60))|int(0) % 24 }}"
minute: "{{ ((states.sensor.vekking_for_lysfade.state|int(0) + (30*60))/60)|int(0) % 60 }}"
second: "{{ (states.sensor.vekking_for_lysfade.state|int(0) + (30*60)) % 60 }}"
timestamp: "{{ (states.sensor.vekking_for_lysfade.state|int(0) + (30*60)) }}"
- unique_id: huetrans_vekking_endtime_auto_old
state: "{{ (state_attr('input_datetime.vekking', 'timestamp') + (30*60))|timestamp_custom('%H:%M:%S', false) }}"
attributes:
friendly_name: 'LysFade: Slutt Vekking (beregnet) - gammel beregning'
editable: "{{ false }}"
has_date: "{{ false }}"
has_time: "{{ true }}"
hour: "{{ ((state_attr('input_datetime.vekking', 'hour') + (state_attr('input_datetime.vekking', 'minute')/60) + (state_attr('input_datetime.vekking', 'second')/(60*60)) + 0.5) // 1) | int }}"
minute: "{{ ((state_attr('input_datetime.vekking', 'minute') + (state_attr('input_datetime.vekking', 'second')/60) + 30) % 60) | int }}"
second: "{{ (state_attr('input_datetime.vekking', 'second') + (30*60)) % 60 }}"
timestamp: "{{ (state_attr('input_datetime.vekking', 'timestamp') + (30*60)) }}"
- unique_id: vekking_timestamp
state: "{{ state_attr('input_datetime.vekking', 'timestamp') }}"
attributes:
friendly_name: 'Vekking: timestamp (beregnet)'
- unique_id: wakeup_lightfade_delay_timestamp
state: "{{ state_attr('input_datetime.wakeup_lightfade_delay', 'timestamp') }}"
attributes:
friendly_name: 'Vekking lysfade delay: timestamp (beregnet)'
- unique_id: huetrans_hoved_arbeidslys_timestamp_helper
state: >-
{% set item_entity_id = 'pyscript.huetrans_hoved_arbeidslys' %}
{% set after_entity = state_attr(item_entity_id, 'after_entity') %}
{% set min_diff = state_attr(item_entity_id, 'min_diff') %}
{% set endtime_entity = state_attr(item_entity_id, 'normal_endtime_entity') %}
{% if not '.' in endtime_entity %}
{% set endtime_entity = 'input_datetime.' + endtime_entity %}
{% endif %}
{% set endtime = state_attr(endtime_entity, 'timestamp') %}
{% set min_endtime = state_attr(after_entity, 'timestamp') %}
{% if endtime - min_endtime < min_diff %}
{{ min_endtime + min_diff }}
{% else %}
{{ endtime }}
{% endif %}
- unique_id: huetrans_arbeidslys_endtime_auto
state: "{{ states('sensor.template_huetrans_hoved_arbeidslys_timestamp_helper')|int|timestamp_custom('%H:%M:%S', false) }}"
attributes:
friendly_name: 'LysFade: Slutt Arbeidslys (beregnet)'
editable: "{{ false }}"
has_date: "{{ false }}"
has_time: "{{ true }}"
hour: "{{ states('sensor.template_huetrans_hoved_arbeidslys_timestamp_helper')|int // (60*60) }}"
minute: "{{ (states('sensor.template_huetrans_hoved_arbeidslys_timestamp_helper')|int % (60*60)) // 60 }}"
second: "{{ states('sensor.template_huetrans_hoved_arbeidslys_timestamp_helper')|int % 60}}"
timestamp: "{{ states('sensor.template_huetrans_hoved_arbeidslys_timestamp_helper')|int }}"
# IPORTANT: This needs to be placed AFTER the auto endtime templates, since this relies on data from them to calculate it's value
- unique_id: next_transition_hoved
state: >-
{% set nowTimestamp = as_timestamp(utcnow()) - as_timestamp(strptime(as_timestamp(utcnow())|timestamp_custom('%Y-%m-%d', true),'%Y-%m-%d')) %}
{% set ns = namespace(nextTimer='',nextTimestamp=0,firstTimer='',firstTimestamp=0) %}
{% set ns.nextTimestamp = 60*60*24 %}
{% set ns.firstTimestamp = 60*60*24 %}
{% for item in states.pyscript %}
{% if 'huetrans_hoved' in item.entity_id %}
{% set endtime_entity = state_attr(item.entity_id, 'endtime_entity') %}
{% if endtime_entity != None %}
{% if not '.' in endtime_entity %}
{% set endtime_entity = 'input_datetime.' + endtime_entity %}
{% endif %}
{% set transTimestamp = state_attr(endtime_entity, 'timestamp') %}
{% if nowTimestamp < transTimestamp %}
{% if ns.nextTimestamp > transTimestamp %}
{% set ns.nextTimer = item.entity_id %}
{% set ns.nextTimestamp = transTimestamp %}
{% endif %}
{% endif %}
{% if ns.firstTimestamp > transTimestamp %}
{% set ns.firstTimer = item.entity_id %}
{% set ns.firstTimestamp = transTimestamp %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% if ns.firstTimestamp > ns.nextTimestamp or ns.nextTimestamp == 60*60*24 %}
{% set ns.nextTimer = ns.firstTimer %}
{% set ns.nextTimestamp = ns.firstTimestamp %}
{% endif %}
{{ ns.nextTimer }}
attributes:
icon: 'mdi:car-parking-lights'
friendly_name: 'Data entity for next transition group with "hoved"'
- unique_id: current_transition_hoved
state: >-
{% set nowTimestamp = as_timestamp(utcnow()) - as_timestamp(strptime(as_timestamp(utcnow())|timestamp_custom('%Y-%m-%d', true),'%Y-%m-%d')) %}
{% set ns = namespace(currentTimer='',currentTimestamp=0,firstTimer='',firstTimestamp=0,seconds_to_complete_trans=0) %}
{% set ns.currentTimestamp = 0 %}
{% set ns.firstTimestamp = 60*60*24 %}
{% for item in states.pyscript %}
{% if 'huetrans_hoved' in item.entity_id %}
{% set ns.seconds_to_complete_trans = 0 %}
{% for scn in state_attr(item.entity_id, 'Scenes') %}
{% set ns.seconds_to_complete_trans = ns.seconds_to_complete_trans + scn.timeinseconds + scn.delay|default(0) %}
{% endfor %}
{% set endtime_entity = state_attr(item.entity_id, 'endtime_entity') %}
{% if endtime_entity != None %}
{% if not '.' in endtime_entity %}
{% set endtime_entity = 'input_datetime.' + endtime_entity %}
{% endif %}
{% set transTimestamp = state_attr(endtime_entity, 'timestamp') - ns.seconds_to_complete_trans %}
{% if nowTimestamp > transTimestamp %}
{% if ns.currentTimestamp < transTimestamp %}
{% set ns.currentTimer = item.entity_id %}
{% set ns.currentTimestamp = transTimestamp %}
{% endif %}
{% endif %}
{% if ns.firstTimestamp > transTimestamp %}
{% set ns.firstTimer = item.entity_id %}
{% set ns.firstTimestamp = transTimestamp %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% if ns.firstTimestamp > ns.currentTimestamp %}
{% set ns.currentTimer = ns.firstTimer %}
{% set ns.currentTimestamp = ns.firstTimestamp %}
{% endif %}
{{ ns.currentTimer }}
attributes:
icon: 'mdi:car-parking-lights'
friendly_name: 'Data entity for current transition group with "hoved"'
- unique_id: huetrans_fastelys_morgen_timestamp_helper
state: >-
{% set item_entity_id = 'pyscript.huetrans_fastelys_morgen' %}
{% set after_entity = state_attr(item_entity_id, 'after_entity') %}
{% set min_diff = state_attr(item_entity_id, 'min_diff') %}
{% set endtime_entity = state_attr(item_entity_id, 'normal_endtime_entity') %}
{% if not '.' in endtime_entity %}
{% set endtime_entity = 'input_datetime.' + endtime_entity %}
{% endif %}
{% set endtime = state_attr(endtime_entity, 'timestamp') %}
{% set min_endtime = state_attr(after_entity, 'timestamp') %}
{% if endtime - min_endtime < min_diff %}
{{ min_endtime + min_diff }}
{% else %}
{{ endtime }}
{% endif %}
- unique_id: huetrans_fastelys_morgen_endtime_auto
state: "{{ states('sensor.template_huetrans_fastelys_morgen_timestamp_helper')|int|timestamp_custom('%H:%M:%S', false) }}"
attributes:
friendly_name: 'LysFade: Slutt Basislys morgen (beregnet)'
editable: "{{ false }}"
has_date: "{{ false }}"
has_time: "{{ true }}"
hour: "{{ states('sensor.template_huetrans_fastelys_morgen_timestamp_helper')|int // (60*60) }}"
minute: "{{ (states('sensor.template_huetrans_fastelys_morgen_timestamp_helper')|int % (60*60)) // 60 }}"
second: "{{ states('sensor.template_huetrans_fastelys_morgen_timestamp_helper')|int % 60}}"
timestamp: "{{ states('sensor.template_huetrans_fastelys_morgen_timestamp_helper')|int }}"
- unique_id: huetrans_fastelys_dag_timestamp_helper
state: >-
{% set item_entity_id = 'pyscript.huetrans_fastelys_dag' %}
{% set after_entity = state_attr(item_entity_id, 'after_entity') %}
{% set min_diff = state_attr(item_entity_id, 'min_diff') %}
{% set endtime_entity = state_attr(item_entity_id, 'normal_endtime_entity') %}
{% if not '.' in endtime_entity %}
{% set endtime_entity = 'input_datetime.' + endtime_entity %}
{% endif %}
{% set endtime = state_attr(endtime_entity, 'timestamp') %}
{% set min_endtime = state_attr(after_entity, 'timestamp') %}
{% if endtime - min_endtime < min_diff %}
{{ min_endtime + min_diff }}
{% else %}
{{ endtime }}
{% endif %}
- unique_id: huetrans_fastelys_dag_endtime_auto
state: "{{ states('sensor.template_huetrans_fastelys_dag_timestamp_helper')|int|timestamp_custom('%H:%M:%S', false) }}"
attributes:
friendly_name: 'LysFade: Slutt Basislys dag (beregnet)'
editable: "{{ false }}"
has_date: "{{ false }}"
has_time: "{{ true }}"
hour: "{{ states('sensor.template_huetrans_fastelys_dag_timestamp_helper')|int // (60*60) }}"
minute: "{{ (states('sensor.template_huetrans_fastelys_dag_timestamp_helper')|int % (60*60)) // 60 }}"
second: "{{ states('sensor.template_huetrans_fastelys_dag_timestamp_helper')|int % 60}}"
timestamp: "{{ states('sensor.template_huetrans_fastelys_dag_timestamp_helper')|int }}"
# IPORTANT: This needs to be placed AFTER the auto endtime templates, since this relies on data from them to calculate it's value
- unique_id: next_transition_fastelys
state: >-
{% set nowTimestamp = as_timestamp(utcnow()) - as_timestamp(strptime(as_timestamp(utcnow())|timestamp_custom('%Y-%m-%d', true),'%Y-%m-%d')) %}
{% set ns = namespace(nextTimer='',nextTimestamp=0,firstTimer='',firstTimestamp=0) %}
{% set ns.nextTimestamp = 60*60*24 %}
{% set ns.firstTimestamp = 60*60*24 %}
{% for item in states.pyscript %}
{% if 'huetrans_fastelys' in item.entity_id %}
{% set endtime_entity = state_attr(item.entity_id, 'endtime_entity') %}
{% if endtime_entity != None %}
{% if not "." in endtime_entity %}
{% set endtime_entity = 'input_datetime.' + endtime_entity %}
{% endif %}
{% set transTimestamp = state_attr(endtime_entity, 'timestamp') %}
{% if nowTimestamp < transTimestamp %}
{% if ns.nextTimestamp > transTimestamp %}
{% set ns.nextTimer = item.entity_id %}
{% set ns.nextTimestamp = transTimestamp %}
{% endif %}
{% endif %}
{% if ns.firstTimestamp > transTimestamp %}
{% set ns.firstTimer = item.entity_id %}
{% set ns.firstTimestamp = transTimestamp %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% if ns.firstTimestamp > ns.nextTimestamp or ns.nextTimestamp == 60*60*24 %}
{% set ns.nextTimer = ns.firstTimer %}
{% set ns.nextTimestamp = ns.firstTimestamp %}
{% endif %}
{{ ns.nextTimer }}
attributes:
icon: 'mdi:car-parking-lights'
friendly_name: 'Data entity for next transition group with "Faste lys"'
- unique_id: current_transition_fastelys
state: >-
{% set nowTimestamp = as_timestamp(utcnow()) - as_timestamp(strptime(as_timestamp(utcnow())|timestamp_custom('%Y-%m-%d', true),'%Y-%m-%d')) %}
{% set ns = namespace(currentTimer='',currentTimestamp=0,firstTimer='',firstTimestamp=0,seconds_to_complete_trans=0) %}
{% set ns.currentTimestamp = 0 %}
{% set ns.firstTimestamp = 60*60*24 %}
{% for item in states.pyscript %}
{% if 'huetrans_fastelys' in item.entity_id %}
{% set ns.seconds_to_complete_trans = 0 %}
{% for scn in state_attr(item.entity_id, 'Scenes') %}
{% set ns.seconds_to_complete_trans = ns.seconds_to_complete_trans + scn.timeinseconds + scn.delay|default(0) %}
{% endfor %}
{% set endtime_entity = state_attr(item.entity_id, 'endtime_entity') %}
{% if endtime_entity != None %}
{% if not '.' in endtime_entity %}
{% set endtime_entity = 'input_datetime.' + endtime_entity %}
{% endif %}
{% set transTimestamp = state_attr(endtime_entity, 'timestamp') - ns.seconds_to_complete_trans %}
{% if nowTimestamp > transTimestamp %}
{% if ns.currentTimestamp < transTimestamp %}
{% set ns.currentTimer = item.entity_id %}
{% set ns.currentTimestamp = transTimestamp %}
{% endif %}
{% endif %}
{% if ns.firstTimestamp > transTimestamp %}
{% set ns.firstTimer = item.entity_id %}
{% set ns.firstTimestamp = transTimestamp %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% if ns.firstTimestamp > ns.currentTimestamp %}
{% set ns.currentTimer = ns.firstTimer %}
{% set ns.currentTimestamp = ns.firstTimestamp %}
{% endif %}
{{ ns.currentTimer }}
attributes:
icon: 'mdi:car-parking-lights'
friendly_name: 'Data entity for current transition group with "Faste lys"'
# - unique_id: test_temp_diff
# state: '{{ (states("sensor.kontoret_temperature")|float(default=20)) - (states("input_number.termostat_kontoret")|float(default=20)) }}'
# attributes:
# friendly_name: 'Test diff temperatur vs termostat'