-
Notifications
You must be signed in to change notification settings - Fork 2
/
M5Stack-Dial-Test
470 lines (421 loc) · 12.3 KB
/
M5Stack-Dial-Test
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
esphome:
name: workshop-rotary-test
friendly_name: workshop-rotary-test
on_boot:
priority: 100
then:
- logger.log: "Startup - Backlight on"
- lambda: |-
id(oledbacklight).set_level(0.7);
# Enable Home Assistant API
api:
encryption:
key: ENCYPTION_KEY
ota:
password: OTA_PASSWORD
globals:
- id: screenwidth
type: int
restore_value: no
- id: max_rotary_value
type: int
restore_value: no
initial_value: '1'
- id: min_rotary_value
type: int
restore_value: no
initial_value: '100'
external_components:
- source: github://dgaust/esphome@gc9a01
components: [ gc9a01, ft3267 ]
refresh: 0s
i2c:
- id: bus_internal
sda: GPIO11
scl: GPIO12
# - id: bus_porta
# sda: GPIO13
# scl: GPIO15
# interrupt: 14
esp32:
board: esp32-s3-devkitc-1
framework:
type: arduino
# Enable logging
logger:
level: DEBUG
color:
- id: my_red
red: 100%
green: 3%
blue: 5%
- id: my_green
hex: 4CBB17
- id: my_blue
red: 3%
green: 5%
blue: 100%
- id: my_yellow
hex: FFFF00
- id: my_light_blue
hex: 145DA0
- id: my_light_red
hex: fc6d6d
- id: my_light_orange
hex: FD7F20
- id: my_light_yellow
hex: B58B00
image:
- file: mdi:volume-variant-off
id: volume_mute
resize: 40x40
- file: mdi:volume-low
id: volume_notmute
resize: 40x40
- file: mdi:fan
id: fan_40
resize: 40x40
- file: mdi:weather-tornado
id: cyclone_icon_40
resize: 40x40
- file: mdi:weather-tornado
id: cyclone_icon_80
resize: 80x80
- file: mdi:fan
id: fan_80
resize: 80x80
- file: mdi:knob
id: volumeknob
resize: 80x80
- file: mdi:volume-low
id: volume_notmute_80
resize: 80x80
- file: mdi:volume-variant-off
id: volume_mute_80
resize: 80x80
font:
- file: "fonts/arial.ttf"
id: my_font
size: 40
- file: "gfonts://Roboto"
id: roboto16
size: 16
- file: "gfonts://Roboto"
id: roboto20
size: 20
- file: "gfonts://Roboto"
id: roboto24
size: 24
- file: "gfonts://Roboto"
id: roboto40
size: 40
wifi:
ssid: WIFI_SSID
password: WIFI_PASSWORD
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: FALLBACK_HS
password: FALLBACK_HS_PASSWORD
captive_portal:
rc522_i2c:
i2c_id: bus_internal
address: 0x28
on_tag:
then:
- rtttl.play: "success:d=24,o=5,b=100:c,g,b"
- homeassistant.tag_scanned: !lambda 'return x;'
touchscreen:
platform: ft3267
spi:
mosi_pin: GPIO5
clk_pin: GPIO6
display:
- platform: gc9a01
reset_pin: GPIO8
id: my_lcd
cs_pin: GPIO7
dc_pin: GPIO4
rotation: 90
pages:
- id: page1
lambda: |-
float screenheight = it.get_height();
float screenwidth = it.get_width();
float halfscreenheight = screenheight / 2;
float halfscreenwidth = screenwidth /2;
it.filled_rectangle(0, 0, halfscreenwidth, halfscreenheight, my_light_orange);
it.filled_rectangle(halfscreenwidth, halfscreenheight, 155, 155, my_blue);
it.filled_rectangle(0, halfscreenheight, halfscreenwidth, 155, my_green);
it.filled_rectangle(halfscreenwidth, 0, 155, halfscreenheight, my_red);
it.filled_rectangle(halfscreenwidth, halfscreenheight, - 155, - 155, my_green);
it.line(0, halfscreenheight, screenwidth, halfscreenheight);
it.line(halfscreenwidth, 0, halfscreenwidth, screenheight);
it.image(halfscreenwidth - 50, halfscreenheight - 90, fan_80, ImageAlign::TOP_CENTER);
it.image(halfscreenwidth + 50, halfscreenheight + 10, cyclone_icon_80, ImageAlign::TOP_CENTER);
it.image(halfscreenwidth + 50, halfscreenheight - 90, volume_notmute_80, ImageAlign::TOP_CENTER);
it.image(halfscreenwidth - 50, halfscreenheight + 10, volumeknob, ImageAlign::TOP_CENTER);
- id: page2
lambda: |-
float screenheight = it.get_height();
float screenwidth = it.get_width();
float halfscreenheight = screenheight / 2;
float halfscreenwidth = screenwidth /2;
it.image(halfscreenwidth, halfscreenheight - 55, fan_80, ImageAlign::TOP_CENTER);
it.start_clipping(0, (id(vent_fan_speed).state * -1) + 155, 250, 250);
it.filled_circle(halfscreenwidth, screenheight, 255, my_blue);
it.end_clipping();
it.printf(halfscreenwidth, halfscreenheight + 35, id(roboto40), TextAlign::TOP_CENTER, "%.0f%%", id(vent_fan_speed).state);
it.circle(halfscreenwidth -12, 225, 3);
it.filled_circle(halfscreenwidth, 225, 3);
it.circle(halfscreenwidth +12, 225, 3);
- id: page3
lambda: |-
float screenheight = it.get_height();
float screenwidth = it.get_width();
float halfscreenheight = screenheight / 2;
float halfscreenwidth = screenwidth /2;
it.image(halfscreenwidth, halfscreenheight - 55, cyclone_icon_80, ImageAlign::TOP_CENTER);
it.printf(halfscreenwidth, halfscreenheight + 35, id(roboto24), TextAlign::TOP_CENTER, "%.0f%%", id(vent_fan_speed).state);
it.circle(halfscreenwidth -12, 225, 3);
it.circle(halfscreenwidth, 225, 3);
it.filled_circle(halfscreenwidth +12, 225, 3);
on_page_change:
- to: page1
then:
- sensor.rotary_encoder.set_value:
id: rotaryencoder
value: !lambda 'return id(beam_volume).state * 100;'
- component.update: my_lcd
- to: page2
then:
- sensor.rotary_encoder.set_value:
id: rotaryencoder
value: !lambda 'return id(vent_fan_speed).state;'
- component.update: my_lcd
binary_sensor:
- platform: gpio
pin: GPIO42
name: "BacklightButton"
on_press:
- if:
condition:
- display.is_displaying_page: page1
then:
if:
condition:
lambda: return id(mediaplayermute).state == "off";
then:
- logger.log:
format: "The mediaplayer sensor reports value %s"
args: [ 'id(mediaplayermute).state' ]
- homeassistant.service:
service: media_player.volume_mute
data:
entity_id: media_player.workshop
is_volume_muted: 'true'
else:
- logger.log:
format: "The mediaplayer sensor reports value %s"
args: [ 'id(mediaplayermute).state' ]
- homeassistant.service:
service: media_player.volume_mute
data:
entity_id: media_player.workshop
is_volume_muted: 'false'
- platform: touchscreen
name: Top Left Touch Quadrant
x_min: 0
x_max: 119
y_min: 0
y_max: 119
on_state:
then:
- if:
condition:
- display.is_displaying_page: page1
then:
- display.page.show: page2
- if:
condition:
or:
- display.is_displaying_page: page2
- display.is_displaying_page: page3
then:
- display.page.show: page1
- component.update: my_lcd
- platform: touchscreen
name: Top Right Touch Quadrant
x_min: 120
x_max: 240
y_min: 0
y_max: 119
on_state:
then:
- if:
condition:
- display.is_displaying_page: page1
then:
- display.page.show: page3
- if:
condition:
or:
- display.is_displaying_page: page2
- display.is_displaying_page: page3
then:
- display.page.show: page2
- component.update: my_lcd
- platform: touchscreen
name: Bottom Left Touch Quadrant
x_min: 0
x_max: 119
y_min: 120
y_max: 240
on_state:
then:
- display.page.show_next: my_lcd
- component.update: my_lcd
- platform: touchscreen
name: Bottom Right Touch Quadrant
x_min: 120
x_max: 240
y_min: 120
y_max: 240
on_state:
then:
- display.page.show_previous: my_lcd
- component.update: my_lcd
- platform: homeassistant
name: "keypad6"
id: "fan_button"
entity_id: binary_sensor.keypadkey_6
on_state:
then:
- display.page.show: page2
- component.update: my_lcd
- platform: homeassistant
name: "keypad9"
id: "dusty_button"
entity_id: binary_sensor.keypadkey_9
on_state:
then:
- display.page.show: page3
- component.update: my_lcd
sensor:
- platform: rotary_encoder
name: "Rotary Encoder"
id: rotaryencoder
pin_a:
number: GPIO40
mode:
input: true
pullup: true
pin_b:
number: GPIO41
mode:
input: true
pullup: true
accuracy_decimals: 1
on_clockwise:
- rtttl.play: quick_e:d=4,o=5,b=100:16e6
- if:
condition:
- display.is_displaying_page: page1
then:
- homeassistant.service:
service: media_player.volume_up
data:
entity_id: media_player.workshop
- component.update: my_lcd
- if:
condition:
- display.is_displaying_page: page2
then:
- homeassistant.service:
service: input_number.increment
data:
entity_id: input_number.vent_fan_speed
- component.update: my_lcd
- if:
condition:
- display.is_displaying_page: page3
then:
- homeassistant.service:
service: input_number.increment
data:
entity_id: input_number.vent_fan_speed
- component.update: my_lcd
on_anticlockwise:
- if:
condition:
- display.is_displaying_page: page1
then:
- homeassistant.service:
service: media_player.volume_down
data:
entity_id: media_player.workshop
- component.update: my_lcd
- if:
condition:
- display.is_displaying_page: page2
then:
- homeassistant.service:
service: input_number.decrement
data:
entity_id: input_number.vent_fan_speed
- component.update: my_lcd
- if:
condition:
- display.is_displaying_page: page3
then:
- homeassistant.service:
service: input_number.decrement
data:
entity_id: input_number.vent_fan_speed
- component.update: my_lcd
- platform: homeassistant
name: "Media Volume"
id: "beam_volume"
entity_id: media_player.workshop
attribute: volume_level
- platform: homeassistant
name: "Vent Fan Speed"
id: vent_fan_speed
entity_id: input_number.vent_fan_speed
on_value:
- component.update: my_lcd
light:
- platform: monochromatic
id: backlight
name: "Backlight"
output: oledbacklight
default_transition_length: 250ms
output:
- id: oledbacklight
platform: ledc
pin: GPIO9
#pin: GPIO21
max_power: 1
min_power: 0
- platform: ledc
id: buzzer_out
pin:
number: GPIO3
# Enable ringtone music support
rtttl:
id: buzzer
output: buzzer_out
text_sensor:
- platform: homeassistant
name: "Media Player Mute"
id: "mediaplayermute"
entity_id: media_player.workshop
attribute: is_volume_muted
on_value:
then:
- component.update: my_lcd
- platform: homeassistant
name: "Vent Fan Status"
id: vent_fan
entity_id: switch.vent_fan
on_value:
- component.update: my_lcd