-
Notifications
You must be signed in to change notification settings - Fork 0
/
esp32.yaml
292 lines (263 loc) · 7.31 KB
/
esp32.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
esphome:
name: esp32
includes:
- uart_read_line_sensor_ld2410v3.h
friendly_name: ESP32
on_boot:
priority: -100
then:
- script.execute: get_config
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
baud_rate: 0
logs:
sensor: INFO # DEBUG level with uart_target_output = overload!
binary_sensor: INFO
text_sensor: INFO
# Enable Home Assistant API
api:
encryption:
key: "zxN5MRD9e97IkSP68YxS6gLeK/2/cnC1ZwFkpuYZn+w="
ota:
password: "4f8c6e8b562a527b6bb2d13b2e649446"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp32 Fallback Hotspot"
password: "rni4YaIKpkDY"
manual_ip:
static_ip: 192.168.1.162
gateway: 192.168.1.1
subnet: 255.255.255.0
web_server:
port: 80
version: 2
include_internal: true
ota: false
captive_portal:
i2c:
sda: GPIO21
scl: GPIO22
scan: True
uart:
id: uart_bus
tx_pin:
number: GPIO1
rx_pin:
number: GPIO3
baud_rate: 256000
parity: NONE
stop_bits: 1
switch:
- platform: safe_mode
name: use_safe_mode
- platform: template
name: configmode
id: configmode
optimistic: true
# assumed_state: false
turn_on_action:
# - switch.turn_off: engineering_mode
- lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(true);'
- delay: 100ms
- script.execute: clear_targets
turn_off_action:
- lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(false);'
- platform: template
name: show_target_stats
id: show_stats
optimistic: true
internal: true
turn_off_action:
- script.execute: clear_targets
text_sensor:
- platform: template
name: uptime_human_readable
id: uptime_human_readable
icon: mdi:clock-start
update_interval: 60s
sensor:
- platform: bh1750
name: "BH1750 Illuminance"
id: "bh_lux"
address: 0x23
update_interval: 15s
- platform: template
name: "bh10x"
lambda: |-
return 10*(id(bh_lux).state);
unit_of_measurement: lx
update_interval: 15s
- platform: uptime
name: uptime_sensor
id: uptime_sensor
update_interval: 60s
internal: true
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human_readable
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? to_string(days)+":" : "00:") +
(hours ? to_string(hours)+":" : "00:") +
(minutes ? to_string(minutes)+":" : "00:") +
(to_string(seconds))
).c_str();
- platform: custom # currently crashes ESP32
lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
//return {uart_component->movingTargetDistance,uart_component->movingTargetEnergy,uart_component->stillTargetDistance,uart_component->stillTargetEnergy,uart_component->detectDistance};
return {};
sensors:
- platform: template
name: movingTargetDistance
id: movingTargetDistance
unit_of_measurement: "cm"
accuracy_decimals: 0
internal: true
- platform: template
name: movingTargetEnergy
id: movingTargetEnergy
unit_of_measurement: "%"
accuracy_decimals: 0
internal: true
- platform: template
name: stillTargetDistance
id: stillTargetDistance
unit_of_measurement: "cm"
accuracy_decimals: 0
internal: true
- platform: template
name: stillTargetEnergy
id: stillTargetEnergy
unit_of_measurement: "%"
accuracy_decimals: 0
internal: true
- platform: template
name: detectDistance
id: detectDistance
unit_of_measurement: "cm"
accuracy_decimals: 0
internal: true
custom_component:
- lambda: |-
return {new LD2410(id(uart_bus))};
components:
- id: ld2410
binary_sensor:
- platform: gpio
name: occupancy
id: mmwave_presence_ld2410
pin: GPIO23
device_class: motion
on_state:
then:
- if:
condition:
- binary_sensor.is_off: mmwave_presence_ld2410
then:
- delay: 150ms
- script.execute: clear_targets
number:
- platform: template
name: configMaxDistance
id: maxconfigDistance
unit_of_measurement: "M"
min_value: 0.75
max_value: 6
step: 0.75
update_interval: never
optimistic: true
set_action:
- switch.turn_on: configmode
- delay: 50ms
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setMaxDistancesAndNoneDuration(x/0.75,x/0.75,id(noneDuration).state);
- delay: 50ms
- lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
- delay: 50ms
- switch.turn_off: configmode
- platform: template
name: "sensitivity_threshold_(%)"
id: allSensitivity
min_value: 10
max_value: 100
step: 5
mode: box
update_interval: never
optimistic: true
set_action:
- switch.turn_on: configmode
- delay: 50ms
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setAllSensitivity(x);
- delay: 50ms
- lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
- delay: 50ms
- switch.turn_off: configmode
- platform: template
name: "motion_hold_(sec)"
id: noneDuration
min_value: 0
# max_value: 32767
max_value: 900
step: 1
mode: box
update_interval: never
optimistic: true
set_action:
- switch.turn_on: configmode
- delay: 50ms
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setMaxDistancesAndNoneDuration(id(maxconfigDistance).state, id(maxconfigDistance).state, x);
- delay: 50ms
- lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
- delay: 50ms
- switch.turn_off: configmode
button:
- platform: restart
name: "reset/restart_ESP/MCU"
entity_category: diagnostic
on_press:
- switch.turn_on: configmode
- delay: 50ms
- lambda: 'static_cast<LD2410 *>(ld2410)->factoryReset();'
- delay: 150ms
- lambda: 'static_cast<LD2410 *>(ld2410)->reboot();'
- delay: 150ms
script:
- id: get_config
then:
- switch.turn_on: configmode
- delay: 500ms
- lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
- delay: 500ms
- switch.turn_off: configmode
- id: clear_targets
then:
- lambda: |-
//id(hasTarget).publish_state(0);
//id(hasMovingTarget).publish_state(0);
//id(hasStillTarget).publish_state(0);
id(movingTargetDistance).publish_state(0);
id(movingTargetEnergy).publish_state(0);
id(stillTargetDistance).publish_state(0);
id(stillTargetEnergy).publish_state(0);
id(detectDistance).publish_state(0);