-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathexample.yaml
220 lines (190 loc) · 5.26 KB
/
example.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
esphome:
name: esphome-eqiva-lock
friendly_name: ESPHome Eqiva Lock
esp32:
board: esp32dev
framework:
type: esp-idf
# Uncomment below for ESP32-C3 if you have unexpected reboots when encrypting data
# sdkconfig_options:
# CONFIG_BOOTLOADER_WDT_TIME_MS: "60000"
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "yourkey"
ota:
web_server:
include_internal: true
local: false
port: 80
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esphome-Web-Eqiva-Lock"
password: "12345678"
# Activate scan only after wifi connect, see https://github.com/esphome/issues/issues/2941#issuecomment-1842369092
on_connect:
- esp32_ble_tracker.start_scan:
continuous: true
- eqiva_key_ble.connect:
mac_address: !lambda 'return id(mac_address).state;'
user_id: !lambda 'return id(user_id).state;'
user_key: !lambda 'return id(user_key).state;'
on_disconnect:
- esp32_ble_tracker.stop_scan:
#button, number and text input for pairing and setting mac/user_id/user-key via UI
button:
- platform: template
id: ble_settings
name: BLE Settings _Save_
icon: "mdi:content-save"
on_press:
- eqiva_key_ble.connect:
mac_address: !lambda 'return id(mac_address).state;'
user_id: !lambda 'return id(user_id).state;'
user_key: !lambda 'return id(user_key).state;'
- platform: template
id: ble_disconnect
name: BLE Settings _Disconnect_
icon: "mdi:clear"
on_press:
- eqiva_key_ble.disconnect:
- platform: template
id: ble_pair
name: BLE Pair _Start_
icon: "mdi:check-underline"
on_press:
- eqiva_key_ble.pair:
card_key: !lambda 'return id(card_key).state;'
- platform: template
id: lock_settings
name: Lock Settings _Apply_
icon: "mdi:check-underline"
on_press:
- eqiva_key_ble.settings:
turn_left: !lambda 'return id(direction).state == "Left";'
key_horizontal: !lambda 'return id(position).state == "Horizontal";'
lock_turns: !lambda 'return atoi(id(turns).state.c_str());'
number:
- platform: template
mode: box
name: BLE Settings User ID
id: user_id
max_value: 7
min_value: 0
step: 1
optimistic: true
restore_value: true
text:
- platform: template
mode: text
name: BLE Settings Mac Address
id: mac_address
optimistic: true
restore_value: true
- platform: template
mode: text
name: BLE Settings User Key
id: user_key
optimistic: true
restore_value: true
- platform: template
mode: text
name: BLE Pair Card Key
id: card_key
optimistic: true
select:
- platform: template
name: Lock Settings Close Direction
id: direction
options:
- "Left"
- "Right"
optimistic: true
- platform: template
name: Lock Settings Key Position
id: position
options:
- "Vertical"
- "Horizontal"
optimistic: true
- platform: template
name: Lock Settings Turns
id: turns
options:
- "1"
- "2"
- "3"
- "4"
optimistic: true
captive_portal:
external_components:
source: github://digaus/esphome-components-eqiva
# use refresh when you do not get latest version
# refresh: 0s
esp32_ble_tracker:
scan_parameters:
window: 300ms
# Activate scan only after wifi connect, see https://github.com/esphome/issues/issues/2941#issuecomment-1842369092
continuous: false
eqiva_ble:
eqiva_key_ble:
id: key_ble
# Below can left empty because we connect in wifi on_connect
# mac_address: 00:12:34:56:42:88
# user_id: 0
# user_key: 12345678636F6763386A726E33746F35
text_sensor:
- platform: eqiva_key_ble
mac_address:
name: "Mac Address"
lock_status:
name: "Lock Status"
id: lock_status
low_battery:
name: "Low Battery"
lock_ble_state:
name: "Lock BLE State"
user_id:
name: "User ID"
user_key:
name: "User Key"
# on_raw_value:
# then: Do stuff on state change (!lambda "return x")
# Call status every 4 minutes because lock seems to disconnect after 5 minutes of inactivity
# need to watch battery consumption, could also do some other time or present based approaches
time:
- platform: sntp
# ...
on_time:
# Every 4 minutes
- seconds: 0
minutes: /4
then:
- eqiva_key_ble.status:
# Lock component for HA, can also create two locks and use connect service to connect/control two different locks
# One ESP per lock is still recommended
lock:
- platform: template
name: "Lock 1"
lambda: |-
if (id(lock_status).state == "LOCKED") {
return LOCK_STATE_LOCKED;
} else if (id(lock_status).state == "UNLOCKED" || id(lock_status).state == "OPENED") {
return LOCK_STATE_UNLOCKED;
} else if(id(lock_status).state == "MOVING") {
return {};
} else if (id(lock_status).state == "UNKNOWN") {
return LOCK_STATE_JAMMED;
}
return LOCK_STATE_LOCKED;
lock_action:
- eqiva_key_ble.lock:
unlock_action:
- eqiva_key_ble.unlock:
open_action:
- eqiva_key_ble.open: