-
Notifications
You must be signed in to change notification settings - Fork 2
/
ESPresenceLD.yaml
398 lines (377 loc) · 9.62 KB
/
ESPresenceLD.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
substitutions:
name: "espresence-ld2410"
friendly_name: "LD2410 Presence Sensor"
disable_entities: "true" # Disabilitare in blocco entità superflue
wifi_ap_timeout: 2min # default to 2 minute timeout for yaml file as package.
esphome:
name: "$name"
build_path: ./build/${name}
project:
name: "espresence.ld2410"
version: "1.0.0"
on_boot: # Ai fini di debug, senza connessione ad HA è inutile far rilevare continuamente distanze, appesantiscono il log
- wait_until:
condition:
api.connected: #se si utilizza mqtt questo va sostituito con wifi connected
# timeout: 8s
esp32:
board: esp32dev
framework:
type: arduino
wifi:
ssid: dummy #!secret wifi_ssid #$ssid
password: dummydummy #!secret wifi_password #$password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ap_timeout: $wifi_ap_timeout
# ssid: # non occorre, di default prenderà il devicename
password: "dummydummy"
# Enable Home Assistant API
api:
services:
- service: set_ld2410_bluetooth_password
variables:
password: string
then:
- bluetooth_password.set:
id: ld2410_device
password: !lambda 'return password;'
ota:
platform: esphome
# on_error:
# then:
# - button.press: restart_button
captive_portal:
web_server:
port: 80
# Enable logging
logger:
hardware_uart: uart0
uart:
#id: uart1
tx_pin: GPIO33
rx_pin: GPIO18
baud_rate: 256000
parity: NONE
stop_bits: 1
ld2410:
#timeout: 10s
throttle: 1000ms
id: ld2410_device
sensor:
# LDR Analog input -------------------------------------
- platform: adc
pin: GPIO34
attenuation: auto
name: "Light Sensor"
unit_of_measurement: "%"
accuracy_decimals: 0
update_interval: 5s
filters:
- lambda: |-
auto r = map((x * 100), 19, id(ldr_sens).state, 0, 100);
if (r > 0) return r;
return 0;
# Retain last Detection Distance reported --------------
- platform: template
name: "Last Detection Distance"
id: last_detection_distance
unit_of_measurement: cm
accuracy_decimals: 0
update_interval: 1s
lambda: |-
if ((id(binary_has_target).state) && (id(presence_det_dist).state > 0)) {
return id(presence_det_dist).state;
} else {
return {};
}
# LD2410 Sensors ----------------------------------------
- platform: ld2410
light:
name: "Light"
moving_distance:
name: "Moving Distance"
still_distance:
name: "Still Distance"
moving_energy:
name: "Move Energy"
still_energy:
name: "Still Energy"
detection_distance:
name: "Detection Distance"
id: presence_det_dist
g0:
move_energy:
name: "G0 move energy"
still_energy:
name: "G0 still energy"
g1:
move_energy:
name: "G1 move energy"
still_energy:
name: "G1 still energy"
g2:
move_energy:
name: "G2 move energy"
still_energy:
name: "G2 still energy"
g3:
move_energy:
name: "G3 move energy"
still_energy:
name: "G3 still energy"
g4:
move_energy:
name: "G4 move energy"
still_energy:
name: "G4 still energy"
g5:
move_energy:
name: "G5 move energy"
still_energy:
name: "G5 still energy"
g6:
move_energy:
name: "G6 move energy"
still_energy:
name: "G6 still energy"
g7:
move_energy:
name: "G7 move energy"
still_energy:
name: "G7 still energy"
g8:
move_energy:
name: "G8 move energy"
still_energy:
name: "G8 still energy"
binary_sensor:
- platform: ld2410
has_target:
name: "Presence"
id: binary_has_target
has_moving_target:
name: "Moving presence"
has_still_target:
name: "Still presence"
out_pin_presence_status:
name: "Out pin presence status"
## Set Up Zones Based On Distance reported by the sensor
- platform: template
name: "Zone 1 Occupancy"
device_class: occupancy
icon: mdi:motion-sensor
lambda: |-
if ((id(binary_has_target).state) && ((id(last_detection_distance).state < id(presence_z1_end).state))) {
return true;
} else {
return false;
}
- platform: template
name: "Zone 2 Occupancy"
device_class: occupancy
icon: mdi:motion-sensor
lambda: |-
if ((id(binary_has_target).state) && ((id(presence_z1_end).state < id(last_detection_distance).state) && (id(last_detection_distance).state < id(presence_z2_end).state))) {
return true;
} else {
return false;
}
- platform: template
name: "Zone 3 Occupancy"
device_class: occupancy
icon: mdi:motion-sensor
lambda: |-
if ((id(binary_has_target).state) && ((id(presence_z2_end).state < id(last_detection_distance).state) && (id(last_detection_distance).state < id(presence_z3_end).state))) {
return true;
} else {
return false;
}
switch:
- platform: ld2410
engineering_mode:
name: "Engineering mode"
bluetooth:
name: "Control bluetooth"
- platform: gpio
pin: GPIO23
name: "Deactivate presence LED"
id: presence_led
entity_category: config
light:
- platform: status_led
name: "Status LED ESP32"
pin: GPIO13
button:
- platform: ld2410
factory_reset:
entity_category: diagnostic
name: "LD 2410 Factory reset"
restart:
entity_category: diagnostic
name: "LD 2410 Restart"
query_params:
entity_category: diagnostic
name: "Query params"
- platform: restart
entity_category: diagnostic
icon: mdi:power-cycle
name: "ESP reboot"
- platform: factory_reset
name: "Restart ESP with Factory Default Settings"
number:
- platform: ld2410
timeout:
name: "Timeout"
entity_category: config
light_threshold:
name: "Light threshold"
entity_category: config
max_move_distance_gate:
name: "Max move distance gate"
entity_category: config
max_still_distance_gate:
name: "Max still distance gate"
entity_category: config
g0:
move_threshold:
name: "G0 move threshold"
still_threshold:
name: "G0 still threshold"
g1:
move_threshold:
name: "G1 move threshold"
still_threshold:
name: "G1 still threshold"
g2:
move_threshold:
name: "G2 move threshold"
still_threshold:
name: "G2 still threshold"
g3:
move_threshold:
name: "G3 move threshold"
still_threshold:
name: "G3 still threshold"
g4:
move_threshold:
name: "G4 move threshold"
still_threshold:
name: "G4 still threshold"
g5:
move_threshold:
name: "G5 move threshold"
still_threshold:
name: "G5 still threshold"
g6:
move_threshold:
name: "G6 move threshold"
still_threshold:
name: "G6 still threshold"
g7:
move_threshold:
name: "G7 move threshold"
still_threshold:
name: "G7 still threshold"
g8:
move_threshold:
name: "G8 move threshold"
still_threshold:
name: "G8 still threshold"
# setup threshold for LDR reading
- platform: template
name: "LDR Threshold"
id: ldr_sens
min_value: 20
max_value: 600
step: 1
mode: box
update_interval: never
optimistic: true
restore_value: true
initial_value: 310
icon: "mdi:head-lightbulb"
entity_category: CONFIG
# setup for 3 zones --> occupancy ending values (distance)
- platform: template
name: "Zone 1 End Distance"
id: presence_z1_end
device_class: distance
min_value: 0
max_value: 600
step: 1
mode: box
update_interval: never
optimistic: true
restore_value: true
initial_value: 50
icon: "mdi:arrow-collapse-right"
entity_category: CONFIG
- platform: template
name: "Zone 2 End Distance"
id: presence_z2_end
device_class: distance
min_value: 0
max_value: 600
step: 1
mode: box
update_interval: never
optimistic: true
restore_value: true
initial_value: 100
icon: "mdi:arrow-collapse-right"
entity_category: CONFIG
- platform: template
name: "Zone 3 End Distance"
id: presence_z3_end
device_class: distance
min_value: 0
max_value: 600
step: 1
mode: box
update_interval: never
optimistic: true
restore_value: true
initial_value: 200
icon: "mdi:arrow-collapse-right"
entity_category: CONFIG
text_sensor:
- platform: ld2410
version:
name: "Firmware version"
entity_category: diagnostic
disabled_by_default: $disable_entities
mac_address:
name: "Mac address"
entity_category: diagnostic
disabled_by_default: $disable_entities
select:
- platform: ld2410
distance_resolution:
entity_category: config
name: "Distance resolution"
baud_rate:
entity_category: config
name: "Baud rate"
light_function:
entity_category: config
name: "Light function"
out_pin_level:
entity_category: config
name: "Out pin level"
# questo ce lo teniamo per le prove, poi possiamo cancellarlo se tutto va bene
#packages:
# remote_package:
# url: https://github.com/papperone/ESPresenceLD
# ref: main # optional
# file: ESPresenceLD.yaml
# refresh: 60s # optional
# Prova per un custom id necessario all'interfaccia di Maurizio
#text:
# - platform: template
# id: sensorname_id
# name: "Sensori-2410-cast"
# optimistic: true
# min_length: 0
# max_length: 20
# mode: text