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
blueprint:name:"Light with Motionsensor (SmartHome yourself)"description:| Turn on a light, when motion is detected for defined Time.
Switch off without motion if timeout reached and no motion for defined time.
(Light stays on longer, when manually turned on)domain: automation
source_url: https://smarthomeyourself.eu/wp-content/uploads/diy-projects/templates/home-assistant/blueprints/motion-light/shys_motion_light.yaml
# ---------------------------------------------# Eingabefelder# ---------------------------------------------input:motion_entity:name:"Motion Sensor"description:"The motionsensor to use"selector:entity:domain:- binary_sensor
device_class:- motion
- presence
- occupancy
multiple:falselight_sensor_entity:name:"Light Sensor (optional)"description:"The Light to use"default:[]selector:entity:domain:- sensor
device_class:- illuminance
multiple:falselux_limit:name:"Lux-Limit"description:| The limit of lux-value. If value of light-sensor is higher, then don't turn on the light on motion.default:100selector:number:min:1max:300unit_of_measurement:"lx"light_target:name: Light(s)
description: light to use
selector:target:entity:domain: light
all_day:name: Turn on only at night?description:"You can choose, if the light automatically turn on all day or only at night."default:"only at night"selector:select:options:-"switch on all day"-"only at night"no_motion_wait:name:"No motion time"description:| Time to leave the light on after last motion is detected.
(This time starts counting, when binary_sensor changes to "off")default:minutes:2selector:duration:light_auto_off_after:name:"Light on - timeout"description:| Time after which the light should be switched off,
if there has been no movement in the "No motion time" period.
(For the case of manual switch on)default:minutes:5selector:duration:default_brightness:name:"Default brightness"description:| The default brightness to set when automatically turn on the light.default:100selector:number:min:1max:100unit_of_measurement:"%"alternative_period_start:name:"Alternative period begin"description:| Start of the alternative period, when the alternative brightness should be set instead of the default brightness.
If you didn't need the alternative period, leave it at 00:00:00default:00:00:00selector:time:alternative_period_end:name:"Alternative period end"description:| End of the alternative period, when the alternative brightness should be set instead of the default brightness.
If you didn't need the alternative period, leave it at 00:00:00default:00:00:00selector:time:alternative_brightness:name:"Alternative brightness"description:| The brightness to set when automatically turn on the light in alternative period.
If you didn't need the alternative period, leave it at 100%default:100selector:number:min:1max:100unit_of_measurement:"%"# ---------------------------------------------# internals# ---------------------------------------------mode: restart
max_exceeded: silent
variables:all_day:!input all_day
my_lights:!input light_target
default_brightness:!input default_brightness
period_start:!input alternative_period_start
period_end:!input alternative_period_end
alternative_brightness:!input alternative_brightness
light_sensor_entity:!input light_sensor_entity
lux_limit:!input lux_limit
light_sensor_value:>-{% if light_sensor_entity !=[] %}{{states(light_sensor_entity) | float(0)}}{% else %} 0
{% endif %}brightness:>-{% if ( period_start < period_end and (now() >= today_at(period_start) and now() <= today_at(period_end)) ) or
( period_start > period_end and (now() >= today_at(period_start) or now() <= today_at(period_end)) ) %}{{alternative_brightness}}{% else %}{{default_brightness}}{% endif %}# ---------------------------------------------# Auslöser# ---------------------------------------------trigger:-platform: state
entity_id:!input motion_entity
from:"off"to:"on"id: bewegung
-platform: state
entity_id:!input motion_entity
to:"off"for:!input no_motion_wait
id: keine_bewegung
-platform: template
value_template:"{{ expand(my_lights.entity_id) | selectattr('state', '==', 'off') | list | count > 0 }}"for:!input light_auto_off_after
id: light_on_timeout
condition:[]# ---------------------------------------------# Aktionen# ---------------------------------------------action:# Licht bei Bewegung einschalten-choose:-conditions:-condition: trigger
id: bewegung
-condition: template
value_template:>-{{ expand(my_lights.entity_id) | selectattr('state','==', 'off') | list | count > 0 }}-condition: or
conditions:-condition: template
value_template:>-{{ all_day == 'switch on all day' }}-condition: state
entity_id: sun.sun
state: below_horizon
-condition: template
value_template:>-{{ (light_sensor_value | float(0)) < (lux_limit | float(0)) }}sequence:-action: light.turn_on
target:!input light_target
data:brightness_pct:'{{ brightness }}'# Licht ausschalten, wenn für die Dauer von {{no_motion_wait}}# keine Bewegung stattgefunden hat.-choose:-conditions:-condition: trigger
id: keine_bewegung
-condition: template
value_template:>-{{ expand(my_lights.entity_id) | selectattr('state','==', 'on') | list | count > 0 }}sequence:-action: light.turn_off
target:!input light_target
# Licht nach der Dauer von {{light_auto_off_after}} abschalten,# wenn keine Bewegung für Dauer von {{no_motion_wait}} existierte-choose:-conditions:-condition: trigger
id: light_on_timeout
-condition: state
entity_id:!input motion_entity
state:'off'for:!input no_motion_wait
-condition: template
value_template:>-{{ expand(my_lights.entity_id) | selectattr('state','==','on') | list | count > 0 }}sequence:-action: light.turn_off
target:!input light_target