-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmal.yaml
338 lines (324 loc) · 12.5 KB
/
smal.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
blueprint:
name: SMAL – Smart Motion-Activated Lighting
description: >
# Introduction
The "Smart Motion-Activated Lighting" blueprint creates an automation that turns on lights or scenes when motion is detected. It has several optional features that allow users to customize the automation's behavior based on their needs.
## Optional Features
Some examples of how the optional features can be used include:
- Defining different scenes for different times of day (e.g. a bright scene for daytime and a warm, dim scene for nighttime)
- Activating an ambient scene during a specified time frame (e.g. a relaxing scene from 6pm to 10pm)
- Only running the automation if certain entities are in a desired state (e.g. only running if the house is unoccupied)
- Setting a "no motion blocker" to prevent the automation from running when a certain boolean is active (e.g. a "vacation" boolean that can be turned on when the user is away)
## Capabilities
- Triggers on motion (can be triggered by anything that switches between "on" and "off")
- Wait time for turning off lights
- Optional feature to only run if certain entities are in a desired state
- Optional feature to check sun elevation
- Optional feature to define 4 different scenes for different times of day
- Optional feature for an ambient scene with a specified time frame
- Optional feature for a default scene when motion stops
- Optional "no motion blocker" with user-specified state
- Transition time for scenes to turn off
- Inputs for motion sensor entity, light
domain: automation
source_url: https://gist.github.com/networkingcat/a1876d7e706e07c8bdcf974113940fb8
input:
motion_entity:
name: Motion Sensor
description: Motion Sensor or a group with Motion Sensors (But can be anything switching between "on" and "off")
selector:
entity:
light_target:
name: Light
selector:
target:
entity:
domain: light
#added from other blueprint
illuminance_sensor:
name: (OPTIONAL) Illuminance sensor
description: This sensor will be used to determine the illumination.
default:
selector:
entity:
domain: sensor
device_class: illuminance
illuminance_cutoff:
name: (OPTIONAL) Illuminance cutoff value
description: This input_number will be used to compare to the current illumination to determine if it is low.
default:
selector:
entity:
domain: input_number
#till here
no_motion_wait:
name: Wait time
description: Time to leave the light on after last motion is detected.
default: 120
selector:
number:
min: 0
max: 3600
unit_of_measurement: seconds
automation_blocker:
name: Automation Blocker (Optional)
description: Only run if this boolean is in desired state (see next input)
default:
selector:
entity:
automation_blocker_boolean:
name: Automation Blocker Chooser (Optional)
description: Desired state of automation blocker, choose on for on and off for off
default: false
selector:
boolean:
no_motion_blocker:
name: No Motion Blocker (Optional)
description: No motion sequence is not run if this boolean is in desired state (see next input)
default:
selector:
entity:
no_motion_blocker_boolean:
name: No Motion Chooser (Optional)
description: Desired state of no motion blocker, choose on for on and off for off
default: false
selector:
boolean:
elevation_check:
name: Sun elevation check (Optional)
description: This is the angle between the sun and the horizon. Negative values mean the sun is BELOW the horizon.
default: none
selector:
number:
min: -90
max: 90
unit_of_measurement: degrees
scene_ambient:
name: Ambient Scene (Optional)
description: Scene for ambient state. Will be activated when no motion is detected.
default: scene.none
selector:
entity:
domain: scene
time_scene_ambient_start:
name: Ambient time frame start (Optional)
description: Time from which on ambient scene will be activated
default: "00:00:00"
selector:
time:
time_scene_ambient_end:
name: Ambient time frame end (Optional)
description: Time from which on ambient scene will be not activated
default: "00:00:00"
selector:
time:
scene_morning:
name: Scene for the morning (Optional)
default: scene.none
selector:
entity:
domain: scene
time_scene_morning:
name: Time for the morning scene (Optional)
description: A time input which defines the time from which on the scene will be activated if motion is detected.
default: "00:00:00"
selector:
time:
scene_day:
name: Scene for the bright day (Optional)
default: scene.none
selector:
entity:
domain: scene
time_scene_day:
name: Time for the day scene (Optional)
description: A time input which defines the time from which on the scene will be activated if motion is detected.
default: "08:00:00"
selector:
time:
scene_evening:
name: Scene for the evening (Optional)
default: scene.none
selector:
entity:
domain: scene
time_scene_evening:
name: Time for the evening scene (Optional)
description: A time input which defines the time from which on the scene will be activated if motion is detected.
default: "21:00:00"
selector:
time:
scene_night:
name: Scene for the dark night (Optional)
default: scene.none
selector:
entity:
domain: scene
time_scene_night:
name: Time for the night scene (Optional)
description: A time input which defines the time from which on the scene will be activated if motion is detectedd.
default: "23:00:00"
selector:
time:
scene_no_motion:
name: Default scene for no motion (Optional)
description: Set this Scene if you want to activate a scene if motion stops
default: scene.none
selector:
entity:
domain: scene
transition_time:
name: Scene Transition
description: Time to transition scenes
default: 0
selector:
number:
min: 0
max: 600
unit_of_measurement: seconds
mode: restart
max_exceeded: silent
variables:
#added from other blueprint
illuminance_currently: !input illuminance_sensor
illuminance_cutoff: !input illuminance_cutoff
transition_time: !input transition_time
#till here
scene_ambient: !input scene_ambient
scene_morning: !input scene_morning
scene_day: !input scene_day
scene_evening: !input scene_evening
scene_night: !input scene_night
automation_blocker: !input automation_blocker
automation_blocker_boolean : !input automation_blocker_boolean
no_motion_blocker: !input no_motion_blocker
no_motion_blocker_boolean: !input no_motion_blocker_boolean
elevation_check: !input elevation_check
scene_no_motion: !input scene_no_motion
motion_entity: !input motion_entity
trigger:
- platform: state
entity_id: !input motion_entity
from: "off"
to: "on"
- platform: state
entity_id: !input motion_entity
from: "on"
to: "off"
for: !input no_motion_wait
# All Conditions must be true
condition:
# Check if automation blocker exist or is in desired state, otherwise do not run
- condition: or
conditions:
- "{{ automation_blocker == none }}"
- "{{ automation_blocker_boolean and states[automation_blocker].state == 'on' }}"
- "{{ not automation_blocker_boolean and states[automation_blocker].state == 'off' }}"
# Check if elevation input exist or is below desired value, otherwise do not run
- condition: template
value_template: "{{ (elevation_check == none) or (state_attr('sun.sun','elevation') <= elevation_check | float(90)) }}"
action:
- choose:
# Trigger to state == "on"
- conditions:
- condition: template
value_template: "{{ trigger.to_state.state == 'on' }}"
#added from other blueprint
- condition: template
value_template: "{{ (illuminance_currently == none) or (illuminance_cutoff == none) or (states[illuminance_currently].state | int < states[illuminance_cutoff].state | int) }}"
#till here
sequence:
- choose:
# Morning Scene
- conditions:
- "{{ scene_morning != 'scene.none'}}"
- condition: time
after: !input time_scene_morning
before: !input time_scene_day
sequence:
- service: scene.turn_on
data:
transition: !input transition_time
target:
entity_id: !input scene_morning
# Day Scene
- conditions:
- "{{ scene_day != 'scene.none'}}"
- condition: time
after: !input time_scene_day
before: !input time_scene_evening
sequence:
- service: scene.turn_on
data:
transition: !input transition_time
target:
entity_id: !input scene_day
# Evening Scene
- conditions:
- "{{ scene_evening != 'scene.none'}}"
- condition: time
after: !input time_scene_evening
before: !input time_scene_night
sequence:
- service: scene.turn_on
data:
transition: !input transition_time
target:
entity_id: !input scene_evening
# Night Scene
- conditions:
- "{{ scene_night != 'scene.none'}}"
- condition: time
after: !input time_scene_night
before: !input time_scene_morning
sequence:
- service: scene.turn_on
data:
transition: !input transition_time
target:
entity_id: !input scene_night
# If State -> "On" defaulting to turn light on
default:
- service: light.turn_on
target: !input light_target
data:
transition: !input transition_time
# Trigger to state = "off"
- conditions:
- condition: template
value_template: "{{ trigger.to_state.state == 'off' }}"
# Check if no motion blocker exist or in in desired state, otherwise do not run any no motion action
- condition: or
conditions:
- "{{ no_motion_blocker == none }}"
- "{{ no_motion_blocker_boolean and states[no_motion_blocker].state == 'on' }}"
- "{{ not no_motion_blocker_boolean and states[no_motion_blocker].state == 'off' }}"
sequence:
- choose:
# Used if ambient scene is true and in ambient scene time frame
- conditions:
- "{{ scene_ambient != 'scene.none' }}"
- condition: time
after: !input time_scene_ambient_start
before: !input time_scene_ambient_end
sequence:
- service: scene.turn_on
data:
transition: !input transition_time
target:
entity_id: !input scene_ambient
# Used if default no motion scene is set
- conditions:
- "{{ scene_no_motion != 'scene.none' }}"
sequence:
- service: scene.turn_on
data:
transition: !input transition_time
target:
entity_id: !input scene_no_motion
# If State -> "off" default to turn lights off
default:
- service: light.turn_off
target: !input light_target
data:
transition: !input transition_time