-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example-bs2-with-features.yaml
389 lines (355 loc) · 9.69 KB
/
example-bs2-with-features.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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
esphome:
name: sense-u
friendly_name: Sense-U
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
reboot_timeout: 0s
encryption:
key: "[Generate]"
ota:
password: "1d45b7655fa5e1444ac9d00ee5e81c4f"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "${device_name} HS"
password: "123456780"
ap_timeout: 1min
captive_portal:
external_components:
- source: github://andyboeh/esphome-sense-u
components: senseu
esp32_ble_tracker:
ble_client:
- mac_address: F1:7A:31:0E:EA:82
id: my_senseu_ble
senseu:
- ble_client_id: my_senseu_ble
id: my_senseu
# baby_code is optional. Needs to be retrieved during pairing phase.
# This allows using the Sense-U with multiple devices, e.g. at different
# locations.
#baby_code: 86eb0eb678f0
globals:
- id: main_light_mode
type: std::string
restore_value: no
- id: alarm_time
type: int
restore_value: no
initial_value: "0"
# Example configuration entry
sensor:
- platform: senseu
id: my_senseu
breath_rate:
name: Breathing Rate
id: breathing_rate
temperature:
name: Temperature
id: temperature
humidity:
name: Humidity
id: humidity
battery_level:
name: Battery Level
id: battery
# Uptime sensor
- platform: uptime
name: Uptime
id: senseu_uptime
# WiFi Signal sensor
- platform: wifi_signal
name: Wifi Signal
update_interval: 60s
id: senseu_wifi_signal
- platform: template
id: main_light_logic
internal: true
update_interval: 2s
lambda: |-
if ((id(breathing_alarm).state == 1 or id(posture_alarm).state == 1 or id(temperature_alarm).state == 1)) {
if (id(main_light_mode) != "red_strobe") {
auto set_light = id(main_light).turn_on();
set_light.set_effect("Red Strobe");
set_light.perform();
id(main_light_mode) = "red_strobe";
id(alarm_time) = id(homeassistant_time).now().timestamp;
}
} else if (id(main_light_mode) == "yellow_pulse") {
id(buzzer_switch).turn_off();
} else if (id(battery_alarm).state == 1) {
if (id(main_light_mode) != "purple_dim") {
auto set_light = id(main_light).turn_on();
set_light.set_effect("none");
set_light.set_rgb(1.0,0.0,1.0);
set_light.set_transition_length(500);
set_light.set_brightness(0.5);
set_light.perform();
id(main_light_mode) = "purple_dim";
id(buzzer_switch).turn_off();
}
} else if (id(party_mode).state == 1){
if (id(main_light_mode) != "party"){
auto set_light = id(main_light).turn_on();
set_light.set_effect("Party Mode");
set_light.set_transition_length(500);
set_light.set_brightness(0.5);
set_light.perform();
id(main_light_mode) = "party";
id(buzzer_switch).turn_off();
}
} else if (id(night_light).state == 1){
if (id(main_light_mode) != "night_light"){
auto set_light = id(main_light).turn_on();
set_light.set_rgb(1.0,0.0,0.0);
set_light.set_effect("flicker");
set_light.set_transition_length(500);
set_light.set_brightness(0.25);
set_light.perform();
id(main_light_mode) = "night_light";
id(buzzer_switch).turn_off();
}
} else {
if (id(main_light_mode) != "off"){
auto set_light = id(main_light).turn_off();
set_light.perform();
id(main_light_mode) = "off";
id(buzzer_switch).turn_off();
}
}
return {};
- platform: template
id: buzzer_logic
internal: true
update_interval: 2s
lambda: |-
if(id(main_light_mode) == "red_strobe" and (id(homeassistant_time).now().timestamp > (id(alarm_time) + 30 )) and !id(buzzer_switch).state) {
id(buzzer_switch).turn_on();
}
return {};
time:
- platform: homeassistant
id: homeassistant_time
# Text sensors with general information
text_sensor:
- platform: wifi_info
ip_address:
name: IP Address
id: ip
- platform: senseu
id: my_senseu
posture:
name: Posture
id: posture
status:
name: Status
id: senseu_status
on_value:
then:
- lambda: |-
if (id(senseu_status).state == "Connected") {
auto set_light = id(status_light).turn_on();
set_light.set_effect("none");
set_light.set_rgb(0.0,1.0,0.0);
set_light.set_transition_length(500);
set_light.set_brightness(0.5);
set_light.perform();
} else if (id(senseu_status).state == "Connecting") {
auto set_light = id(status_light).turn_on();
set_light.set_effect("Fast Pulse");
set_light.set_rgb(0.0,0.0,1.0);
set_light.perform();
} else if (id(senseu_status).state == "Disconnected") {
auto set_light = id(status_light).turn_on();
set_light.set_effect("none");
set_light.set_rgb(1.0,0.0,0.0);
set_light.set_transition_length(500);
set_light.set_brightness(0.5);
set_light.perform();
} else {
auto set_light = id(status_light).turn_on();
set_light.set_effect("none");
set_light.set_rgb(1.0,0.0,0.0);
set_light.set_transition_length(500);
set_light.set_brightness(0.5);
set_light.perform();
}
output:
- platform: ledc
pin: GPIO4
id: buzzer
- platform: ledc
pin: GPIO17
id: status_output_green
- platform: ledc
pin: GPIO18
id: status_output_blue
- platform: ledc
pin: GPIO5
id: status_output_red
- platform: ledc
pin: GPIO27
id: main_output_blue
- platform: ledc
pin: GPIO32
id: main_output_green
- platform: ledc
pin: GPIO33
id: main_output_red
switch:
- platform: template
name: Buzzer Switch
id: buzzer_switch
internal: true
optimistic: true
turn_on_action:
- output.turn_on: buzzer
- output.ledc.set_frequency:
id: buzzer
frequency: "1000Hz"
- output.set_level:
id: buzzer
level: "50%"
turn_off_action:
- output.turn_off: buzzer
- platform: senseu
senseu_id: my_senseu
name: Power Switch
id: power_switch
- platform: template
name: Party Mode
id: party_mode
optimistic: true
restore_mode: always_off
on_turn_on:
then:
- switch.turn_off: night_light
- platform: template
name: Night Light
id: night_light
optimistic: true
restore_mode: always_off
on_turn_on:
then:
- switch.turn_off: party_mode
binary_sensor:
- platform: gpio
pin:
number: GPIO25
inverted: yes
name: Reset Button
id: reset_button
- platform: gpio
pin: GPIO14
id: touch_sensor
name: Touch Sensor
on_click:
then:
- if:
condition:
not:
text_sensor.state:
id: senseu_status
state: 'Connected'
then:
- switch.turn_on: power_switch
- light.turn_on:
id: status_light
effect: "Medium Pulse"
red: 100%
green: 100%
blue: 0%
on_multi_click:
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 0.2s
then:
- switch.turn_off: power_switch
- light.turn_on:
id: status_light
effect: "Fast Pulse"
red: 100%
green: 100%
blue: 0%
- switch.turn_off: party_mode
- switch.turn_off: night_light
- platform: senseu
id: my_senseu
breath:
name: Breathing Alarm
id: breathing_alarm
posture:
name: Posture Alarm
id: posture_alarm
temperature:
name: Temperature Alarm
id: temperature_alarm
battery:
name: Battery Alarm
id: battery_alarm
light:
- platform: rgb
name: Status Light
id: status_light
internal: true
red: status_output_red
green: status_output_green
blue: status_output_blue
effects:
- pulse:
name: "Slow Pulse"
transition_length: 3s
update_interval: 3.5s
- pulse:
name: "Medium Pulse"
transition_length: 1.5s
update_interval: 1.5s
- pulse:
name: "Fast Pulse"
transition_length: .5s
update_interval: .5s
- platform: rgb
name: Main Light
id: main_light
internal: true
red: main_output_red
green: main_output_green
blue: main_output_blue
effects:
- pulse:
name: "Slow Pulse"
transition_length: 3s
update_interval: 4s
- pulse:
name: "Medium Pulse"
transition_length: 1.5s
update_interval: 2s
- pulse:
name: "Fast Pulse"
transition_length: .5s
update_interval: .5s
- flicker
- strobe:
name: Red Strobe
colors:
- state: true
brightness: 100%
red: 100%
green: 0%
blue: 0%
duration: 500ms
- state: false
duration: 500ms
- random:
name: Party Mode
transition_length: 5s
update_interval: 7s