This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjiecang_desk_controller_full.yaml
253 lines (237 loc) · 6.66 KB
/
jiecang_desk_controller_full.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
esphome:
name: jiecang-desk-controller
friendly_name: Jiecang Desk Controller
includes:
- jiecang_desk_sensor.h
on_boot:
priority: 0 # when mostly everything else is done
then:
- uart.write: [0xF1, 0xF1, 0x0C, 0x00, 0x0C, 0x7e] # request physical limits
- delay: 0.1s
- uart.write: [0xF1, 0xF1, 0x20, 0x00, 0x20, 0x7e] # request limits
- delay: 0.1s
- uart.write: [0xF1, 0xF1, 0x07, 0x00, 0x07, 0x7e] # request settings
esp8266:
board: esp01_1m
# Enable logging
logger:
level: VERBOSE #makes uart stream available in esphome logstream
baud_rate: 0 #disable logging over uart
# Enable Home Assistant API
api:
encryption:
key: !secret encryption_key
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "esphome-desk"
password: "9ebc6eac0b4e0e26b8d3b955ec660557"
captive_portal:
uart:
id: uart_bus
tx_pin: TX
rx_pin: RX
baud_rate: 9600
sensor:
- platform: custom
lambda: |-
auto desk = new JiecangDeskSensor(id(uart_bus));
App.register_component(desk);
return {desk->height,desk->height_pct,desk->unit,desk->height_min,desk->height_max,desk->position1,desk->position2,desk->position3,desk->position4};
sensors:
- id: "desk_height"
name: "Height"
unit_of_measurement: cm
accuracy_decimals: 1
- id: "desk_height_pct"
name: "Height Percent"
unit_of_measurement: "%"
- id: "desk_height_unit"
on_value:
then:
- select.set_index:
id: unit
index: !lambda return id(desk_height_unit).state;
- id: "desk_height_min"
name: "Height Min"
unit_of_measurement: cm # !lambda return id(unit).state
accuracy_decimals: 1
- id: "desk_height_max"
name: "Height Max"
unit_of_measurement: cm
accuracy_decimals: 1
- id: "desk_position1"
name: "Position 1"
unit_of_measurement: cm
accuracy_decimals: 1
- id: "desk_position2"
name: "Position 2"
unit_of_measurement: cm
accuracy_decimals: 1
- id: "desk_position3"
name: "Position 3"
unit_of_measurement: cm
accuracy_decimals: 1
- id: "desk_position4"
name: "Position 4"
unit_of_measurement: cm
accuracy_decimals: 1
select:
- platform: template
name: Unit
id: unit
options:
- "cm"
- "inch"
initial_option: "cm"
optimistic: true
set_action:
then:
- if:
condition:
- lambda: return id(unit).state == "cm";
then:
- uart.write: [0xF1, 0xF1, 0x0E, 0x01, 0x00, 0x0F, 0x7e]
else:
- uart.write: [0xF1, 0xF1, 0x0E, 0x01, 0x01, 0x10, 0x7e]
# - platform: template
# name: "Anti collision sensitivity"
# id: anti_collision
# options:
# - "High"
# - "Medium"
# - "Low"
# initial_option: "High"
# optimistic: true
# set_action:
# then:
# - if:
# condition:
# - lambda: |-
# return id(unit).state == "High" ;
# then:
# - uart.write: [0xF1, 0xF1, 0x1D, 0x01, 0x01, 0x1F, 0x7e]
# else:
# - if:
# condition:
# - lambda: |-
# return id(unit).state == "Medium" ;
# then:
# - uart.write: [0xF1, 0xF1, 0x1D, 0x01, 0x02, 0x20, 0x7e]
# else:
# - uart.write: [0xF1, 0xF1, 0x1D, 0x01, 0x03, 0x21, 0x7e]
button:
- platform: template
name: "Move up"
on_press:
- lambda: |-
if (id(moving) != 0) {
id(moving) = 0;
} else {
id(moving) = 1;
id(move_up).execute();
}
- platform: template
name: "Move down"
on_press:
- lambda: |-
if (id(moving) != 0) {
id(moving) = 0;
} else {
id(moving) = 2;
id(move_down).execute();
}
- platform: template
name: "Move stop"
on_press:
- lambda: 'id(moving) = 0;'
- platform: template
name: "Step up"
on_press:
- uart.write: [0xF1, 0xF1, 0x01, 0x00, 0x01, 0x7e]
- lambda: 'id(moving) = 0;'
- platform: template
name: "Step down"
on_press:
- uart.write: [0xF1, 0xF1, 0x02, 0x00, 0x02, 0x7e]
- lambda: 'id(moving) = 0;'
- platform: template
name: "Position 1"
on_press:
- uart.write: [0xF1, 0xF1, 0x05, 0x00, 0x05, 0x7e]
- lambda: 'id(moving) = 0;'
- platform: template
name: "Position 2"
on_press:
- uart.write: [0xF1, 0xF1, 0x06, 0x00, 0x06, 0x7e]
- lambda: 'id(moving) = 0;'
- platform: template
name: "Position 3"
on_press:
- uart.write: [0xF1, 0xF1, 0x27, 0x00, 0x27, 0x7e]
- lambda: 'id(moving) = 0;'
- platform: template
name: "Position 4"
on_press:
- uart.write: [0xF1, 0xF1, 0x28, 0x00, 0x28, 0x7e]
- lambda: 'id(moving) = 0;'
- platform: uart
name: "Request Settings"
data: [0xF1, 0xF1, 0x07, 0x00, 0x07, 0x7e]
- platform: uart
name: "Request Limits"
data: [0xF1, 0xF1, 0x20, 0x00, 0x20, 0x7e]
# - platform: uart
# name: "Wake"
# data: [0xF1, 0xF1, 0x29, 0x00, 0x29, 0x7e]
# - platform: uart
# name: "Set Limit Max"
# data: [0xF1, 0xF1, 0x21, 0x00, 0x21, 0x7e]
# - platform: uart
# name: "Set Limit Min"
# data: [0xF1, 0xF1, 0x22, 0x00, 0x22, 0x7e]
# - platform: uart
# name: "Clear Limit Max"
# data: [0xF1, 0xF1, 0x23, 0x01, 0x01, 0x25, 0x7e]
# - platform: uart
# name: "Clear Limit Min"
# data: [0xF1, 0xF1, 0x23, 0x01, 0x02, 0x26, 0x7e]
# - platform: uart
# name: "Set Position 1"
# data: [0xF1, 0xF1, 0x03, 0x00, 0x03, 0x7e]
# - platform: uart
# name: "Set Position 2"
# data: [0xF1, 0xF1, 0x04, 0x00, 0x04, 0x7e]
# - platform: uart
# name: "Set Position 3"
# data: [0xF1, 0xF1, 0x25, 0x00, 0x25, 0x7e]
# - platform: uart
# name: "Set Position 4"
# data: [0xF1, 0xF1, 0x26, 0x00, 0x26, 0x7e]
globals:
- id: moving
type: int
restore_value: no
initial_value: "0"
script:
- id: move_up
mode: single
then:
- while:
condition:
lambda: 'return id(moving) == 1 && id(desk_height).state < id(desk_height_max).state - 0.1;'
then:
- uart.write: [0xF1, 0xF1, 0x01, 0x00, 0x01, 0x7e]
- delay: 0.5s
- id: move_down
mode: single
then:
- while:
condition:
lambda: 'return id(moving) == 2 && id(desk_height).state > id(desk_height_min).state + 0.1;'
then:
- uart.write: [0xF1, 0xF1, 0x02, 0x00, 0x02, 0x7e]
- delay: 0.5s