-
Notifications
You must be signed in to change notification settings - Fork 0
/
f1-r1-light-bg-splash-01.yaml
569 lines (530 loc) · 14.9 KB
/
f1-r1-light-bg-splash-01.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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
# BH1750:
# IO27: SDA
# IO25: SCL
# PIR:
# IO12
# DFRobot:
# IO13
# IO33: TX
# IO14: RX
# Button:
# IO32
# Button LED:
# IO15
# CCT:
# IO23:
# IO19:
# ----------------------------------------------------------------
substitutions:
# Project
#---------------------------------
device_name: f1-r1-light-bg-splash-01
comment: 'Kitchen light controller with PIR and MMWave sensors'
version: '0.4'
# Settings
#---------------------------------
web_server_include_internal: 'true'
mmwave_sensor_name: presence # dfrobot
pir_sensor_name: motion # pir
illuminance_senor_name: illuminance # bh1750
# HW settings (configurable)
#---------------------------------
i2c_sda: '27'
i2c_scl: '25'
uart_tx_pin: GPIO33
uart_rx_pin: GPIO14
ledc_warm_white: GPIO23
ledc_cold_white: GPIO19
pin_mmwave: GPIO13
pin_pir: GPIO12
pin_button: GPIO32
# Timeouts
#---------------------------------
timeout_pir: 5s
timeout_mmwave: 5s
timeout_combined: 5s
timeout_light_on: 150s
# common configuration
# ----------------------------------------------------------------
<<: !include common/esp32.yaml
<<: !include common/logger.yaml
<<: !include common/ota.yaml
<<: !include common/api.yaml
<<: !include common/wifi_dhcp_failover.yaml
<<: !include common/web_server.yaml
<<: !include common/sntp.yaml
# ----------------------------------------------------------------
esphome:
name: $device_name
comment: $comment
project:
name: timota.$device_name
version: $version
on_boot:
priority: 100
then:
# Disable DFRobot led by default
- logger.log: "boot::disable mmwave"
- switch.turn_off: mmwave_sensor
- delay: 1s
- logger.log: "boot::setLedMode"
- uart.write: "setLedMode 1 1"
- delay: 1s
# Disable presence output: Enable for debugging
- logger.log: "boot::setUartOutput"
- uart.write: "setUartOutput 1 0"
- delay: 1s
- logger.log: "boot::saveConfig"
- uart.write: "saveConfig"
- delay: 3s
- switch.turn_on: mmwave_sensor
- logger.log: "boot::enable mmwave"
# ------------------------------------
i2c:
sda: $i2c_sda
scl: $i2c_scl
scan: true
id: bus_a
# ------------------------------------
uart:
id: uart_bus
tx_pin: $uart_tx_pin
rx_pin: $uart_rx_pin
baud_rate: 115200
# DISABLE: disabled by default
debug:
direction: BOTH
dummy_receiver: true
after:
delimiter: "\n"
sequence:
- lambda: UARTDebug::log_string(direction, bytes);
# ------------------------------------
output:
- platform: ledc
pin: $ledc_warm_white
id: gpio_23
frequency: 1000 Hz
max_power: 100%
- platform: ledc
pin: $ledc_cold_white
id: gpio_19
frequency: 1000 Hz
max_power: 100%
# - id: button_led_output
# platform: gpio
# pin: GPIO15
# ------------------------------------
light:
- platform: cwww
name: $device_name
id: rgb_light
cold_white: gpio_19
warm_white: gpio_23
cold_white_color_temperature: 6536 K
warm_white_color_temperature: 2000 K
constant_brightness: true
default_transition_length: 3s
flash_transition_length: 2s
on_turn_on:
then:
- if:
condition:
- switch.is_off: enable_auto_effect
then:
- light.control:
id: rgb_light
effect: "Follow the sun"
else:
- light.control:
id: rgb_light
effect: "None"
effects:
- lambda:
name: Follow the sun
update_interval: 1min
lambda: |-
int minutes_since_midnight = (id(sntp_time).now().hour * 60) + id(sntp_time).now().minute;
ESP_LOGD("custom", "Minutes since midnight: %i", minutes_since_midnight);
int scale;
if (minutes_since_midnight <= 720) {
scale = map(minutes_since_midnight,0,720,500,153);
}
else if (minutes_since_midnight > 720 ) {
scale = map(minutes_since_midnight,720,1440,153,500);
}
ESP_LOGD("custom", "Scale: %i", scale);
auto call = id(rgb_light).turn_on();
call.set_color_temperature(scale);
call.perform();
# - platform: binary
# name: Main::Button Led
# id: button_led
# output: button_led_output
# internal: true
# ------------------------------------
sensor:
- platform: bh1750
name: ${device_name}-${illuminance_senor_name}
address: 0x23
update_interval: 30s
device_class: illuminance
# ------------------------------------
binary_sensor:
- platform: gpio
name: ${device_name}-presence
device_class: presence
id: mmwave_detection
# internal: true
pin:
number: $pin_mmwave
mode: INPUT_PULLDOWN
filters:
- delayed_off: $timeout_mmwave
on_press:
then:
- if:
condition:
- switch.is_off: motion_light_override
then:
- script.execute: lights_on_motion
- platform: gpio
name: ${device_name}-motion
device_class: motion
id: pir_detection
# internal: true
pin:
number: $pin_pir
mode: INPUT_PULLDOWN
filters:
- delayed_off: $timeout_pir
on_press:
then:
- if:
condition:
- switch.is_off: motion_light_override
then:
- script.execute: lights_on_motion
- platform: gpio
name: ${device_name}-button
id: push_button
internal: true
pin:
number: $pin_button
mode: INPUT_PULLUP
inverted: True
filters:
- delayed_on: 50ms
- delayed_off: 50ms
on_multi_click:
# Single click - turn on/off light
- timing:
- ON for at most 1s
- OFF for at least 400ms
then:
- light.toggle: rgb_light
# Double click - enable/disable auto effect
- timing:
- ON for at most 1s
- OFF for at most 399ms
- ON for at most 1s
- OFF for at least 400ms
then:
- if:
condition:
switch.is_on: enable_auto_effect
then:
- switch.template.publish:
id: enable_auto_effect
state: OFF
else:
- switch.template.publish:
id: enable_auto_effect
state: ON
- text_sensor.template.publish:
id: buttons
state: "button_pressed"
- delay: 50ms
- text_sensor.template.publish:
id: buttons
state: "double"
# Tripple click - enable/disable lights on motion
- timing:
- ON for at most 1s
- OFF for at most 399ms
- ON for at most 1s
- OFF for at most 399ms
- ON for at most 1s
- OFF for at least 400ms
then:
- if:
condition:
switch.is_on: motion_light_override
then:
- switch.template.publish:
id: motion_light_override
state: OFF
else:
- switch.template.publish:
id: motion_light_override
state: ON
- text_sensor.template.publish:
id: buttons
state: "button_pressed"
- delay: 50ms
- text_sensor.template.publish:
id: buttons
state: "triple"
# Hold - disable (auto effect)/(lights on motion)
- timing:
- ON for at least 10s
then:
- switch.template.publish:
id: motion_light_override
state: OFF
- switch.template.publish:
id: enable_auto_effect
state: OFF
- text_sensor.template.publish:
id: buttons
state: "button_pressed"
- delay: 50ms
- text_sensor.template.publish:
id: buttons
state: "button_long"
# ------------------------------------
switch:
- platform: template
name: ${device_name}-auto-motion
id: motion_light_override
optimistic: true
restore_state: true
entity_category: config
- platform: template
name: ${device_name}-auto-affect
id: enable_auto_effect
optimistic: true
restore_state: true
entity_category: config
turn_on_action:
- light.control:
id: rgb_light
effect: "None"
# - light.turn_off: button_led
turn_off_action:
- light.control:
id: rgb_light
effect: "Follow the sun"
# - light.turn_on: button_led
- platform: template
name: ${mmwave_sensor_name}-enable
id: "mmwave_sensor"
optimistic: true
restore_state: true
device_class: switch
entity_category: config
# internal: true
turn_on_action:
- uart.write: "sensorStart"
- delay: 1s
turn_off_action:
- uart.write: "sensorStop"
- delay: 1s
# - platform: template
# name: "${mmwave_sensor_name}-led"
# id: mmwave_led
# optimistic: true
# restore_state: true
# assumed_state: true
# entity_category: config
# turn_on_action:
# - switch.turn_off: mmwave_sensor
# - delay: 1s
# - uart.write: "setLedMode 1 0"
# - delay: 1s
# - uart.write: "saveConfig"
# - delay: 3s
# - switch.turn_on: mmwave_sensor
# turn_off_action:
# - switch.turn_off: mmwave_sensor
# - delay: 1s
# - uart.write: "setLedMode 1 1"
# - delay: 1s
# - uart.write: "saveConfig"
# - delay: 3s
# - switch.turn_on: mmwave_sensor
# - platform: template
# name: "${mmwave_sensor_name}-output-presence"
# id: "uart_presence_output"
# optimistic: true
# restore_state: true
# assumed_state: true
# entity_category: diagnostic
# turn_on_action:
# - switch.turn_off: mmwave_sensor
# - delay: 1s
# - uart.write: "setUartOutput 1 1"
# - delay: 1s
# - uart.write: "saveConfig"
# - delay: 3s
# - switch.turn_on: mmwave_sensor
# turn_off_action:
# - switch.turn_off: mmwave_sensor
# - delay: 1s
# - uart.write: "setUartOutput 1 0"
# - delay: 1s
# - uart.write: "saveConfig"
# - delay: 3s
# - switch.turn_on: mmwave_sensor
# - platform: template
# name: "${mmwave_sensor_name}-output-target"
# id: "uart_target_output"
# optimistic: true
# restore_state: true
# assumed_state: false
# entity_category: diagnostic
# turn_on_action:
# - switch.turn_off: mmwave_sensor
# - delay: 1s
# - uart.write: "setUartOutput 2 1 1 1"
# - delay: 1s
# - uart.write: "saveConfig"
# - delay: 3s
# - switch.turn_on: mmwave_sensor
# turn_off_action:
# - switch.turn_off: mmwave_sensor
# - delay: 1s
# - uart.write: "setUartOutput 2 0"
# - delay: 1s
# - uart.write: "saveConfig"
# - delay: 3s
# - switch.turn_on: mmwave_sensor
# ------------------------------------
number:
- platform: template
name: ${mmwave_sensor_name}-distance
id: mmwave_distance
min_value: 0.15
max_value: 9.45
initial_value: 3.15
optimistic: true
step: 0.15
restore_value: true
unit_of_measurement: M
mode: box
entity_category: config
set_action:
- switch.turn_off: mmwave_sensor
- delay: 1s
- uart.write: !lambda
std::string range = "setRange 0 " + str_sprintf("%.2f", x);
return std::vector<unsigned char>(range.begin(), range.end());
- delay: 1s
- uart.write: "saveConfig"
- delay: 1s
- switch.turn_on: mmwave_sensor
- delay: 1s
- platform: template
name: ${mmwave_sensor_name}-latency
id: mmwave_latency
min_value: 1
max_value: 600
initial_value: 90
optimistic: true
step: 1
restore_value: true
unit_of_measurement: s
mode: box
entity_category: config
set_action:
- switch.turn_off: mmwave_sensor
- delay: 1s
- uart.write: !lambda
std::string setL = "setLatency 0.1 " + str_sprintf("%.0f", x);
return std::vector<unsigned char>(setL.begin(), setL.end());
- delay: 1s
- uart.write: "saveConfig"
- delay: 1s
- switch.turn_on: mmwave_sensor
- platform: template
name: ${mmwave_sensor_name}-sensitivity
id: sensitivity
min_value: 0
max_value: 9
initial_value: 6
optimistic: true
step: 1
restore_value: true
entity_category: config
set_action:
- switch.turn_off: mmwave_sensor
- delay: 1s
- uart.write: !lambda
std::string mss = "setSensitivity " + to_string((int)x);
return std::vector<unsigned char>(mss.begin(), mss.end());
- delay: 1s
- uart.write: "saveConfig"
- delay: 1s
- switch.turn_on: mmwave_sensor
# ------------------------------------
button:
- platform: template
name: ${mmwave_sensor_name}-getSensitivity
entity_category: diagnostic
internal: true
on_press:
- uart.write: !lambda
std::string getS = "getSensitivity";
return std::vector<unsigned char>(getS.begin(), getS.end());
- platform: template
name: ${mmwave_sensor_name}-getLatency
entity_category: diagnostic
internal: true
on_press:
- uart.write: !lambda
std::string getL = "getLatency";
return std::vector<unsigned char>(getL.begin(), getL.end());
- platform: template
name: ${mmwave_sensor_name}-getRang
entity_category: diagnostic
internal: true
on_press:
- uart.write: !lambda
std::string getR = "getRange";
return std::vector<unsigned char>(getR.begin(), getR.end());
- platform: restart
name: ${device_name}-restart
entity_category: diagnostic
- platform: template
name: ${mmwave_sensor_name}-factory-reset
id: "factory_reset_dfrobot"
entity_category: diagnostic
internal: true
on_press:
- switch.turn_off: mmwave_sensor
- delay: 1s
- uart.write: "resetCfg"
- delay: 3s
- switch.turn_on: mmwave_sensor
# ------------------------------------
text_sensor:
- platform: template
name: ${device_name}-buttons
id: buttons
icon: "mdi:light-switch"
internal: true
# ------------------------------------
script:
- id: lights_on_motion
mode: restart
then:
- if:
condition:
- light.is_off: rgb_light
then:
- light.turn_on: rgb_light
- wait_until:
condition:
- binary_sensor.is_off: mmwave_detection
- delay: $timeout_light_on
- light.turn_off: rgb_light