-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensor.yaml
429 lines (393 loc) · 16.2 KB
/
sensor.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
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
###############################################################################
# SENSORS
###############################################################################
###############################################################################
# INTEGRAL AND DERIVATIVE
###############################################################################
# Derivative for current gas usage
- platform: derivative
source: sensor.gas_consumed
name: 'Huidige gas verbruik'
round: 1
unit_time: h
unit: 'm³/h'
time_window: "00:05:00"
###############################################################################
# HOLIDAY REPLAY
###############################################################################
# Replay sensor for holiday mode
- platform: history_stats
name: "replay_living_room"
entity_id: light.living_room
state: "on"
type: count
start: >
{{ as_timestamp(now()) - (7*86400) }}
duration: 00:00:30
- platform: history_stats
name: "replay_bedroom"
entity_id: light.bedroom
state: "on"
type: count
start: >
{{ as_timestamp(now()) - (7*86400) }}
duration: 00:00:30
- platform: history_stats
name: "replay_dining_room"
entity_id: light.dining_room
state: "on"
type: count
start: >
{{ as_timestamp(now()) - (7*86400) }}
duration: 00:00:30
- platform: history_stats
name: "replay_closet"
entity_id: light.closet
state: "on"
type: count
start: >
{{ as_timestamp(now()) - (7*86400) }}
duration: 00:00:30
- platform: history_stats
name: "replay_kitchen"
entity_id: light.kitchen
state: "on"
type: count
start: >
{{ as_timestamp(now()) - (7*86400) }}
duration: 00:00:30
###############################################################################
# TEMPLATE SENSORS
###############################################################################
- platform: template
sensors:
# Alarm panel battery sensor
alarm_panel_battery:
friendly_name: "Alarm paneel batterij"
unit_of_measurement: "%"
device_class: battery
value_template: >-
{% set battery_level = state_attr('sensor.alarm_panel_power', 'battery_voltage') %}
{% if is_number(battery_level) %}
{{ ((battery_level - 3.6)/2.4 * 100) | int('unknown') }}
{% else %}
{{ 'unknown' }}
{% endif %}
icon_template: >-
{% set battery_level = states('sensor.alarm_panel_battery') %}
{% if not is_number(battery_level) %}
mdi:battery-unknown
{% else %}
{% set battery_round = (battery_level|int / 10)|int * 10 %}
{% if battery_round >= 100 %}
mdi:battery
{% elif battery_round > 0 %}
mdi:battery-{{ battery_round }}
{% else %}
mdi:battery-alert
{% endif %}
{% endif %}
# Quiet time schedule
quiet_time_schedule:
friendly_name: "Stilte tijd schema"
icon_template: mdi:volume-off
value_template: >-
{% set night_start_free = state_attr('input_datetime.start_night_free_day', 'hour') * 60 + state_attr('input_datetime.start_night_free_day', 'minute')%}
{% set night_start_work = state_attr('input_datetime.start_night_workday', 'hour') * 60 + state_attr('input_datetime.start_night_workday', 'minute')%}
{% set night_end_free = state_attr('input_datetime.end_night_free_day', 'hour') * 60 + state_attr('input_datetime.end_night_free_day', 'minute')%}
{% set night_end_work = state_attr('input_datetime.end_night_workday', 'hour') * 60 + state_attr('input_datetime.end_night_workday', 'minute')%}
{% set offset = state_attr('input_datetime.quiet_offset', 'hour') * 60 + state_attr('input_datetime.quiet_offset', 'minute')%}
{% set now = (states('sensor.time')[:2] | int)*60 + (states('sensor.time')[-2:] | int)%}
{% if is_state('binary_sensor.workday_sensor', 'off') %}
{% if (night_end_free + offset) < now < (night_start_free - offset) %}
false
{%else%}
true
{%endif%}
{%else%}
{% if (night_end_work + offset) < now < (night_start_work - offset) %}
false
{%else%}
true
{%endif%}
{%endif%}
# outdoor light schedule
outdoor_lights:
friendly_name: "Buiten lampen schema"
value_template: >-
{% set mod_now = now().hour * 60 + now().minute %}
{%set dawn = as_local(as_datetime(state_attr('sun.sun', 'next_dawn')))%}
{%set dusk = as_local(as_datetime(state_attr('sun.sun', 'next_dusk')))%}
{% set hour = state_attr('input_datetime.outdoor_lights_offset', 'hour')%}
{% set minute = state_attr('input_datetime.outdoor_lights_offset', 'minute')%}
{%set offset_dawn = dawn + timedelta( hours = hour, minutes = minute )%}
{%set offset_dusk = dusk - timedelta( hours = hour, minutes = minute )%}
{%set mod_dawn = offset_dawn.hour * 60 + offset_dawn.minute %}
{%set mod_dusk = offset_dusk.hour * 60 + offset_dusk.minute %}
{% if ((is_state('sensor.house_state', 'home') or states('proximity.home_mike')|int(10) < 2 or states('proximity.home_anneloes')|int(10) < 2)) and not is_state('sensor.house_state', 'night') %}
{% if mod_now < mod_dawn %}
on
{% elif mod_now > mod_dusk %}
on
{%else%}
off
{%endif%}
{%else%}
off
{%endif%}
somebody_home:
friendly_name: "Iemand thuis"
value_template: >-
{% set mike_home = is_state('person.tmp', 'home') %}
{% set anneloes_home = is_state('person.anneloes_jagt', 'home') %}
{% if mike_home or anneloes_home %}
true
{% else %}
false
{% endif %}
house_state:
friendly_name: "Huis toestand"
value_template: >-
{% set time = states('sensor.time') %}
{% if is_state('input_select.house_state_override', 'auto') %}
{% if is_state('input_boolean.holiday', 'on') %}
holiday
{% else %}
{% if is_state('sensor.somebody_home', 'false') %}
away
{% else %}
{% if is_state('binary_sensor.workday_sensor', 'off') %}
{% if states('input_datetime.start_night_free_day') > time > states('input_datetime.end_night_free_day') %}
home
{% else %}
night
{% endif %}
{% else %}
{% if states('input_datetime.start_night_workday') > time > states('input_datetime.end_night_workday') %}
home
{% else %}
night
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% else %}
{{ states('input_select.house_state_override') }}
{% endif %}
icon_template: >-
{% if is_state('sensor.house_state', 'holiday') %}
mdi:beach
{% elif is_state('sensor.house_state', 'home') %}
mdi:home
{% elif is_state('sensor.house_state', 'away') %}
mdi:home-export-outline
{% elif is_state('sensor.house_state', 'night') %}
mdi:weather-night
{% endif %}
# +3600 for winter time check the method for quiet time that works better
climate_period:
friendly_name: "Klimaat periode"
value_template: >-
{% set night_start_free = state_attr('input_datetime.start_night_free_day', 'hour') * 60 + state_attr('input_datetime.start_night_free_day', 'minute')%}
{% set night_start_work = state_attr('input_datetime.start_night_workday', 'hour') * 60 + state_attr('input_datetime.start_night_workday', 'minute')%}
{% set night_end_free = state_attr('input_datetime.end_night_free_day', 'hour') * 60 + state_attr('input_datetime.end_night_free_day', 'minute')%}
{% set night_end_work = state_attr('input_datetime.end_night_workday', 'hour') * 60 + state_attr('input_datetime.end_night_workday', 'minute')%}
{% set offset_start = state_attr('input_datetime.heating_pre_heat', 'hour') * 60 + state_attr('input_datetime.heating_pre_heat', 'minute')%}
{% set offset_end = state_attr('input_datetime.heating_early_stop', 'hour') * 60 + state_attr('input_datetime.heating_early_stop', 'minute')%}
{% set evening_start = state_attr('input_datetime.evening_start', 'hour') * 60 + state_attr('input_datetime.evening_start', 'minute')%}
{% set morning_end = state_attr('input_datetime.morning_end', 'hour') * 60 + state_attr('input_datetime.morning_end', 'minute')%}
{% set tnow = (states('sensor.time')[:2] | int)*60 + (states('sensor.time')[-2:] | int)%}
{% if is_state('input_select.climate_period_override', 'auto') %}
{% if is_state('binary_sensor.workday_sensor', 'off') %}
{% if night_end_free - offset_start < tnow < morning_end %}
morning
{% elif morning_end < tnow < evening_start %}
day
{% elif evening_start < tnow < night_start_free - offset_end %}
evening
{% else %}
night
{% endif %}
{% else %}
{% if night_end_work - offset_start < tnow < morning_end %}
morning
{% elif morning_end < tnow < evening_start %}
day
{% elif evening_start < tnow < night_start_work - offset_end %}
evening
{% else %}
night
{% endif %}
{% endif %}
{% else %}
{{states('input_select.climate_period_override')}}
{% endif %}
icon_template: >-
{% if is_state('sensor.climate_period', 'morning') %}
mdi:weather-sunset-up
{% elif is_state('sensor.climate_period', 'day') %}
mdi:weather-sunny
{% elif is_state('sensor.climate_period', 'evening') %}
mdi:weather-sunset-down
{% elif is_state('sensor.climate_period', 'night') %}
mdi:minus
{% endif %}
# Sensor to check if heating is allowed
heating_allowed:
friendly_name: "Verwarmen toegestaan"
value_template: >-
{% set house_state = states('sensor.house_state') %}
{% set climate_period = states('sensor.climate_period') %}
{% if house_state == 'away' or house_state == 'holiday' %}
false
{% elif states('sensor.buienradar_temperature_1d')|int(0) > states('input_number.zomerstand_temperatuur')|int(0) %}
false
{% elif climate_period != 'night' %}
true
{% else %}
false
{% endif %}
# Downstairs thermostat setpoint for time of the day.
climate_setpoint:
friendly_name: "Beneden temperatuur instelpunt"
unit_of_measurement: "°C"
device_class: temperature
value_template: >-
{% if is_state('sensor.climate_period', 'morning') %}
{{ states('input_number.morning_temperature') }}
{% elif is_state('sensor.climate_period', 'day') %}
{{ states('input_number.day_temperature') }}
{% elif is_state('sensor.climate_period', 'evening') %}
{{ states('input_number.evening_temperature') }}
{% else %}
{{ states('input_number.night_temperature') }}
{% endif %}
# A template to determine if the growlight should be on.
# It will turn on the grow light if nobody is home and the sun is up.
grow_light_scheduler:
friendly_name: "Groei lamp schema"
value_template: >-
{% set house = states('sensor.house_state') %}
{% set sun = states('sun.sun') %}
{%if ((house == 'away') or (house == 'holiday')) and (sun == 'above_horizon')%}
true
{%else%}
false
{%endif%}
# Icon for air quality to be used in dashboards
humidifier:
friendly_name: "Luchtbevochtiger"
value_template: >-
{% if states('switch.humidifier') == 'off' %}
uit
{% elif states('sensor.humidifier_power')|int > 20 %}
aan
{% else %}
standby
{%endif%}
icon_template: >-
{% if states('switch.humidifier') == 'off' %}
mdi:air-humidifier-off
{% elif states('sensor.humidifier_power')|int > 20 %}
mdi:air-humidifier
{% else %}
mdi:air-humidifier
{%endif%}
# Low batteries to be used in the UI
low_batteries:
friendly_name: "Lege batterijen"
value_template: >-
{%- set threshold = 15 -%}
{% set data = namespace(thing=[]) %}
{%- set domains = ['light', 'switch', 'sensor', 'binary_sensor', 'cover'] -%}
{%- for domain in domains -%}
{%- for item in states[domain] if ((item.attributes.battery_level is defined and item.attributes['battery_level'] | int(100) < threshold) or ("battery" in item.name | lower and ((item.state | int(100) < threshold and item.state|int != 0) or item.state | lower == "low" or item.state | lower == "unknown"))) -%}
{% set data.thing = data.thing + [item.attributes.friendly_name] %}
{%- endfor -%}
{%- endfor -%}
{{data.thing|count}}
# Disconnected devices to be used in the UI
disconnected:
friendly_name: "Niet verbonden"
value_template: >-
{% set data = namespace(thing=[]) %}
{%- for item in states.binary_sensor -%}
{% if "connectivity" in item | string %}
{% if item.state == 'off' and "Rendier " not in item | string%}
{% set data.thing = data.thing + [item.attributes.friendly_name] %}
{% endif %}
{% endif %}
{% endfor %}
{{data.thing|count}}
# Open windows
open_windows:
friendly_name: "Open ramen"
value_template: >-
{% set data = namespace(thing=[]) %}
{%- for item in states.binary_sensor -%}
{% if "device_class=window" in item | string %}
{% if item.state == 'on' %}
{% set data.thing = data.thing + [item.attributes.friendly_name] %}
{% endif %}
{% endif %}
{% endfor %}
{{data.thing|count}}
# Open doors
open_doors:
friendly_name: "Open deuren"
value_template: >-
{% set data = namespace(thing=[]) %}
{%- for item in states.binary_sensor -%}
{% if "device_class=door" in item | string %}
{% if item.state == 'on' %}
{% set data.thing = data.thing + [item.attributes.friendly_name] %}
{% endif %}
{% endif %}
{% endfor %}
{{data.thing|count}}
problem_plants:
friendly_name: "Planten met een probleem"
value_template: >-
{% set data = namespace(thing=[]) %}
{%- for item in states.plant -%}
{% if "problem=none" not in item | string and "drakenbloedboom=problem; problem=moisture low," not in item | string %}
{% set data.thing = data.thing + [item.attributes.friendly_name] %}
{% endif %}
{% endfor %}
{{ data.thing|count }}
missing_entities_services:
friendly_name: "Missende entiteiten of services"
value_template: >-
{{ states("sensor.watchman_missing_entities")|int(0) + states("sensor.watchman_missing_services")|int(0) }}
###############################################################################
# STATISTICS
###############################################################################
# Average used for sprinkler water level
- platform: statistics
entity_id: sensor.buienradar_humidity
name: "Average humidity"
state_characteristic: mean
sampling_size: 200
max_age:
hours: 24
# Average used for sprinkler water level
- platform: statistics
entity_id: sensor.buienradar_ground_temperature
name: "Average ground temperature"
state_characteristic: mean
sampling_size: 200
max_age:
hours: 24
###############################################################################
# TIME
###############################################################################
# Date and time sensors
- platform: time_date
display_options:
- 'time'
- 'date'
- 'date_time'
- 'date_time_utc'
- 'date_time_iso'
- 'time_date'
- 'time_utc'