Blueprint zur einfachen Lichtsteuerung mit Bewegungsmelder und optionalem Helligkeitssensor
1blueprint:
2 name: "Light with Motionsensor (SmartHome yourself)"
3 description: |
4 Turn on a light, when motion is detected for defined Time.
5 Switch off without motion if timeout reached and no motion for defined time.
6 (Light stays on longer, when manually turned on)
7 domain: automation
8 source_url: https://smarthomeyourself.eu/wp-content/uploads/diy-projects/templates/home-assistant/blueprints/motion-light/shys_motion_light.yaml
9
10 # ---------------------------------------------
11 # Eingabefelder
12 # ---------------------------------------------
13 input:
14 motion_entity:
15 name: "Motion Sensor"
16 description: "The motionsensor to use"
17 selector:
18 entity:
19 domain:
20 - binary_sensor
21 device_class:
22 - motion
23 - presence
24 - occupancy
25 multiple: false
26
27 light_sensor_entity:
28 name: "Light Sensor (optional)"
29 description: "The Light to use"
30 default: []
31 selector:
32 entity:
33 domain:
34 - sensor
35 device_class:
36 - illuminance
37 multiple: false
38
39 lux_limit:
40 name: "Lux-Limit"
41 description: |
42 The limit of lux-value. If value of light-sensor is higher, then don't turn on the light on motion.
43 default: 100
44 selector:
45 number:
46 min: 1
47 max: 300
48 unit_of_measurement: "lx"
49
50 light_target:
51 name: Light(s)
52 description: light to use
53 selector:
54 target:
55 entity:
56 domain: light
57
58 all_day:
59 name: Turn on only at night?
60 description: "You can choose, if the light automatically turn on all day or only at night."
61 default: "only at night"
62 selector:
63 select:
64 options:
65 - "switch on all day"
66 - "only at night"
67
68 no_motion_wait:
69 name: "No motion time"
70 description: |
71 Time to leave the light on after last motion is detected.
72 (This time starts counting, when binary_sensor changes to "off")
73 default:
74 minutes: 2
75 selector:
76 duration:
77
78 light_auto_off_after:
79 name: "Light on - timeout"
80 description: |
81 Time after which the light should be switched off,
82 if there has been no movement in the "No motion time" period.
83 (For the case of manual switch on)
84 default:
85 minutes: 5
86 selector:
87 duration:
88
89 default_brightness:
90 name: "Default brightness"
91 description: |
92 The default brightness to set when automatically turn on the light.
93 default: 100
94 selector:
95 number:
96 min: 1
97 max: 100
98 unit_of_measurement: "%"
99
100 alternative_period_start:
101 name: "Alternative period begin"
102 description: |
103 Start of the alternative period, when the alternative brightness should be set instead of the default brightness.
104 If you didn't need the alternative period, leave it at 00:00:00
105 default: 00:00:00
106 selector:
107 time:
108
109 alternative_period_end:
110 name: "Alternative period end"
111 description: |
112 End of the alternative period, when the alternative brightness should be set instead of the default brightness.
113 If you didn't need the alternative period, leave it at 00:00:00
114 default: 00:00:00
115 selector:
116 time:
117
118 alternative_brightness:
119 name: "Alternative brightness"
120 description: |
121 The brightness to set when automatically turn on the light in alternative period.
122 If you didn't need the alternative period, leave it at 100%
123 default: 100
124 selector:
125 number:
126 min: 1
127 max: 100
128 unit_of_measurement: "%"
129
130# ---------------------------------------------
131# internals
132# ---------------------------------------------
133mode: restart
134max_exceeded: silent
135
136variables:
137 all_day: !input all_day
138 my_lights: !input light_target
139 default_brightness: !input default_brightness
140 period_start: !input alternative_period_start
141 period_end: !input alternative_period_end
142 alternative_brightness: !input alternative_brightness
143 light_sensor_entity: !input light_sensor_entity
144 lux_limit: !input lux_limit
145 light_sensor_value: >-
146 {% if light_sensor_entity != [] %}
147 {{states(light_sensor_entity) | float(0)}}
148 {% else %}
149 0
150 {% endif %}
151 brightness: >-
152 {% if ( period_start < period_end and (now() >= today_at(period_start) and now() <= today_at(period_end)) ) or
153 ( period_start > period_end and (now() >= today_at(period_start) or now() <= today_at(period_end)) ) %}
154 {{alternative_brightness}}
155 {% else %}
156 {{default_brightness}}
157 {% endif %}
158
159# ---------------------------------------------
160# Auslöser
161# ---------------------------------------------
162trigger:
163 - platform: state
164 entity_id: !input motion_entity
165 from: "off"
166 to: "on"
167 id: bewegung
168
169 - platform: state
170 entity_id: !input motion_entity
171 to: "off"
172 for: !input no_motion_wait
173 id: keine_bewegung
174
175 - platform: template
176 value_template: "{{ expand(my_lights.entity_id) | selectattr('state', '==', 'off') | list | count > 0 }}"
177 for: !input light_auto_off_after
178 id: light_on_timeout
179
180condition: []
181
182# ---------------------------------------------
183# Aktionen
184# ---------------------------------------------
185action:
186 # Licht bei Bewegung einschalten
187 - choose:
188 - conditions:
189 - condition: trigger
190 id: bewegung
191 - condition: template
192 value_template: >-
193 {{ expand(my_lights.entity_id) | selectattr('state', '==', 'off') | list | count > 0 }}
194 - condition: or
195 conditions:
196 - condition: template
197 value_template: >-
198 {{ all_day == 'switch on all day' }}
199 - condition: state
200 entity_id: sun.sun
201 state: below_horizon
202 - condition: template
203 value_template: >-
204 {{ (light_sensor_value | float(0)) < (lux_limit | float(0)) }}
205 sequence:
206 - action: light.turn_on
207 target: !input light_target
208 data:
209 brightness_pct: '{{ brightness }}'
210
211 # Licht ausschalten, wenn für die Dauer von {{no_motion_wait}}
212 # keine Bewegung stattgefunden hat.
213 - choose:
214 - conditions:
215 - condition: trigger
216 id: keine_bewegung
217 - condition: template
218 value_template: >-
219 {{ expand(my_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0 }}
220 sequence:
221 - action: light.turn_off
222 target: !input light_target
223
224 # Licht nach der Dauer von {{light_auto_off_after}} abschalten,
225 # wenn keine Bewegung für Dauer von {{no_motion_wait}} existierte
226 - choose:
227 - conditions:
228 - condition: trigger
229 id: light_on_timeout
230 - condition: state
231 entity_id: !input motion_entity
232 state: 'off'
233 for: !input no_motion_wait
234 - condition: template
235 value_template: >-
236 {{ expand(my_lights.entity_id) | selectattr('state', '==','on') | list | count > 0 }}
237 sequence:
238 - action: light.turn_off
239 target: !input light_target