forked from EverythingSmartHome/everything-presence-one
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheverything-presence-one-st-sen0609.yaml
More file actions
768 lines (719 loc) · 22.4 KB
/
everything-presence-one-st-sen0609.yaml
File metadata and controls
768 lines (719 loc) · 22.4 KB
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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
substitutions:
name: "everything-presence-st"
room: ""
friendly_name: "Everything Presence One ST"
project_name: "Everything Smart Technology.Everything Presence One"
project_version: "1.2.11s"
temperature_offset: "-3"
humidity_offset: "5"
temperature_update_interval: "60s"
illuminance_update_interval: "30s"
pir_delay_off: "10s"
occupancy_delay_off: "15s"
hidden_ssid: "false"
factory_reset_disabled: "true"
uart_target_output_disabled: "true"
uart_presence_output_disabled: "true"
esphome:
name: "${name}"
name_add_mac_suffix: true
project:
name: "${project_name}"
version: "${project_version}"
on_boot:
priority: -100
then:
- uart.write: "sensorStart"
esp32:
board: esp32dev
framework:
type: esp-idf
logger:
ota:
- platform: esphome
web_server:
wifi:
fast_connect: ${hidden_ssid}
ap: {}
captive_portal:
improv_serial:
light:
- platform: status_led
name: "ESP32 Status LED"
pin: GPIO32
entity_category: config
i2c:
sda: 26
scl: 25
scan: true
sensor:
- platform: shtcx
temperature:
name: "${room} Temperature"
filters:
offset: ${temperature_offset}
humidity:
name: "${room} Humidity"
filters:
offset: ${humidity_offset}
address: 0x70
update_interval: ${temperature_update_interval}
- platform: bh1750
name: "${room} Illuminance"
address: 0x23
update_interval: ${illuminance_update_interval}
filters:
- calibrate_linear:
method: exact
datapoints:
- 0.3 -> 0.3
- 0.9 -> 1.7
- 1.2 -> 3.6
- 3.2 -> 6.9
- 5.1 -> 10.2
- 6.8 -> 27.1
- 7.0 -> 13.5
- 7.4 -> 28.2
- 8.7 -> 21.7
- 8.9 -> 17.1
- 10.9 -> 20.4
- 12.8 -> 23.5
- 14.5 -> 31.2
- 14.9 -> 26.7
- 16.8 -> 41.1
- 16.9 -> 30.2
- 18.8 -> 33.4
- 19.1 -> 35.8
- 20.7 -> 37.0
- 24.3 -> 60.3
- 26.1 -> 68.6
- 26.7 -> 83.8
- 30.2 -> 75.9
- 32.6 -> 80.3
- 34.6 -> 83.2
- 40.4 -> 99.9
- 48.0 -> 183.7
- 48.3 -> 119.2
- 55.5 -> 141.3
- 55.8 -> 137.9
- 63.8 -> 157.6
- 71.5 -> 176.9
- 79.8 -> 197.1
- 84.3 -> 205.7
- clamp:
min_value: 0
# Distance and speed sensors for tracking mode
- platform: template
name: "mmWave Target Distance"
id: mmwave_target_distance
unit_of_measurement: "m"
accuracy_decimals: 2
device_class: distance
state_class: measurement
disabled_by_default: true
entity_category: diagnostic
- platform: template
name: "mmWave Target Speed"
id: mmwave_target_speed
unit_of_measurement: "m/s"
accuracy_decimals: 2
state_class: measurement
disabled_by_default: true
entity_category: diagnostic
- platform: template
name: "mmWave Target Energy"
id: mmwave_target_energy
accuracy_decimals: 0
state_class: measurement
disabled_by_default: true
entity_category: diagnostic
- platform: template
name: "mmWave Target Count"
id: mmwave_target_count
accuracy_decimals: 0
state_class: measurement
disabled_by_default: true
entity_category: diagnostic
binary_sensor:
- platform: gpio
name: ${room} mmWave
id: mmwave
device_class: occupancy
pin:
number: GPIO17
mode: INPUT_PULLDOWN
- platform: gpio
pin:
number: 33
mode: INPUT_PULLDOWN
name: ${room} PIR
id: pir_motion_sensor
device_class: motion
filters:
- delayed_off: ${pir_delay_off}
- platform: template
name: ${room} Occupancy
id: occupancy
device_class: occupancy
filters:
- delayed_off: ${occupancy_delay_off}
lambda: |-
if ( id(mmwave).state or id(pir_motion_sensor).state) {
return true;
}
else if (id(mmwave).state == 0 and id(pir_motion_sensor).state == 0) {
return false;
}
else {
return id(occupancy).state;
}
uart:
id: uart_bus
tx_pin: GPIO14
rx_pin: GPIO13
baud_rate: 9600
debug:
direction: BOTH
dummy_receiver: true
after:
delimiter: "\n"
sequence:
- lambda: |-
UARTDebug::log_string(direction, bytes);
// Only process incoming data
if (direction == UART_DIRECTION_RX) {
std::string data = "";
for (int i = 0; i < bytes.size(); i++) {
data += char(bytes[i]);
}
// Parse presence detection data: $DFHPD,1,,,*
if (data.find("$DFHPD") == 0) {
size_t comma1 = data.find(',', 6);
if (comma1 != std::string::npos) {
std::string presence_str = data.substr(comma1 + 1, 1);
if (presence_str == "1") {
id(mmwave).publish_state(true);
} else if (presence_str == "0") {
id(mmwave).publish_state(false);
}
}
}
// This section is used for factory reset to sync the UI
static std::string last_query_command = "";
if (data.find("getRange") == 0) {
last_query_command = "getRange";
} else if (data.find("getSensitivity") == 0) {
last_query_command = "getSensitivity";
} else if (data.find("getLatency") == 0) {
last_query_command = "getLatency";
} else if (data.find("getTrigRange") == 0) {
last_query_command = "getTrigRange";
}
if (data.find("Response ") == 0) {
std::string response_data = data.substr(9);
if (last_query_command == "getRange") {
size_t space_pos = response_data.find(' ');
if (space_pos != std::string::npos) {
float min_range = atof(response_data.substr(0, space_pos).c_str());
float max_range = atof(response_data.substr(space_pos + 1).c_str());
id(mmwave_min_distance).publish_state(min_range * 100);
id(mmwave_distance).publish_state(max_range * 100);
}
}
else if (last_query_command == "getSensitivity") {
size_t space_pos = response_data.find(' ');
if (space_pos != std::string::npos) {
float sustain = atof(response_data.substr(0, space_pos).c_str());
float trigger = atof(response_data.substr(space_pos + 1).c_str());
id(mmwave_sensitivity).publish_state(sustain);
id(mmwave_trigger_sensitivity).publish_state(trigger);
}
}
else if (last_query_command == "getLatency") {
size_t space_pos = response_data.find(' ');
if (space_pos != std::string::npos) {
float on_lat = atof(response_data.substr(0, space_pos).c_str());
float off_lat = atof(response_data.substr(space_pos + 1).c_str());
id(mmwave_on_latency).publish_state(on_lat);
id(mmwave_off_latency).publish_state(off_lat);
}
}
else if (last_query_command == "getTrigRange") {
float trig_range = atof(response_data.c_str());
id(mmwave_trigger_distance).publish_state(trig_range);
}
last_query_command = "";
}
// Parse distance and speed data: $DFDMD,target_count,target_number,distance,speed,energy,,*
if (data.find("$DFDMD") == 0) {
// Throttling for distance/speed updates
static uint32_t last_distance_update = 0;
uint32_t now = millis();
// Get throttle interval from user setting
uint32_t throttle_interval = 400; // Default 0.4s
if (id(mmwave_update_rate).state == "0.3s") {
throttle_interval = 300;
} else if (id(mmwave_update_rate).state == "0.4s") {
throttle_interval = 400;
} else if (id(mmwave_update_rate).state == "0.5s") {
throttle_interval = 500;
}
std::vector<std::string> parts;
std::string current = "";
for (char c : data) {
if (c == ',') {
parts.push_back(current);
current = "";
} else {
current += c;
}
}
parts.push_back(current); // Add last part
if (parts.size() >= 6) {
// Target count - always update for binary sensor
int target_count = 0;
if (parts[1].length() > 0 && parts[1] != " ") {
target_count = atoi(parts[1].c_str());
}
// Update mmWave binary sensor based on target count when in distance mode
if (id(mmwave_mode).state == "Distance and Speed") {
id(mmwave).publish_state(target_count > 0);
}
// Throttle distance/speed sensor updates
if (now - last_distance_update >= throttle_interval) {
last_distance_update = now;
// Target count
id(mmwave_target_count).publish_state(target_count);
// Distance (parts[3])
if (parts[3].length() > 0 && parts[3] != " ") {
float distance = atof(parts[3].c_str());
id(mmwave_target_distance).publish_state(distance);
} else {
id(mmwave_target_distance).publish_state(NAN);
}
// Speed (parts[4])
if (parts[4].length() > 0 && parts[4] != " ") {
float speed = atof(parts[4].c_str());
id(mmwave_target_speed).publish_state(speed);
} else {
id(mmwave_target_speed).publish_state(NAN);
}
// Energy (parts[5])
if (parts[5].length() > 0 && parts[5] != " " && parts[5].find('*') == std::string::npos) {
int energy = atoi(parts[5].c_str());
id(mmwave_target_energy).publish_state(energy);
} else {
id(mmwave_target_energy).publish_state(NAN);
}
}
}
}
}
switch:
- platform: template
name: "mmWave Sensor"
id: "mmwave_sensor"
entity_category: config
optimistic: true
restore_mode: DISABLED
turn_on_action:
- uart.write: "sensorStart"
- delay: 1s
turn_off_action:
- uart.write: "sensorStop"
- delay: 1s
- platform: template
name: "mmWave LED"
id: "mmwave_led"
entity_category: config
optimistic: true
restore_mode: DISABLED
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: "uart_presence_output"
id: "uart_presence_output"
entity_category: config
internal: ${uart_presence_output_disabled}
optimistic: true
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: "uart_target_output"
id: "uart_target_output"
entity_category: config
internal: ${uart_target_output_disabled}
optimistic: true
assumed_state: false
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
- platform: template
name: "Micro-motion Detection"
id: micro_motion_detection
entity_category: config
icon: mdi:motion-sensor
optimistic: true
disabled_by_default: true
restore_mode: RESTORE_DEFAULT_OFF
turn_on_action:
- if:
condition:
lambda: 'return id(mmwave_mode).state == "Distance and Speed";'
then:
- switch.turn_off: mmwave_sensor
- delay: 1s
- uart.write: "setMicroMotion 1"
- delay: 1s
- uart.write: "saveConfig"
- delay: 1s
- switch.turn_on: mmwave_sensor
turn_off_action:
- if:
condition:
lambda: 'return id(mmwave_mode).state == "Distance and Speed";'
then:
- switch.turn_off: mmwave_sensor
- delay: 1s
- uart.write: "setMicroMotion 0"
- delay: 1s
- uart.write: "saveConfig"
- delay: 1s
- switch.turn_on: mmwave_sensor
select:
- platform: template
name: "mmWave Mode"
id: mmwave_mode
entity_category: config
icon: mdi:radar
optimistic: true
disabled_by_default: true
options:
- "Presence Detection"
- "Distance and Speed"
initial_option: "Presence Detection"
restore_value: true
set_action:
- switch.turn_off: mmwave_sensor
- delay: 1s
- if:
condition:
lambda: 'return x == "Distance and Speed";'
then:
- uart.write: "setRunApp 1"
- delay: 1s
- uart.write: "saveConfig"
- delay: 1s
- switch.turn_on: mmwave_sensor
- delay: 2s
- switch.turn_on: uart_target_output
else:
- uart.write: "setRunApp 0"
- delay: 1s
- uart.write: "saveConfig"
- delay: 1s
- switch.turn_on: mmwave_sensor
- delay: 2s
- switch.turn_off: uart_target_output
- platform: template
name: "Distance/Speed Update Rate"
id: mmwave_update_rate
entity_category: config
icon: mdi:timer
optimistic: true
disabled_by_default: true
options:
- "0.3s"
- "0.4s"
- "0.5s"
initial_option: "0.5s"
restore_value: true
number:
- platform: template
name: mmWave Min Distance
id: mmwave_min_distance
entity_category: config
min_value: 0
max_value: 2500
initial_value: 0
optimistic: true
step: 10
restore_value: true
unit_of_measurement: cm
mode: slider
set_action:
- switch.turn_off: mmwave_sensor
- delay: 1s
- uart.write: !lambda
int min = id(mmwave_min_distance).state / 100;
int max = id(mmwave_distance).state / 100;
std::string ms = "setRange " + to_string(min) + " " + to_string(max);
return std::vector<unsigned char>(ms.begin(), ms.end());
- delay: 1s
- uart.write: "saveConfig"
- delay: 1s
- switch.turn_on: mmwave_sensor
- platform: template
name: mmWave Distance
id: mmwave_distance
entity_category: config
min_value: 0
max_value: 2500
initial_value: 300
optimistic: true
step: 10
restore_value: true
unit_of_measurement: cm
mode: slider
set_action:
- switch.turn_off: mmwave_sensor
- delay: 1s
- uart.write: !lambda
int min = id(mmwave_min_distance).state / 100;
int max = id(mmwave_distance).state / 100;
std::string ms = "setRange " + to_string(min) + " " + to_string(max);
return std::vector<unsigned char>(ms.begin(), ms.end());
- delay: 1s
- uart.write: "saveConfig"
- delay: 1s
- switch.turn_on: mmwave_sensor
- platform: template
name: mmWave Off Latency
id: mmwave_off_latency
entity_category: config
min_value: 1
max_value: 60
initial_value: 15
optimistic: true
step: 1
restore_value: true
unit_of_measurement: seconds
mode: slider
set_action:
- switch.turn_off: mmwave_sensor
- delay: 1s
- uart.write: !lambda |-
std::string mss = "setLatency " + to_string(id(mmwave_on_latency).state) + " " + to_string(id(mmwave_off_latency).state);
return std::vector<unsigned char>(mss.begin(), mss.end());
- delay: 1s
- uart.write: "saveConfig"
- delay: 1s
- switch.turn_on: mmwave_sensor
- platform: template
name: mmWave On Latency
id: mmwave_on_latency
entity_category: config
min_value: 0
max_value: 60
initial_value: 0
optimistic: true
step: 0.5
restore_value: true
unit_of_measurement: seconds
mode: slider
set_action:
- switch.turn_off: mmwave_sensor
- delay: 1s
- uart.write: !lambda |-
std::string mss = "setLatency " + to_string(id(mmwave_on_latency).state) + " " + to_string(id(mmwave_off_latency).state);
return std::vector<unsigned char>(mss.begin(), mss.end());
- delay: 1s
- uart.write: "saveConfig"
- delay: 1s
- switch.turn_on: mmwave_sensor
- platform: template
name: mmWave Trigger Distance
icon: mdi:radar
id: mmwave_trigger_distance
entity_category: config
min_value: 0
max_value: 25
initial_value: 6
optimistic: true
step: 0.1
restore_value: true
unit_of_measurement: m
mode: slider
set_action:
- if:
condition:
lambda: 'return id(mmwave_mode).state == "Presence Detection";'
then:
- switch.turn_off: mmwave_sensor
- delay: 1s
- uart.write: !lambda |-
std::string mss = "setTrigRange " + to_string(x);
return std::vector<unsigned char>(mss.begin(), mss.end());
- delay: 1s
- uart.write: "saveConfig"
- delay: 1s
- switch.turn_on: mmwave_sensor
- platform: template
name: mmWave Sensitivity
id: mmwave_sensitivity
entity_category: config
min_value: 0
max_value: 9
initial_value: 7
optimistic: true
step: 1
restore_value: true
set_action:
- if:
condition:
lambda: 'return id(mmwave_mode).state == "Presence Detection";'
then:
- switch.turn_off: mmwave_sensor
- delay: 1s
- uart.write:
!lambda std::string mss = "setSensitivity " + to_string(id(mmwave_sensitivity).state) + " " + to_string(id(mmwave_trigger_sensitivity).state);
return std::vector<unsigned char>(mss.begin(), mss.end());
- delay: 1s
- uart.write: "saveConfig"
- delay: 1s
- switch.turn_on: mmwave_sensor
- platform: template
name: mmWave Trigger Sensitivity
icon: mdi:target-variant
id: mmwave_trigger_sensitivity
entity_category: config
min_value: 0
max_value: 9
initial_value: 5
optimistic: true
step: 1
restore_value: true
set_action:
- if:
condition:
lambda: 'return id(mmwave_mode).state == "Presence Detection";'
then:
- switch.turn_off: mmwave_sensor
- delay: 1s
- uart.write:
!lambda std::string mss = "setSensitivity " + to_string(id(mmwave_sensitivity).state) + " " + to_string(id(mmwave_trigger_sensitivity).state);
return std::vector<unsigned char>(mss.begin(), mss.end());
- delay: 1s
- uart.write: "saveConfig"
- delay: 1s
- switch.turn_on: mmwave_sensor
- platform: template
name: "mmWave Threshold Factor"
id: mmwave_threshold_factor
entity_category: config
icon: mdi:tune-variant
disabled_by_default: true
min_value: 1
max_value: 20
initial_value: 5
optimistic: true
step: 1
restore_value: true
set_action:
- if:
condition:
lambda: 'return id(mmwave_mode).state == "Distance and Speed";'
then:
- switch.turn_off: mmwave_sensor
- delay: 1s
- uart.write: !lambda |-
std::string mss = "setThrFactor " + 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: restart
name: Restart_internal
id: restart_internal
entity_category: config
internal: true
- platform: template
name: "Restart mmWave Sensor"
id: "restart_mmwave"
entity_category: config
internal: true
on_press:
- uart.write: "resetSystem"
- platform: template
name: Restart $name
entity_category: config
on_press:
- button.press: restart_mmwave
- button.press: restart_internal
- platform: safe_mode
internal: false
name: $name Safe Mode
entity_category: config
- platform: template
name: "Factory Reset mmWave"
id: "factory_reset_mmwave"
internal: ${factory_reset_disabled}
entity_category: config
on_press:
- switch.turn_off: mmwave_sensor
- delay: 2s
- uart.write: "resetCfg"
- delay: 3s
- uart.write: "setRunApp 0"
- delay: 2s
- uart.write: "saveConfig"
- delay: 3s
- switch.turn_on: mmwave_sensor
- delay: 3s
- uart.write: "getRange"
- delay: 3s
- uart.write: "getSensitivity"
- delay: 3s
- uart.write: "getLatency"
- delay: 3s
- uart.write: "getTrigRange"
- delay: 3s
- lambda: |-
id(mmwave_mode).publish_state("Presence Detection");
id(micro_motion_detection).publish_state(false);
id(mmwave_threshold_factor).publish_state(5.0);
id(uart_target_output).publish_state(false);
id(mmwave_led).publish_state(true);