-
Notifications
You must be signed in to change notification settings - Fork 20
/
esphome-ld2450.yaml
433 lines (418 loc) · 12.2 KB
/
esphome-ld2450.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
substitutions:
devicename: ld2450
upper_devicename: "Hi-Link LD2450"
esphome:
name: ${devicename}
comment: ${upper_devicename}
includes:
- components/ld2450_uart.h
on_boot:
priority: -100
# ...
then:
- lambda: 'static_cast<LD2450 *>(ld2450)->getInfo();'
- lambda: id(tracking_mode).publish_state("Multiple");
esp8266:
board: esp01_1m
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# reboot_timeout: 0s
ap:
password: "admin1234"
ap_timeout: 30s
# Enable logging
logger:
baud_rate: 0
# Enable Home Assistant API
api:
ota:
uart:
id: uart_ld2450
tx_pin: TX
rx_pin: RX
baud_rate: 256000
parity: NONE
stop_bits: 1
# debug:
# direction: BOTH
# dummy_receiver: false
custom_component:
- lambda: |-
return {new LD2450(id(uart_ld2450))};
components:
- id: ld2450
binary_sensor:
- platform: custom
lambda: |-
auto uart_component = static_cast<LD2450 *>(ld2450);
return {uart_component->lastCommandSuccess, uart_component->configMode, uart_component->bluetoothState};
binary_sensors:
- name: "Last Command Success"
id: binary_sensor_command_state
internal: true
- name: "Config Mode"
icon: mdi:cog
id: binary_sensor_config_mode
- name: "Bluetooth State"
icon: mdi:bluetooth
id: binary_sensor_bluetooth_state
internal: true
button:
- platform: template
name: "Reboot LD2450"
on_press:
- lambda: 'static_cast<LD2450 *>(ld2450)->reboot();'
- platform: template
name: "Factory Reset LD2450"
on_press:
- lambda: 'static_cast<LD2450 *>(ld2450)->factoryReset();'
- platform: template
name: "Single Target Tracking"
on_press:
- lambda: 'static_cast<LD2450 *>(ld2450)->setSingle();'
- platform: template
name: "Multiple Targets Tracking"
on_press:
- lambda: 'static_cast<LD2450 *>(ld2450)->setMultiple();'
- platform: template
name: "Get Zones Information"
on_press:
- lambda: 'static_cast<LD2450 *>(ld2450)->getZone();'
- platform: template
name: "Set Zones Information"
on_press:
lambda: |-
int type = 0;
if (id(zone_type).state == "Disable Zone Filter") {
type = 0;
} else if (id(zone_type).state == "Only Detect Configured Zone") {
type = 1;
} else if (id(zone_type).state == "Not Detect Configured Zone") {
type = 2;
}
static_cast<LD2450 *>(ld2450)->setZone(type, id(zone1_x1).state * 10, id(zone1_y1).state * 10, id(zone1_x2).state * 10, id(zone1_y2).state * 10, id(zone2_x1).state * 10, id(zone2_y1).state * 10, id(zone2_x2).state * 10, id(zone2_y2).state * 10, id(zone2_x1).state * 10, id(zone2_y1).state * 10, id(zone2_x2).state * 10, id(zone2_y2).state * 10);
number:
- platform: template
name: "Zone1 X1"
id: zone1_x1
icon: mdi:align-horizontal-left
min_value: -100
max_value: 100
step: 1
optimistic: true
- platform: template
name: "Zone1 Y1"
id: zone1_y1
icon: mdi:align-horizontal-distribute
min_value: -100
max_value: 100
step: 1
optimistic: true
- platform: template
name: "Zone1 X2"
id: zone1_x2
icon: mdi:align-horizontal-right
min_value: -100
max_value: 100
step: 1
optimistic: true
- platform: template
name: "Zone1 Y2"
id: zone1_y2
icon: mdi:align-horizontal-distribute
min_value: -100
max_value: 100
step: 1
optimistic: true
- platform: template
name: "Zone2 X1"
id: zone2_x1
icon: mdi:align-horizontal-left
min_value: -100
max_value: 100
step: 1
optimistic: true
- platform: template
name: "Zone2 Y1"
id: zone2_y1
icon: mdi:align-horizontal-distribute
min_value: -100
max_value: 100
step: 1
optimistic: true
- platform: template
name: "Zone2 X2"
id: zone2_x2
icon: mdi:align-horizontal-right
min_value: -100
max_value: 100
step: 1
optimistic: true
- platform: template
name: "Zone2 Y2"
id: zone2_y2
icon: mdi:align-horizontal-distribute
min_value: -100
max_value: 100
step: 1
optimistic: true
- platform: template
name: "Zone3 X1"
id: zone3_x1
icon: mdi:align-horizontal-left
min_value: -100
max_value: 100
step: 1
optimistic: true
- platform: template
name: "Zone3 Y1"
id: zone3_y1
icon: mdi:align-horizontal-distribute
min_value: -100
max_value: 100
step: 1
optimistic: true
- platform: template
name: "Zone3 X2"
id: zone3_x2
icon: mdi:align-horizontal-right
min_value: -100
max_value: 100
step: 1
optimistic: true
- platform: template
name: "Zone3 Y2"
id: zone3_y2
icon: mdi:align-horizontal-distribute
min_value: -100
max_value: 100
step: 1
optimistic: true
select:
- platform: template
name: "Template select"
id: zone_type
optimistic: true
options:
- Disable Zone Filter
- Only Detect Configured Zone
- Not Detect Configured Zone
sensor:
- platform: custom
lambda: |-
auto uart_component = static_cast<LD2450 *>(ld2450);
return {uart_component->target1Resolution, uart_component->target1Speed, uart_component->target1X, uart_component->target1Y, uart_component->target2Resolution, uart_component->target2Speed, uart_component->target2X, uart_component->target2Y, uart_component->target3Resolution, uart_component->target3Speed, uart_component->target3X, uart_component->target3Y, uart_component->targets, uart_component->zoneType, uart_component->zone1X1, uart_component->zone1Y1, uart_component->zone1X2, uart_component->zone1Y2, uart_component->zone2X1, uart_component->zone2Y1, uart_component->zone2X2, uart_component->zone2Y2, uart_component->zone3X1, uart_component->zone3Y1, uart_component->zone3X2, uart_component->zone3Y2
};
sensors:
- name: "Target1 Resolution"
unit_of_measurement: "nm"
accuracy_decimals: 0
icon: mdi:artboard
- name: "Target1 Speed"
unit_of_measurement: "cm/s"
accuracy_decimals: 0
icon: mdi:speedometer
- name: "Target1 X"
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:map-marker-right
- name: "Target1 Y"
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:map-marker-down
- name: "Target2 Resolution"
unit_of_measurement: "nm"
accuracy_decimals: 0
icon: mdi:artboard
- name: "Target2 Speed"
unit_of_measurement: "cm/s"
accuracy_decimals: 0
icon: mdi:speedometer
- name: "Target2 X"
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:map-marker-right
- name: "Target2 Y"
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:map-marker-down
- name: "Target3 Resolution"
unit_of_measurement: "nm"
accuracy_decimals: 0
icon: mdi:artboard
- name: "Target3 Speed"
unit_of_measurement: "cm/s"
accuracy_decimals: 0
icon: mdi:speedometer
- name: "Target3 X"
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:map-marker-right
- name: "Target3 Y"
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:map-marker-down
- name: "Targets"
- name: "Zone Type"
id: zonetype
icon: mdi:tangram
internal: true
on_value:
then:
lambda: |-
if (id(zonetype).state == 0) {
id(zone_type).publish_state("Disable Zone Filter");
} else if (id(zonetype).state == 1) {
id(zone_type).publish_state("Only Detect Configured Zone");
} else if (id(zonetype).state == 2) {
id(zone_type).publish_state("Not Detect Configured Zone");
}
- name: "Zone1 X1"
id: zone1x1
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:align-horizontal-left
internal: true
on_value:
then:
- lambda: id(zone1_x1).publish_state(id(zone1x1).state);
- name: "Zone1 Y1"
id: zone1y1
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:align-horizontal-distribute
internal: true
on_value:
then:
- lambda: id(zone1_y1).publish_state(id(zone1y1).state);
- name: "Zone1 X2"
id: zone1x2
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:align-horizontal-right
internal: true
on_value:
then:
- lambda: id(zone1_x2).publish_state(id(zone1x2).state);
- name: "Zone1 Y2"
id: zone1y2
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:align-horizontal-distribute
internal: true
on_value:
then:
- lambda: id(zone1_y2).publish_state(id(zone1y2).state);
- name: "Zone2 X1"
id: zone2x1
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:align-horizontal-left
internal: true
on_value:
then:
- lambda: id(zone2_x1).publish_state(id(zone2x1).state);
- name: "Zone2 Y1"
id: zone2y1
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:align-horizontal-distribute
internal: true
on_value:
then:
- lambda: id(zone2_y1).publish_state(id(zone2y1).state);
- name: "Zone2 X2"
id: zone2x2
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:align-horizontal-right
internal: true
on_value:
then:
- lambda: id(zone2_x2).publish_state(id(zone2x2).state);
- name: "Zone2 Y2"
id: zone2y2
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:align-horizontal-distribute
internal: true
on_value:
then:
- lambda: id(zone2_y2).publish_state(id(zone2y2).state);
- name: "Zone3 X1"
id: zone3x1
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:align-horizontal-left
internal: true
on_value:
then:
- lambda: id(zone3_x1).publish_state(id(zone3x1).state);
- name: "Zone3 Y1"
id: zone3y1
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:align-horizontal-distribute
internal: true
on_value:
then:
- lambda: id(zone3_y1).publish_state(id(zone3y1).state);
- name: "Zone3 X2"
id: zone3x2
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:align-horizontal-right
internal: true
on_value:
then:
- lambda: id(zone3_x2).publish_state(id(zone3x2).state);
- name: "Zone3 Y2"
id: zone3y2
unit_of_measurement: "cm"
accuracy_decimals: 0
icon: mdi:align-horizontal-distribute
internal: true
on_value:
then:
- lambda: id(zone3_y2).publish_state(id(zone3y2).state);
switch:
- platform: template
name: "Config Mode"
lambda: |-
if (id(binary_sensor_config_mode).state) {
return true;
} else {
return false;
}
turn_on_action:
- lambda: 'static_cast<LD2450 *>(ld2450)->setConfigMode(true);'
turn_off_action:
- lambda: 'static_cast<LD2450 *>(ld2450)->setConfigMode(false);'
- platform: template
name: "Bluetooth Function"
lambda: |-
if (id(binary_sensor_bluetooth_state).state) {
return true;
} else {
return false;
}
icon: mdi:bluetooth
turn_on_action:
- lambda: 'static_cast<LD2450 *>(ld2450)->setBluetooth(true);'
turn_off_action:
- lambda: 'static_cast<LD2450 *>(ld2450)->setBluetooth(false);'
text_sensor:
- platform: custom
lambda: |-
auto uart_component = static_cast<LD2450 *>(ld2450);
return { uart_component->macAddress, uart_component->fwVersion, uart_component->trackingMode
};
text_sensors:
- name: "Mac Address"
icon: mdi:puzzle
- name: "Firmware Versoin"
icon: mdi:new-box
- name: "Tracking Mode"
icon: mdi:radar
id: tracking_mode