-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
276 lines (276 loc) · 12.7 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
- trigger:
- platform: state
entity_id:
- binary_sensor.presence_bathroom
- binary_sensor.presence_bedroom
- binary_sensor.presence_hall
- binary_sensor.presence_kitchen
- binary_sensor.presence_lounge
- binary_sensor.presence_office
- binary_sensor.rose_away_from_home
sensor:
- unique_id: last_occupied_room
name: Last Occupied Room
state: >
{% if is_state('binary_sensor.rose_away_from_home', 'on') %}
{{ states['binary_sensor.rose_away_from_home'].name }}
{% else %}
{% set rooms = 'binary_sensor.presence_bathroom', 'binary_sensor.presence_bedroom', 'binary_sensor.presence_hall', 'binary_sensor.presence_kitchen', 'binary_sensor.presence_lounge', 'binary_sensor.presence_office' %}
{% set roomSensors = namespace(sensors=[],all=[]) %}
{% for room in rooms %}
{% set roomData = states[room] %}
{% set roomSensors.all = roomSensors.all + [roomData] %}
{% if roomData.state in ['on', on, True] %}
{% set roomSensors.sensors = roomSensors.sensors + [roomData] %}
{% endif %}
{% endfor %}
{% if (roomSensors.sensors | count) > 0 %}
{% set roomList = roomSensors.sensors %}
{% else %}
{% set roomList = roomSensors.all %}
{% endif %}
{{ roomList | sort(true, attribute='last_updated') | map(attribute='name') | first | replace("Presence:", "") | trim }}
{% endif %}
- unique_id: rose_is_state
name: "Rose"
state: "{{ states('input_select.rose_state') }}"
- name: Alarm Clock Timestamp
unique_id: alarm_clock_timestamp
device_class: timestamp
state: >
{{ today_at(states('input_datetime.alarm_time')) }}
- binary_sensor:
- name: Water Jug Filter Needs Replacing
unique_id: water_jug_filter_needs_replacing
state: "{{ int(states('counter.water_jug_filter')) <= 5 }}"
- name: Replace Dishwasher Cassette
unique_id: replace_dishwasher_cassette
state: "{{ int(states('counter.dishwasher_refills_remaining')) <= 7 }}"
- name: Bathroom Door Occupancy
unique_id: bathroom_door
state: "{{ is_state('binary_sensor.bathroom_door_contact', 'off') }}"
- name: Alarm Clock Status
unique_id: alarm_clock_status
state: >
{% set alarmClockOn = false %}
{% set lastNotToday = as_timestamp(states('input_datetime.alarm_clock_ran')) < as_timestamp(today_at()) %}
{% if is_state('input_select.manual_alarm_setting', 'Unset') %}
{% set alarmClockOn = is_state('binary_sensor.workday_sensor', 'on') %}
{% else %}
{% set alarmClockOn = is_state('input_select.manual_alarm_setting', 'On') %}
{% endif %}
{{ alarmClockOn and lastNotToday and is_state('person.rosemary_orchard', 'home') }}
- name: No-One Home
unique_id: noone_home
device_class: occupancy
state: >
{{ not is_state('group.people', 'home') }}
- name: Someone Home
unique_id: someone_home
device_class: occupancy
state: >
{{ is_state('group.people', 'home') }}
- name: Living Room Occupied
unique_id: lounge_occupied
device_class: occupancy
delay_off: 00:05:00
state: >
{% set current = is_state('binary_sensor.presence_lounge', 'on') %}
{% set lastSeen = states('sensor.last_occupied_room') | lower %}
{% set lastSeenLounge = 'lounge' in lastSeen %}
{% set lastSeenLivingRoom = 'living' in lastSeen %}
{% set lounge_occupied = [current, lastSeenLounge, lastSeenLivingRoom] | select('in', [on, 'on', True]) | list | count > 0 %}
{{ lounge_occupied }}
- name: Hallway Occupied
unique_id: hall_occupied
device_class: occupancy
delay_off: 00:05:00
state: >
{% set current = is_state('binary_sensor.presence_hall', 'on') %}
{% set lastSeen = 'hall' in (states('sensor.last_occupied_room') | lower) %}
{% set hall_occupied = [current, lastSeen] | select('in', [on, 'on', True]) | list | count > 0 %}
{{ hall_occupied }}
- name: Bedroom Occupied
unique_id: bedroom_occupied
device_class: occupancy
delay_off: 00:05:00
state: >
{% set current = is_state('binary_sensor.presence_bedroom', 'on') %}
{% set lastSeen = 'bedroom' in (states('sensor.last_occupied_room') | lower) %}
{% set asleep = is_state('input_select.rose_state', 'Sleep') %}
{% set bedroom_occupied = [current, asleep, lastSeen] | select('in', [on, 'on', True]) | list | count > 0 %}
{{ bedroom_occupied }}
- name: Office Occupied
unique_id: office_occupied
device_class: occupancy
delay_off: 00:05:00
state: >
{% set current = is_state('binary_sensor.presence_office', 'on') %}
{% set lastSeen = 'office' in (states('sensor.last_occupied_room') | lower) %}
{% set office_occupied = [current, lastSeen] | select('in', [on, 'on', True]) | list | count > 0 %}
{{ office_occupied }}
- name: Kitchen Occupied
unique_id: kitchen_occupied
device_class: occupancy
delay_off: 00:05:00
state: >
{% set current = is_state('binary_sensor.presence_kitchen', 'on') %}
{% set lastSeen = is_state('sensor.last_occupied_room', 'Kitchen Presence') %}
{% set tvOn = is_state('media_player.kitchen_tv', 'playing') %}
{% set kitchen_occupied = [current, lastSeen, tvOn] | select('in', [on, 'on', True]) | list | count > 0 %}
{{ kitchen_occupied }}
- name: Bathroom Occupied
unique_id: bathroom_occupied
device_class: occupancy
delay_off: 00:03:00
state: >
{% set current = is_state('binary_sensor.presence_bathroom', 'on') %}
{% set lastSeen = 'bathroom' in (states('sensor.last_occupied_room') | lower) %}
{% set bathroom_occupied = [current, lastSeen] | select('in', [on, 'on', True]) | list | count > 0 %}
{{ bathroom_occupied }}
- name: Television On
unique_id: television_on
device_class: connectivity
state: >
{{ is_state('media_player.philips_tv', 'on') }}
- name: Television Active
unique_id: television_active
device_class: connectivity
state: >
{% if is_state('media_player.philips_tv', 'on') %}
{% if is_state('switch.harmony_hub_my_apple_tv', 'on') %}
{{ is_state('media_player.living_room_apple_tv', 'playing') or is_state('media_player.apple_tv_plex', 'playing') }}
{% else %}
{{ is_state('media_player.philips_tv', 'on') }}
{% endif %}
{% else %}
{{ false }}
{% endif %}
- name: Kitchen Television On
unique_id: kitchen_tv_on
state: >
{{ is_state('media_player.kitchen_tv', 'on') }}
- name: Rose Home
unique_id: rose_home
device_class: presence
state: >
{{ is_state('person.rosemary_orchard', 'home') }}
- name: A Heating Pad is On
unique_id: any_heating_pad
device_class: power
state: >
{{ is_state('input_boolean.living_room_heating_pad_controller', 'on') or is_state('input_boolean.office_heating_pad_controller', 'on') }}
- name: "Work Laptop Docked"
unique_id: work_laptop_docked
device_class: presence
state: >
{% set isActive = is_state('sensor.work_laptop_ssid', 'The Promised LAN') and is_state('binary_sensor.work_laptop_active', 'on') and is_state('sensor.work_laptop_connection_type', 'Ethernet') and not is_state('sensor.work_laptop_frontmost_app', 'loginwindow') %}
{% set workingHours = now() > today_at("08:30") and now() < today_at("17:30") %}
{{ isActive and workingHours }}
- name: Rose Away from Home
unique_id: rose_away
state: "{{ not is_state('person.rosemary_orchard', 'home') }}"
- name: >
{% if is_state("input_boolean.logic_asleep", "on") %}
Asleep
{% else %}
Awake
{% endif %}
unique_id: asleep
state: "{{ is_state('input_boolean.logic_asleep', 'on') }}"
icon: >
{% if is_state("input_boolean.logic_asleep", "on") %}
mdi:sleep
{% else %}
mdi:sleep-off
{% endif %}
- sensor:
- name: Sleep or Wake
state: >
{% set get_up_time = state_attr('script.getting_up', 'last_triggered') %}
{% set sleep_time = state_attr('script.time_to_sleep', 'last_triggered') %}
{{ (get_up_time > sleep_time) | iif('script.time_to_sleep', 'script.getting_up') }}
- name: "Average Living Room Temperature"
unique_id: average_lounge_temperature
unit_of_measurement: "°C"
state: >
{% set sensors = 'sensor.netatmo_queens_square_station_temperature', 'sensor.living_room_hue_sensor_temperature', 'sensor.living_room_door_temperature' %}
{% set sensors = expand(sensors) | rejectattr('state', 'eq', 'unavailable') | map(attribute='state') | map('float', none) | reject('eq', none) | list %}
{% if sensors | length > 0 %}
{{ sensors | average }}
{% else %}
15
{% endif %}
- name: "Average Hallway Temperature"
unique_id: average_hall_temperature
unit_of_measurement: "°C"
state: >
{% set sensors = 'sensor.hallway_climate_sensor_temperature', 'sensor.airer_temperature' %}
{% set sensors = expand(sensors) | rejectattr('state', 'eq', 'unavailable') | map(attribute='state') | map('float', none) | reject('eq', none) | list %}
{% if sensors | length > 0 %}
{{ sensors | average }}
{% else %}
15
{% endif %}
- name: "Average Office Temperature"
unique_id: average_office_temperature
unit_of_measurement: "°C"
state: >
{% set sensors = 'sensor.netatmo_queens_square_station_additional_smart_indoor_module_temperature', 'sensor.ble_temperature_office_clock', 'sensor.office_hue_sensor_temperature' %}
{% set sensors = expand(sensors) | rejectattr('state', 'eq', 'unavailable') | map(attribute='state') | map('float', none) | reject('eq', none) | list %}
{% if sensors | length > 0 %}
{{ sensors | average }}
{% else %}
15
{% endif %}
- name: "Average Bedroom Temperature"
unique_id: average_bedroom_temperature
unit_of_measurement: "°C"
state: >
{% set sensors = 'sensor.netatmo_bedroom_temperature', 'sensor.bedroom_hue_sensor_temperature' %}
{% set sensors = expand(sensors) | rejectattr('state', 'eq', 'unavailable') | map(attribute='state') | map('float', none) | reject('eq', none) | list %}
{% if sensors | length > 0 %}
{{ sensors | average }}
{% else %}
15
{% endif %}
- name: "Average Kitchen Temperature"
unique_id: average_kitchen_temperature
unit_of_measurement: "°C"
state: >
{% set sensors = 'sensor.kitchen_climate_sensor_temperature', 'sensor.kitchen_door_temperature', 'sensor.kitchen_motion_sensor_temperature' %}
{% set sensors = expand(sensors) | rejectattr('state', 'eq', 'unavailable') | map(attribute='state') | map('float', none) | reject('eq', none) | list %}
{% if sensors | length > 0 %}
{{ sensors | average }}
{% else %}
15
{% endif %}
- name: "Average Storage Cupboard Temperature"
unique_id: average_storeroom_temperature
unit_of_measurement: "°C"
state: >
{% set sensors = 'sensor.storage_cupboard_climate_sensor_temperature', 'sensor.storage_cupboard_door_sensor_temperature', 'sensor.storage_cupboard_flood_sensor_temperature' %}
{% set sensors = expand(sensors) | rejectattr('state', 'eq', 'unavailable') | map(attribute='state') | map('float', none) | reject('eq', none) | list %}
{% if sensors | length > 0 %}
{{ sensors | average }}
{% else %}
15
{% endif %}
- name: "Night Motion"
unique_id: "night_motion"
state: >
{% set asleep = is_state('input_select.rose_state', 'Sleep') %}
{% set motion = is_state('binary_sensor.bedroom_door_under_bed_motion_sensor_occupancy', 'on') or is_state('binary_sensor.bedroom_window_under_bed_motion_sensor_occupancy', 'on') %}
{{ asleep and motion }}
- name: "HA Uptime Seconds"
unique_id: uptime_seconds
state: >
{{ ( now() - states('sensor.uptime')|as_datetime ).seconds | default(60) }}
- name: "HA Uptime Minutes"
unique_id: uptime_minutes
state: >
{{ ((( now() - states('sensor.uptime')|as_datetime ).seconds / 60) | round) | default(1) }}
- name: "Grocy in 15 Minutes"
unique_id: "grocy_in_15"
state: >
{{ (now() + timedelta( minutes = 15 )).strftime('%Y-%m-%d %H:%M:%S') }}