-
Notifications
You must be signed in to change notification settings - Fork 0
/
hackem-doorlock.yaml
391 lines (361 loc) · 8.79 KB
/
hackem-doorlock.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
esphome:
name: hackem-doorlock
friendly_name: "Hackem Doorlock"
board: featheresp32
platform: esp32
# Enable logging
logger:
globals:
- id: wifi_connected
type: bool
restore_value: no
initial_value: "false"
- id: ota_progress
type: float
restore_value: no
- id: mqtt_connected
type: bool
restore_value: no
initial_value: "false"
interval:
- interval: 1h
then:
- component.update: my_display
- interval: 3000ms
then:
- if:
condition:
- wifi.connected:
then:
- if:
condition:
not:
mqtt.connected:
then:
- lambda: |-
id(wifi_connected) = true;
- script.execute: status_wifi_connected
else:
- lambda: |-
id(wifi_connected) = false;
- script.execute: status_no_connection
mqtt:
broker: 192.168.1.5
username: door
password: !secret mqtt_password
on_connect:
- lambda: |-
id(mqtt_connected) = true;
- script.execute: status_ready
on_disconnect:
- lambda: |-
id(mqtt_connected) = false;
- script.execute: status_wifi_connected
on_message:
topic: door
payload: "1"
then:
- mqtt.publish:
topic: door/response
payload: "unlocked"
- switch.turn_on: relay
- mqtt.publish:
topic: door
payload: "zhopa"
retain: true
api:
encryption:
key: !secret doorlock_apikey
ota:
password: !secret ota_pass
on_progress:
then:
- lambda: |-
id(ota_progress) = x;
# - component.update: my_display
on_begin:
then:
# - display.page.show: page_ota
# - component.update: my_display
on_end:
then:
# - display.page.show: page_reset
# - component.update: my_display
on_error:
then:
- script.execute: gui_reset
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
power_save_mode: none
ap:
ssid: "Hackem Fallback"
password: !secret wifi_fallback_password
sensor:
- platform: wifi_signal
name: "WiFi Signal"
update_interval: 60s
binary_sensor:
- platform: status
name: "Node Status"
id: system_status
# - platform: gpio
# pin:
# number: GPIO0
# inverted: true
# mode:
# input: true
# pullup: true
# name: "T-Display Button 0"
# id: tdisplay_button_input_0
# on_double_click:
# - button.press: restart_button
# - platform: gpio
# pin:
# number: GPIO35
# inverted: true
# name: "T-Display Button 1"
# id: tdisplay_button_input_1
# on_click:
# - switch.turn_on: relay
- platform: gpio
name: Doorbell Button
pin:
number: GPIO16
mode:
input: true
pulldown: true
filters:
- delayed_off: 10s
- platform: gpio
name: Unlock Button
pin:
number: GPIO17
mode:
input: true
pulldown: true
on_press:
- switch.turn_on: relay
script:
- id: status_no_connection
then:
- logger.log: "No Connection"
- light.turn_on:
id: status_light
effect: "Blink"
- display.page.show: page_not_ok
- component.update: my_display
- while:
condition:
not:
wifi.connected:
then:
- delay: 250ms
- component.update: my_display
- id: status_wifi_connected
then:
- logger.log: "Wi-Fi Connected"
- light.turn_on:
id: status_light
effect: "Fast Pulse"
- display.page.show: page_not_ok
- component.update: my_display
- while:
condition:
and:
- wifi.connected:
- not:
mqtt.connected:
then:
- delay: 100ms
- component.update: my_display
- delay: 500ms
- script.execute: status_ready
- id: status_ready
then:
- light.turn_on:
id: status_light
effect: "None"
- display.page.show: page_ok
- component.update: my_display
- id: gui_reset
then:
- logger.log: "GUI reset"
- if:
condition:
mqtt.connected:
then:
- light.turn_on:
id: status_light
effect: "None"
- display.page.show: page_ok
- component.update: my_display
- if:
condition:
- script.is_running: status_wifi_connected
then:
- script.stop: status_wifi_connected
- if:
condition:
- script.is_running: status_no_connection
then:
- script.stop: status_no_connection
- id: door_opened
then:
# - light.turn_off:
# id: status_light
# transition_length: 0s
# - light.turn_on:
# id: status_light
# transition_length: 2s
# brightness: 100%
# - display.page.show: page_door
# - component.update: my_display
# - light.turn_on:
# id: status_light
# effect: "Blink faster"
# - delay: 300ms
# - script.execute: gui_reset
switch:
- platform: gpio
name: "Door Relay"
restore_mode: ALWAYS_OFF
id: relay
pin:
number: GPIO5
inverted: false
mode:
open_drain: false
output: true
on_turn_on:
# - script.execute: door_opened
- delay: 200ms
- switch.turn_off: relay
button:
- platform: restart
id: restart_button
name: Restart
output:
- platform: ledc
id: output_status
pin: GPIO18
image:
# - file: "doorlock/flag.png"
# id: britishflag
# resize: 240x135
# type: RGB24
- file: "doorlock/bwflag.png"
id: britishflag
# resize: 240x135
type: BINARY
dither: FLOYDSTEINBERG
- file: "doorlock/error.png"
id: error_icon
resize: 100x100
type: TRANSPARENT_BINARY
dither: FLOYDSTEINBERG
spi:
clk_pin: 13
mosi_pin: 14
time:
- platform: sntp
timezone: "Asia/Yerevan"
id: sntp_time
servers:
- "minimi.lan"
# - "0.pool.ntp.org"
# - "1.pool.ntp.org"
display:
- platform: waveshare_epaper
cs_pin: 15
dc_pin: 27
reset_duration: 5ms
busy_pin: 25
reset_pin: 26
id: my_display
model: 2.13in-ttgo-dke
# model: 2.13inv2
full_update_every: 5
update_interval: never
rotation: 90°
pages:
- id: no_time
lambda: |-
it.printf(125, 65, id(clockfont), TextAlign::CENTER, "init");
- id: has_time
lambda: |-
it.strftime(125, 65, id(clockfont), TextAlign::CENTER, "%H:%M", id(sntp_time).now());
- id: page_ok
lambda: |-
it.image(0, 0, id(britishflag));
- id: page_not_ok
lambda: |-
it.rectangle(0, 0, it.get_width(), it.get_height());
it.rectangle(0, 20, it.get_width(), it.get_height()); // header bar
it.print(5, 5, id(roboto_12), TextAlign::TOP_LEFT, "Hacker Embassy");
if (id(mqtt_connected)) {
it.print(235, 5, id(roboto_12), TextAlign::TOP_RIGHT, "Online");
} else {
it.print(235, 5, id(roboto_12), TextAlign::TOP_RIGHT, "Offline");
it.image(75, 25, id(error_icon));
// it.printf(125, 65, id(clockfont), TextAlign::CENTER, "NOT OK");
}
if (id(wifi_connected)) {
it.print(120, 115, id(roboto_12), TextAlign::TOP_CENTER, "Wi-Fi connected");
} else {
it.print(120, 115, id(roboto_12), TextAlign::TOP_CENTER, "Wi-Fi disconnected");
}
light:
- platform: monochromatic
name: "Status Light"
id: status_light
output: output_status
effects:
- pulse:
- pulse:
name: "Very Fast Pulse"
transition_length: 0.2s
update_interval: 0.2s
- pulse:
name: "Fast Pulse"
transition_length: 0.3s
update_interval: 0.3s
- pulse:
name: "Slow Pulse"
transition_length: 0.6s
update_interval: 0.6s
- strobe:
name: Blink
colors:
- state: true
brightness: 100%
duration: 100ms
- state: false
duration: 100ms
- strobe:
name: Blink faster
colors:
- state: true
brightness: 100%
duration: 50ms
- state: false
duration: 50ms
font:
- file: "gfonts://Anton"
id: clockfont
size: 96
- file: "gfonts://Roboto"
id: roboto_12
size: 12
- file: "gfonts://Roboto"
id: roboto_36
size: 36
- file: "gfonts://Roboto"
id: roboto_48
size: 48
web_server:
port: 80
local: true
auth:
username: admin
password: !secret web_server_password