-
Notifications
You must be signed in to change notification settings - Fork 56
/
flexispot_e5b_esp32.yaml
315 lines (283 loc) · 7.93 KB
/
flexispot_e5b_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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
substitutions:
device_name: Flexispot E5B
name: flexispot_e5b
min_height: "71.0" # Min height + 0.1
#min_height: "62.1" # Min height + 0.1 (original one)
max_height: "125.1" # Max height - 0.1
esphome:
name: ${name}
comment: ${device_name}
platform: esp32 # TODO Change to your platform
board: esp32dev # TODO Change to your board
includes:
- desk_height_sensor.h
- desk_keypad.h
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${device_name} Fallback Hotspot"
password: !secret ap_fallback_password
captive_portal:
# Enable logging
logger:
level: DEBUG
baud_rate: 0
# Enable Home Assistant API
api:
password: !secret ha_api_password
ota:
password: !secret ha_api_password
script:
- id: screen_timer
mode: restart
then:
# on_start
- logger.log: "Executing screen timer command"
- switch.turn_on: virtual_screen
- delay: 12s # timer length (keypad screen timeout is 10s + 2s buffer)
- if:
condition:
binary_sensor.is_off : screen
then:
- switch.turn_off: virtual_screen
# on_end
- id: script_start_command
mode: restart
then:
- logger.log: "Executing Empty command"
- if:
condition:
switch.is_off : virtual_screen
then:
- script.execute: screen_timer
- delay: 480ms
else:
- script.execute: screen_timer
uart:
- id: desk_uart
baud_rate: 9600
tx_pin: GPIO17
rx_pin: GPIO16
- id: keypad_uart
baud_rate: 9600
tx_pin: GPIO1
rx_pin: GPIO3
sensor:
- platform: wifi_signal
name: "WiFi Signal"
update_interval: 60s
- platform: uptime
name: Uptime
- platform: custom
lambda: |-
auto desk_height_sensor = new DeskHeightSensor(id(desk_uart));
App.register_component(desk_height_sensor);
return {desk_height_sensor};
sensors:
id: "desk_height"
name: Desk Height
unit_of_measurement: cm
accuracy_decimals: 1
icon: "mdi:counter"
on_value:
then:
- script.execute: screen_timer
# - cover.template.publish:
# id: desk
# position: !lambda |-
# // The sensor outputs values from min_height (cm) to max_height (cm)
# // We need to translate this to 0 - 1 scale.
# float position = (float(x) - float(${min_height})) / (float(${max_height}) - float(${min_height}));
# return position;
- platform: custom
lambda: |-
auto desk_keypad_sensor = new DeskKeypad(id(keypad_uart));
App.register_component(desk_keypad_sensor);
return {desk_keypad_sensor};
sensors:
id: "desk_command"
name: Desk command
icon: "mdi:counter"
on_value:
then:
lambda: |-
if(!id(keypad_switch).state)
{
if(id(desk_command).state == 1)
{
id(desk).open();
} else if(id(desk_command).state == 2)
{
id(desk).close();
} else if(id(desk_command).state == 3)
{
id(switch_preset1).turn_on();
} else if(id(desk_command).state == 4)
{
id(switch_preset2).turn_on();
} else if(id(desk_command).state == 5)
{
id(switch_preset3).turn_on();
} else if(id(desk_command).state == 6)
{
id(switch_m).turn_on();
} else if(id(desk_command).state == 7)
{
id(switch_alarm).turn_on();
} else if(id(desk_command).state == 8)
{
id(desk).stop();
}
}
binary_sensor:
- platform: gpio
name: "Screen"
id: "screen"
pin: GPIO22
internal: false
on_press:
then:
- switch.turn_on: virtual_screen
on_release:
then:
- switch.turn_off: virtual_screen
switch:
- platform: template
name: "Keypad locked"
icon: mdi:key
id: "keypad_switch"
internal: false
restore_state: true
assumed_state: false
optimistic: true
- platform: template
name: "Preset 1"
id: switch_preset1
icon: mdi:numeric-1-box
turn_on_action:
- logger.log: "Executing Preset 1 command"
- script.execute: script_start_command
- script.wait: script_start_command
- uart.write:
id: desk_uart
data: [0x9b, 0x06, 0x02, 0x04, 0x00, 0xac, 0xa3, 0x9d]
internal: false
- platform: template
name: "Preset 2"
id: switch_preset2
icon: mdi:numeric-2-box
turn_on_action:
- logger.log: "Executing Preset 2 command"
- script.execute: script_start_command
- script.wait: script_start_command
- uart.write:
id: desk_uart
data: [0x9b, 0x06, 0x02, 0x08, 0x00, 0xac, 0xa6, 0x9d]
internal: false
- platform: template
name: "Preset 3"
id: switch_preset3
icon: mdi:numeric-3-box
turn_on_action:
- logger.log: "Executing Preset 3 command"
- script.execute: script_start_command
- script.wait: script_start_command
- uart.write:
id: desk_uart
data: [0x9b, 0x06, 0x02, 0x10, 0x00, 0xac, 0xac, 0x9d]
internal: false
- platform: template
name: "M"
id: switch_m
icon: mdi:alpha-m-circle
turn_on_action:
- logger.log: "Executing Preset 3 command"
- script.execute: script_start_command
- script.wait: script_start_command
- uart.write:
id: desk_uart
data: [0x9b, 0x06, 0x02, 0x20, 0x00, 0xac, 0xb8, 0x9d]
internal: false
- platform: template
name: "Alarm"
id: switch_alarm
icon: mdi:alpha-m-circle
turn_on_action:
- logger.log: "Executing Alarm command"
# - script.execute: script_start_command
# - script.wait: script_start_command
# - uart.write:
# id: desk_uart
# data: [0x9b, 0x06, 0x02, 0x40, 0x00, 0xac, 0x90, 0x9d]
internal: false
- platform: gpio
name: "Virtual Screen"
id: "virtual_screen"
pin:
number: GPIO23
mode: OUTPUT
restore_mode: ALWAYS_OFF
internal: false
- platform: uart
name: "Up"
id: switch_up
icon: mdi:arrow-up-bold
data: [0x9b, 0x06, 0x02, 0x01, 0x00, 0xfc, 0xa0, 0x9d]
uart_id: desk_uart
internal: false
- platform: uart
name: "Down"
id: switch_down
icon: mdi:arrow-down-bold
data: [0x9b, 0x06, 0x02, 0x02, 0x00, 0x0c, 0xa0, 0x9d]
uart_id: desk_uart
internal: false
- platform: uart
name: "Empty command"
id: switch_empty
data: [0x9b, 0x06, 0x02, 0x00, 0x00, 0x6c, 0xa1, 0x9d]
uart_id: desk_uart
internal: false
cover:
- platform: template
name: "Desk"
id: "desk"
assumed_state: true
# has_position: true
# position_action:
# - logger.log: "Requesting action change"
# Move desk up
open_action:
- script.execute: script_start_command
- script.wait: script_start_command
- while:
condition:
sensor.in_range:
id: desk_height
below: ${max_height}
then:
- logger.log: "Executing up command"
# - cover.template.publish:
# id: desk
# current_operation: OPENING
- switch.turn_on: switch_up
- delay: 108ms
# Move desk down
close_action:
- script.execute: script_start_command
- script.wait: script_start_command
- while:
condition:
sensor.in_range:
id: desk_height
above: ${min_height}
then:
- logger.log: "Executing down command"
# - cover.template.publish:
# id: desk
# current_operation: CLOSING
- switch.turn_on: switch_down
- delay: 108ms
optimistic: true