Skip to content

Commit 9894685

Browse files
committed
Add motion sensing lights blueprint
1 parent 591ac4c commit 9894685

File tree

1 file changed

+228
-0
lines changed

1 file changed

+228
-0
lines changed

motion-sensing-lights.yaml

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
# adapted from https://github.com/iainsmacleod/Home-Assistant-Blueprints
2+
blueprint:
3+
name: Motion- or sensor- activated light with brightness and temperature
4+
description: Turn on lights when motion is detected, with brightness and temperature depending on sunrise/sunset (with offsets).
5+
domain: automation
6+
input:
7+
motion_sensors:
8+
name: Motion and Occupancy Sensors
9+
description: Select one or more motion or occupancy sensors.
10+
selector:
11+
entity:
12+
domain: binary_sensor
13+
device_class:
14+
- motion
15+
- occupancy
16+
- door
17+
multiple: true
18+
entity_target:
19+
name: Lights and Switches
20+
description: Select one or more lights or switches to control.
21+
selector:
22+
target:
23+
entity:
24+
domain:
25+
- light
26+
- switch
27+
no_motion_wait:
28+
name: Wait Time
29+
description: Time to leave the light on after last motion is detected.
30+
default: 120
31+
selector:
32+
number:
33+
min: 0
34+
max: 3600
35+
unit_of_measurement: seconds
36+
use_custom_settings:
37+
name: Use Changing Brightness and Temperature
38+
description: Enable to use brightness and temperature settings based on surrounding lights and light level.
39+
default: true
40+
selector:
41+
boolean:
42+
brightness_bright:
43+
name: Brightness (bright setting)
44+
description: Set the brightness level (0-255) used when high brightness is set.
45+
default: 255
46+
selector:
47+
number:
48+
min: 0
49+
max: 255
50+
brightness_dim:
51+
name: Brightness (dim setting)
52+
description: Set the brightness level (0-255) used when low brightness is set.
53+
default: 255
54+
selector:
55+
number:
56+
min: 0
57+
max: 255
58+
sun_offset_brightness:
59+
name: Sun Offset for Brightness (Optional)
60+
description: Offset from sunrise/sunset in format 'HH:MM' (e.g., '01:00' or '-01:00') at which light brightness reduces.
61+
default: "00:00"
62+
selector:
63+
text:
64+
temperature_cool:
65+
name: Cool temperature
66+
description: A cooler colour temperature, used during the day.
67+
default: 250
68+
selector:
69+
number:
70+
min: 1.0
71+
max: 600.0
72+
step: 1.0
73+
mode: slider
74+
temperature_warm:
75+
name: Warm temperature
76+
description: A warmer colour temperature, used at night.
77+
default: 375
78+
selector:
79+
number:
80+
min: 1.0
81+
max: 600.0
82+
step: 1.0
83+
mode: slider
84+
sun_offset_temperature:
85+
name: Sun Offset for Temperature (Optional)
86+
description: Offset from sunrise/sunset in format 'HH:MM' (e.g. '01:00' or '-01:00') at which light temperature turns warm.
87+
default: "00:00"
88+
selector:
89+
text:
90+
91+
mode: restart
92+
max_exceeded: silent
93+
94+
trigger:
95+
- platform: state
96+
entity_id: !input motion_sensors
97+
to: "on"
98+
99+
variables:
100+
use_custom_settings: !input use_custom_settings
101+
sun_offset: !input sun_offset
102+
entity_target: !input entity_target
103+
104+
condition:
105+
- condition: and
106+
conditions:
107+
- condition: or
108+
conditions:
109+
- condition: template
110+
value_template: "{{ blocking_entity == None or blocking_entity == '' }}"
111+
- condition: template
112+
value_template: >
113+
{% set blocking_states_list = blocking_states.split(',') | map('trim') | list %}
114+
{{ states(blocking_entity) not in blocking_states_list }}
115+
- condition: or
116+
conditions:
117+
- condition: template
118+
value_template: "{{ condition_entity == None or condition_entity == '' }}"
119+
- condition: template
120+
value_template: >
121+
{% set states_list = condition_states.split(',') | map('trim') | list %}
122+
{{ condition_entity != None and condition_entity != '' and states_list | length > 0 and states(condition_entity) in states_list }}
123+
- condition: or
124+
conditions:
125+
- condition: template
126+
value_template: "{{ sun_condition == 'none' }}"
127+
- condition: and
128+
conditions:
129+
- condition: template
130+
value_template: "{{ sun_condition == 'day' }}"
131+
- condition: sun
132+
after: sunrise
133+
after_offset: !input sun_offset
134+
before: sunset
135+
before_offset: !input sun_offset
136+
- condition: and
137+
conditions:
138+
- condition: template
139+
value_template: "{{ sun_condition == 'night' }}"
140+
- condition: or
141+
conditions:
142+
- condition: sun
143+
after: sunset
144+
after_offset: !input sun_offset
145+
- condition: sun
146+
before: sunrise
147+
before_offset: !input sun_offset
148+
149+
action:
150+
- choose:
151+
- conditions:
152+
- condition: template
153+
value_template: "{{ use_custom_settings }}"
154+
sequence:
155+
- choose:
156+
- conditions:
157+
- condition: template
158+
value_template: "{{ 'light.' in entity_target.entity_id|string }}"
159+
sequence:
160+
161+
- if:
162+
- condition: sun
163+
after: sunrise
164+
after_offset: !input sun_offset_brightness
165+
before: sunset
166+
before_offset: !input sun_offset_brightness
167+
then:
168+
- variables:
169+
brightness: !input brightness_bright
170+
else:
171+
- variables:
172+
brightness: !input brightness_dim
173+
- if:
174+
- condition: sun
175+
after: sunrise
176+
after_offset: !input sun_offset_temperature
177+
before: sunset
178+
before_offset: !input sun_offset_temperature
179+
then:
180+
- variables:
181+
temperature: !input temperature_cool
182+
else:
183+
- variables:
184+
temperature: !input temperature_warm
185+
186+
- service: light.turn_on
187+
target: !input entity_target
188+
data:
189+
brightness: "{{ brightness }}"
190+
color_temp: "{{ temperature }}"
191+
- conditions:
192+
- condition: template
193+
value_template: "{{ 'switch.' in entity_target.entity_id|string }}"
194+
sequence:
195+
- service: switch.turn_on
196+
target: !input entity_target
197+
default:
198+
- choose:
199+
- conditions:
200+
- condition: template
201+
value_template: "{{ 'light.' in entity_target.entity_id|string }}"
202+
sequence:
203+
- service: light.turn_on
204+
target: !input entity_target
205+
- conditions:
206+
- condition: template
207+
value_template: "{{ 'switch.' in entity_target.entity_id|string }}"
208+
sequence:
209+
- service: switch.turn_on
210+
target: !input entity_target
211+
- wait_for_trigger:
212+
platform: state
213+
entity_id: !input motion_sensors
214+
to: "off"
215+
- delay: !input no_motion_wait
216+
- choose:
217+
- conditions:
218+
- condition: template
219+
value_template: "{{ 'light.' in entity_target.entity_id|string }}"
220+
sequence:
221+
- service: light.turn_off
222+
target: !input entity_target
223+
- conditions:
224+
- condition: template
225+
value_template: "{{ 'switch.' in entity_target.entity_id|string }}"
226+
sequence:
227+
- service: switch.turn_off
228+
target: !input entity_target

0 commit comments

Comments
 (0)