forked from brigger/HomeAssistant_Blueprints
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvanced_custom_motion_sensor.yaml
227 lines (226 loc) · 7.94 KB
/
advanced_custom_motion_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
blueprint:
name: Advanced Custom Motion Sensor
description:
"This motion sensor is based on several ideas from other blueprints, and adding my own customizations.\n\n
\n\n
Inputs and actions are:\n
- Turn on lights or scenes when motion is detected. The trigger can be a motion detector or anything that switches between ON and OFF. You can use several motion detectors.\n
- The activation can be triggered between a certain time slot (so the bathroom light does not turn on in the middle of the night)\n
- You can specify a luminance value: only run when it is darker than indicated\n
- Sun horizon setting: you can run the action always, or only when the sun is above or below the horizon.\n
- You can adjust the horizon by giving an elevation adjustment number\n
- Wait time for turning off\n
- Only run if an optional entity is in desired state (optional)\n
- Default scene when motion stops (optional)\n
- Only run the motion off action if an optional entity is in desired state\n"
domain: automation
source_url: https://github.com/brigger/HomeAssistant_Blueprints/blob/main/advanced_custom_motion_sensor.yaml
input:
motion_entity:
name: Motion Sensor
description: Motion Sensor or a group with Motion Sensors (But can be anything switching between "Detected" and "Clear)
selector:
entity:
multiple: false
light_target:
name: Light
selector:
target:
entity:
domain: light
luminance_sensor:
name: Illuminance sensor
description: This sensor will be used to determine the illumination.
default:
selector:
entity:
domain: sensor
device_class: illuminance
multiple: false
luminance_required:
name: Required Lux Level
description: Lux level below which the automation will run.
default: 100
selector:
number:
min: 0
max: 10000
unit_of_measurement: lx
no_motion_wait:
name: Wait time
description: Time to leave the light on after last motion is detected.
default: 120
selector:
number:
min: 0.0
max: 600.0
unit_of_measurement: seconds
mode: slider
step: 1.0
time_default_start:
name: Only run default action after this time (Optional)
description: Default Light target will only run when time is later than this time value.
default: 00:00:00
selector:
time: {}
time_default_end:
name: Only run default action before this time (Optional)
description: Default Light target will only run when time is earlier than this time value.
default: 00:00:00
selector:
time: {}
elevation:
name: Elevation
description: Choose whether to check if the sun is above, below the horizon, or always trigger the action
default: Always
selector:
select:
options:
- Always
- Below horizon
- Above horizon
elevation_adjustment:
name: Sun elevation adjustment (Optional)
description: With a postivie number, the sun is further above the horizon. For instance, +10 approximately means the trigger will activate one hour before the sun is below horizon. A negative number moves the trigger further below the horizon.
default: 0
selector:
number:
min: -90.0
max: 90.0
unit_of_measurement: degrees
mode: slider
step: 1.0
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: {}
motion_off_blocker:
name: Motion Off Blocker (Optional)
description:
Motion off sequence (trigger goes from ON to OFF) is not run if this boolean is in desired state
(see next input)
default:
selector:
entity: {}
motion_off_blocker_boolean:
name: Motion Off Chooser (Optional)
description: Desired state of motion off blocker
default: false
selector:
boolean: {}
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
multiple: false
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: {}
mode: restart
max_exceeded: silent
variables:
scene_ambient: !input scene_ambient
automation_blocker: !input automation_blocker
automation_blocker_boolean: !input automation_blocker_boolean
motion_off_blocker: !input motion_off_blocker
motion_off_blocker_boolean: !input motion_off_blocker_boolean
elevation: !input elevation
elevation_adjustment: !input elevation_adjustment
motion_entity: !input motion_entity
luminance_sensor: !input luminance_sensor
luminance_required: !input luminance_required
trigger:
- platform: state
entity_id: !input motion_entity
from: "Clear"
to: "Detected"
- platform: state
entity_id: !input motion_entity
from: "Detected"
to: "Clear"
for: !input no_motion_wait
condition:
- 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'
}}"
- condition: template
value_template: >
{% if 'Always' == elevation %}
true
{% else %}
{% set sun_elevation = state_attr('sun.sun', 'elevation') %}
{% if sun_elevation is none %}
false
{% else %}
{%
if (sun_elevation > elevation_adjustment and 'Above horizon' == elevation) or
(sun_elevation <= elevation_adjustment and 'Below horizon' == elevation) %}
true
{% else %}
false
{% endif %}
{% endif %}
{% endif %}
action:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.to_state.state == 'on' }}"
- condition: numeric_state
entity_id: !input luminance_sensor
below: !input luminance_required
sequence:
- condition: time
after: !input time_default_start
before: !input time_default_end
- service: light.turn_on
target: !input light_target
- conditions:
- condition: template
value_template: "{{ trigger.to_state.state == 'off' }}"
- condition: or
conditions:
- "{{ motion_off_blocker == none }}"
- "{{ motion_off_blocker_boolean and states[motion_off_blocker].state == 'on'
}}"
- "{{ not motion_off_blocker_boolean and states[motion_off_blocker].state == 'off'
}}"
sequence:
- choose:
- conditions:
- "{{ scene_ambient != 'scene.none' }}"
- condition: time
after: !input time_scene_ambient_start
before: !input time_scene_ambient_end
sequence:
- scene: !input scene_ambient
default:
- service: light.turn_off
target: !input light_target