-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
477 lines (450 loc) · 19.1 KB
/
template.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
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
- binary_sensor:
- name: Buiten Warmer
state: '{{ float(states("sensor.buiten_gemiddelde_temperatuur") | default) - float(0.5) > float(states("sensor.gang_eerste_temperature") | default) }}'
- name: Buiten Kouder
state: '{{ float(states("sensor.buiten_gemiddelde_temperatuur") | default) + float(1) < float(states("sensor.gang_eerste_temperature") | default) }}'
- name: Trash Collection Tomorrow Today
state: >-
{{ states('sensor.recycleapp_tomorrow') != 'None' or states('sensor.recycleapp_today') != 'None' }}
- name: Vacuum Empty Bin
unique_id: vacuum_empty_bin
state: >-
{{ states('input_number.vacuum_number_of_runs') |float (0) >= states('input_number.vacuum_empty_bin_after_days') |float (0) }}
- name: WFH
unique_id: WFH
state: >-
{{ is_state('binary_sensor.workday_sensor', 'on')
and is_state('input_boolean.philippe_vacation', 'off')
and states('proximity.philippe_home') | float < 10 }}
- name: wasmachine
unique_id: wasmachine
state: "{{ states('sensor.wasmachine_power') | float(0) >= 3 }}"
delay_off:
minutes: 5
icon: mdi:washing-machine
device_class: running
- name: droogkast
unique_id: droogkast
state: "{{ states('sensor.droogkast_power') | float(0) >= 3 }}"
delay_off:
minutes: 5
icon: mdi:tumble-dryer
device_class: running
- name: vaatwas
unique_id: vaatwas
state: "{{ states('sensor.vaatwas_power') | float(0) >= 3 }}"
delay_off:
minutes: 5
icon: mdi:dishwasher
device_class: running
- name: waterpomp
unique_id: waterpomp
state: "{{ states('sensor.waterpomp_power') | float(0) > 1 or states('sensor.water_pump_flow') | float(0) > 0 }}"
icon: mdi:pump
device_class: running
- sensor:
- name: Number of Lights On
unique_id: number_of_lights_on
state: >-
{{ states.light
| rejectattr('attributes.is_deconz_group', 'eq', true)
| rejectattr('attributes.entity_id', 'defined')
| selectattr('state', 'eq', 'on')
| list | count }}
icon: mdi:lightbulb-group
- name: Number of Doors Open
unique_id: number_of_doors_open
state: >-
{{ expand('group.all_doors') | selectattr('state','eq','on') | list | count | float }}
icon: mdi:door-open
- name: Number of Motion Sensors On
unique_id: number_of_motion_sensors_on
state: >-
{{ expand('group.all_motion_sensors') | selectattr('state','eq','on') | list | count | float }}
icon: mdi:motion-sensor
- name: Number of Climate Active
unique_id: number_of_climate_active
state: >-
{{ expand('group.all_climate_rooms') | selectattr('attributes.hvac_action', 'eq', 'heating') | list | count | float }}
icon: mdi:motion-sensor
# Aggregates emergency status from across all nest protects (CO and Smoke)
- name: Nest Protect Emergency Status
state: >-
{% set sensors = [
states.sensor.dining_room_nest_protect_co_status,
states.sensor.inkom_nest_protect_co_status,
states.sensor.attic_nest_protect_co_status,
states.sensor.hallway_nest_protect_co_status,
states.sensor.dining_room_nest_protect_smoke_status,
states.sensor.inkom_nest_protect_smoke_status,
states.sensor.attic_nest_protect_smoke_status,
states.sensor.hallway_nest_protect_smoke_status] %}
{% if sensors | selectattr('state', 'eq', 'Emergency') | list | count > 0 %}
emergency
{% elif sensors | selectattr('state', 'eq', 'Warning') | list | count > 0 %}
warning
{% else %}
none
{% endif %}
icon: >-
{% if is_state('sensor.home_emergency', 'emergency') %}
mdi:alert-decagram
{% elif is_state('sensor.home_emergency', 'warning') %}
mdi:smoke-detector-alert
{% else %}
mdi:smoke-detector
{% endif %}
- name: "Unavailable Entities"
unique_id: unavailable_entities
icon: "{{ iif(states(this.entity_id)|float(0) > 0,'mdi:alert-circle','mdi:check-circle') }}"
unit_of_measurement: entities
state: >
{% set entities = state_attr(this.entity_id,'entity_id') %}
{% if entities != none %} {{ entities|count }} {% endif %}
attributes:
entity_id: >
{% set ignore_seconds = 60 %}
{% set ignored = state_attr('group.ignored_unavailable_entities','entity_id') %}
{% set ignore_ts = (now().timestamp() - ignore_seconds)|as_datetime %}
{% set entities = states|rejectattr('domain','eq','group')
|rejectattr('last_changed','ge',ignore_ts)
|selectattr('state','in',['unavailable','unknown','None']) %}
{% if ignored != none %}
{% set entities = entities|rejectattr('entity_id','in',ignored) %}
{% endif %}
{{ entities|map(attribute='entity_id')|list }}
- name: "Entities with Low Battery"
unique_id: entities_with_low_battery
unit_of_measurement: entities
state: >
{% set entities = state_attr(this.entity_id,'entity_id') %}
{% if entities != none %} {{ entities|count }} {% endif %}
attributes:
entity_id: >-
{% set ignore_entities = [] %}
{% set entities = states.sensor
| selectattr('attributes.device_class', 'defined')
| selectattr('attributes.device_class', 'eq', 'battery')
| rejectattr('entity_id', 'in', ignore_entities)
| rejectattr('state','in',['unavailable','unknown','None']) %}
{% set ns = namespace(low_entities=[]) %}
{% for x in entities %}
{% if x.state | float(0) < 25 %}
{% set ns.low_entities = ns.low_entities + [x.entity_id] %}
{% endif -%}
{% endfor %}
{{ ns.low_entities | list }}
icon: >-
{% if is_state('sensor.entities_with_low_battery', '0') %}
mdi:battery-check
{% else %}
mdi:battery-alert
{% endif %}
- name: "Operating State"
unique_id: "operating_state"
state: >-
{% if state_attr('climate.controller', 'hvac_action') != None %}
{{ state_attr('climate.controller', 'hvac_action') }}
{% endif %}
- name: "Heat Demands"
unique_id: fc_heat_demand
unit_of_measurement: "%"
state: >-
{% if state_attr('climate.controller', 'heat_demands') != None %}
{% if state_attr('climate.controller', 'heat_demands').get('FC') != None %}
{{ state_attr('climate.controller', 'heat_demands').FC * 100 }}
{% endif %}
{% endif %}
- name: "Total of Known Devices Power"
unique_id: "total_of_known_devices_power"
device_class: "power"
unit_of_measurement: W
state: >-
{{ states('sensor.koelkast_vriezer_berging_power') | float (0) +
states('sensor.koelkast_keuken_power') | float (0) +
states('sensor.vriezer_garage_power') | float (0) +
states('sensor.koelkast_vriezer_garage_power') | float (0) +
states('sensor.boiler_keuken_power') | float (0) +
states('sensor.wasmachine_power') | float (0) +
states('sensor.droogkast_power') | float (0) +
states('sensor.brander_power') | float (0) +
states('sensor.waterpomp_power') | float (0) +
states('sensor.vaatwas_power') | float (0) +
states('sensor.computer_power') | float (0) +
states('sensor.verlichting_gang_eerste_verdiep_power') | float (0) +
states('sensor.verlichting_garage_gelijkvloers_power') | float (0) +
states('sensor.verlichting_garage_voorkant_power') | float (0) +
states('sensor.verlichting_garage_zijkant_power') | float (0) +
states('sensor.verlichting_garage_zolder_power') | float (0) +
states('sensor.bureau_powerstrip_power') | float (0) +
states('sensor.verlichting_inkom_power') | float (0) +
states('sensor.verlichting_voordeur_power') | float (0) +
states('sensor.led_slaapkamer_power') | float(0) +
states('sensor.led_desk_lamp_power') | float(0) +
states('sensor.led_febe_bed_power') | float(0) +
states('sensor.led_margot_bed_power') | float(0) +
states('sensor.led_schouw_power') | float(0) +
states('sensor.led_speelkamer_power') | float(0)}}
- name: "Current Power From To Grid"
unique_id: "current_power_from_to_grid"
unit_of_measurement: W
device_class: power
state: >-
{% if states('sensor.power_produced') | float(0) * 1000 > 0 %}
{{ (states('sensor.power_produced') | float(0) * 1000) | int }}
{% else %}
{{ (states('sensor.power_consumed') | float(0) * 1000) | int }}
{% endif %}
icon: >-
{% if (states('sensor.power_produced') | float(0) * 1000) | int > 0 %}
mdi:transmission-tower-export
{% else %}
mdi:transmission-tower-import
{% endif %}
availability: >
{{ states('sensor.power_consumed') | float(none) != none and
states('sensor.power_produced') | float(none) != none }}
- name: "Current Power"
unique_id: "current_power"
unit_of_measurement: W
device_class: power
state: >-
{% set grid_power = states('sensor.stp6_0_3se_40_411_grid_power') | float (0) %}
{% if grid_power > 0 %}
{% set consumed = states('sensor.stp6_0_3se_40_411_metering_power_absorbed') | float(0) %}
{% set produced = states('sensor.stp6_0_3se_40_411_metering_power_supplied') | float(0) %}
{% else %}
{% set consumed = states('sensor.power_consumed') | float(0) * 1000 %}
{% set produced = states('sensor.power_produced') | float(0) * 1000 %}
{% endif %}
{% if grid_power > 0 %}
{% if consumed > 0 %}
{{ grid_power + consumed }}
{% else %}
{{ grid_power - produced }}
{% endif %}
{% else %}
{{ consumed }}
{% endif %}
availability: >
{{ (states('sensor.stp6_0_3se_40_411_grid_power') | float(none) != none and
states('sensor.stp6_0_3se_40_411_metering_power_absorbed') | float(none) != none and
states('sensor.stp6_0_3se_40_411_metering_power_supplied') | float(none) != none) or
(states('sensor.power_consumed') | float(none) != none and
states('sensor.power_produced') | float(none) != none) }}
- name: "Unknown Power"
unique_id: "unknown_power"
unit_of_measurement: W
device_class: power
state: >-
{% set unknown_power = states('sensor.current_power') | float (0) -
states('sensor.total_of_known_devices_power') | float (0)
%}
{{ unknown_power if unknown_power > 0 else 0 }}
- name: "Solar Battery Recharge Time"
unique_id: "solar_battery_recharge_time"
device_class: duration
icon: mdi:battery-clock
state: >-
{% if states('sensor.stp6_0_3se_40_411_battery_power_charge_total') | float(0) == 0 %}
{% set decimal_hours = 0 | float(0) %}
{% set minutes = 0 | float(0) %}
{% else %}
{% set remain_percent = (100 - states('sensor.stp6_0_3se_40_411_battery_soc_total') | float(0)) / 100 %}
{% set battery_capacity = 10.2 %}
{% set battery_capacity = battery_capacity * ((states('sensor.stp6_0_3se_40_411_battery_capacity_total') | float(0)) / 100) %}
{% set charge = remain_percent * battery_capacity %}
{% set current_power = states('sensor.stp6_0_3se_40_411_battery_power_charge_total') | float (0) / 1000 %}
{% set decimal_hours = charge / current_power %}
{% set minutes = (decimal_hours % 1 * 60) | round(0) %}
{% endif %}
{{ decimal_hours | int(0) ~ 'u' ~ minutes ~ 'min' }}
- name: "Solar Battery Life"
unique_id: "solar_battery_life"
device_class: "duration"
icon: mdi:battery-clock
state: >-
{% if states('sensor.current_power') | float(0) == 0 %}
{% set decimal_hours = 0 | float(0) %}
{% set minutes = 0 | float(0) %}
{% else %}
{% set percent = states('sensor.stp6_0_3se_40_411_battery_soc_total') | float(0) / 100.0 %}
{% set battery_capacity = 10.2 %}
{% set battery_capacity = battery_capacity * ((states('sensor.stp6_0_3se_40_411_battery_capacity_total') | float(0)) / 100) %}
{% set reserve = 0.1 %}
{% set charge = percent * (battery_capacity * (1 - reserve)) %}
{% set current_power = states('sensor.current_power') | float (0) / 1000 %}
{% set decimal_hours = charge / current_power %}
{% set minutes = (decimal_hours % 1 * 60) | round(0) %}
{% endif %}
{{ decimal_hours | int(0) ~ 'u' ~ minutes ~ 'min' }}
- name: "Solar Battery Life 24 hr"
unique_id: "solar_battery_life_24_hr"
device_class: "duration"
icon: mdi:battery-clock
state: >-
{% if states('sensor.current_power_avg_over_last_24_hours') | float(0) == 0 %}
{% set decimal_hours = 0 | float(0) %}
{% set minutes = 0 | float(0) %}
{% else %}
{% set percent = states('sensor.stp6_0_3se_40_411_battery_soc_total') | float(0) / 100.0 %}
{% set battery_capacity = 10.2 %}
{% set battery_capacity = battery_capacity * ((states('sensor.stp6_0_3se_40_411_battery_capacity_total') | float(0)) / 100) %}
{% set reserve = 0.1 %}
{% set charge = percent * (battery_capacity * (1 - reserve)) %}
{% set current_power = states('sensor.current_power_avg_over_last_24_hours') | float (0) / 1000 %}
{% set decimal_hours = charge / current_power %}
{% set minutes = (decimal_hours % 1 * 60) | round(0) %}
{% endif %}
{{ decimal_hours | int(0) ~ 'u' ~ minutes ~ 'min' }}
# PV Benefit is grid power + returning/supplied power back to the net.
# Do not take battery charging into account as later when the battery is discharging it's included in the grid power.
- name: PV benefit
unique_id: pv_benefit
unit_of_measurement: €/h
state: >
{{(states('sensor.stp6_0_3se_40_411_grid_power') | float (0) / 1000) * states('input_number.electricity_consumption_price') | float (0)
+ (states('sensor.stp6_0_3se_40_411_metering_power_supplied') | float (0) / 1000) * states('input_number.electricity_injection_price') | float (0) }}
- name: 'Led Slaapkamer Power'
unique_id: 'led_slaapkamer_power'
unit_of_measurement: 'W'
device_class: power
state: >-
{{ states('sensor.led_slaapkamer_estimated_current')|float(0) * 5/1000 }}
- name: 'Led Margot Bed Power'
unique_id: 'led_Margot_Bed_power'
unit_of_measurement: 'W'
device_class: power
state: >-
{{ states('sensor.margot_led_bed_estimated_current')|float(0) * 5/1000 }}
- name: 'Led Febe Bed Power'
unique_id: 'led_Febe_Bed_power'
unit_of_measurement: 'W'
device_class: power
state: >-
{{ states('sensor.febe_led_bed_estimated_current')|float(0) * 5/1000 }}
- name: 'Led Desk Lamp Power'
unique_id: 'led_desk_lamp_power'
unit_of_measurement: 'W'
device_class: power
state: >-
{{ states('sensor.desk_lamp_estimated_current')|float(0) * 5/1000 }}
- name: 'Led Schouw Power'
unique_id: 'led_schouw_power'
unit_of_measurement: 'W'
device_class: power
state: >-
{{ states('sensor.schouw_estimated_current')|float(0) * 5/1000 }}
- name: 'Led Speelkamer Power'
unique_id: 'led_Speelkamer_power'
unit_of_measurement: 'W'
device_class: power
state: >-
{{ states('sensor.wled_speelkamer_estimated_current')|float(0) * 5/1000 }}
- name: "Energy Consumed"
unique_id: "energy_consumed"
unit_of_measurement: "kWh"
device_class: energy
state: >-
{{ states('sensor.energy_consumed_tariff_1') | float (0) +
states('sensor.energy_consumed_tariff_2') | float (0)
}}
availability: >
{{ states('sensor.energy_consumed_tariff_1') | float(none) != none
and states('sensor.energy_consumed_tariff_2') | float(none) != none }}
- name: "Gas Consumed Belgium kWh"
unique_id: "gas_consumed_belgium_kwh"
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
state: >-
{{ states('sensor.gas_consumed_belgium') | float (0) * 11.4226 }}
availability: >
{{ states('sensor.gas_consumed_belgium') | float(none) != none
and states('sensor.gas_consumed_belgium') | float(0) > 0 }}
- name: "Max Peak"
unique_id: max_peak
unit_of_measurement: "kW"
device_class: power
state: >-
{% set peak = ((states("sensor.quarter_hourly_grid_consumed") | float(0)) * 4) %}
{% set max_peak = (states("input_number.max_peak") | float(0)) %}
{% macro max(X, Y) -%} {{X|float if X|float > Y|float else Y|float }} {%- endmacro %}
{{ max(max_peak, peak) }}
state_class: "measurement"
icon: mdi:summit
- name: "Average Year Peak"
unique_id: year_peak
unit_of_measurement: "kW"
device_class: power
state: >
{{ (( states('input_number.january_peak') | float(0) +
states('input_number.february_peak') | float(0) +
states('input_number.march_peak') | float(0) +
states('input_number.april_peak') | float(0) +
states('input_number.may_peak') | float(0) +
states('input_number.june_peak') | float(0) +
states('input_number.july_peak') | float(0) +
states('input_number.august_peak') | float(0) +
states('input_number.september_peak') | float(0) +
states('input_number.october_peak') | float(0) +
states('input_number.november_peak') | float(0) +
states('input_number.december_peak') | float(0) ) / 12) | round(2)
}}
state_class: "measurement"
icon: mdi:summit
- trigger:
- platform: state
entity_id:
- sensor.quarter_hourly_grid_consumed
attribute: last_reset
sensor:
- name: "Quarter Peak"
unique_id: quarter_peak
unit_of_measurement: "kW"
device_class: power
state: >-
{{ state_attr("sensor.quarter_hourly_grid_consumed", "last_period") | float(0) * 4 }}
state_class: "measurement"
attributes:
last_reset: >-
{{ state_attr("sensor.quarter_hourly_grid_consumed", "last_reset") }}
icon: mdi:summit
- trigger:
- platform: state
entity_id:
- binary_sensor.bureau_motion
- binary_sensor.speelkamer_motion
- binary_sensor.motion_achterdeur
- binary_sensor.oprit_camera
- binary_sensor.voordeur
- binary_sensor.achterdeur
- binary_sensor.keukendeur
- binary_sensor.garagedeur
- binary_sensor.motion_wc_boven
- binary_sensor.motion_wc_beneden
- binary_sensor.motion_gang_eerste_2
- binary_sensor.motion_gang_eerste_1
- binary_sensor.motion_inkom_1
- binary_sensor.motion_inkom_2
- binary_sensor.motion_gang_zolder
- binary_sensor.motion_voordeur
- binary_sensor.motion_bureau
- binary_sensor.motion_dressing
- binary_sensor.motion_speelkamer
- binary_sensor.motion_woonkamer
- binary_sensor.motion_keuken
- binary_sensor.motion_garagepoort
- binary_sensor.garagepoort_input
to: "on"
sensor:
- name: Last Motion
unique_id: last_motion
icon: mdi:motion-sensor
state: >-
{{trigger.to_state.name.split(' sensor Motion')[0]}} - {{as_timestamp(trigger.to_state.last_changed)| timestamp_custom('%X') }}
attributes:
entity_id: >-
{{trigger.entity_id}}
last_detected: >-
{{as_timestamp(trigger.to_state.last_changed)| timestamp_custom('%X') }}