-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdial_lvgl
458 lines (436 loc) · 10.9 KB
/
dial_lvgl
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
esphome:
name: m4dial
friendly_name: M4Dial
on_boot:
priority: 600
then:
- light.turn_on: backlight
esp32:
board: esp32-s3-devkitc-1
framework:
type: arduino
external_components:
- source: github://clydebarrow/esphome@lvgl
refresh: 10min
components: [ lvgl ]
# Enable logging
logger:
level: DEBUG
api:
encryption:
key: !secret m4dialencryption
on_client_connected:
- if:
condition:
lambda: 'return (0 == client_info.find("Home Assistant "));'
then:
- delay: 1s
- lvgl.widget.hide: boot_screen
ota:
platform: esphome
password: !secret m4dialotapassword
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "M5Dial Fallback Hotspot"
password: !secret m4fallbackpassword
captive_portal:
substitutions:
# Add the ids of the devices you want to control here
light_control: light.great_room_dimmer_4
climate_control: climate.doris
cover_control: cover.bridget_s_blind
<<: !include common/colors.yaml
<<: !include common/images.yaml
i2c:
- id: bus_internal
sda: GPIO11
scl: GPIO12
scan: False
touchscreen:
platform: ft5x06
address: 0x38
id: my_touchscreen
on_release:
- if:
condition: lvgl.is_paused
then:
- logger.log: "LVGL resuming"
- lvgl.resume:
- lvgl.widget.redraw:
- light.turn_on: backlight
uart:
tx_pin: GPIO2
rx_pin: GPIO1
baud_rate: 256000
parity: NONE
stop_bits: 1
spi:
mosi_pin: GPIO5
clk_pin: GPIO6
display:
- platform: ili9xxx
model: gc9a01a
auto_clear_enabled: False
update_interval: never
reset_pin: GPIO8
id: my_lcd
cs_pin: GPIO7
dc_pin: GPIO4
dimensions:
height: 240
width: 240
binary_sensor:
- platform: gpio
pin: GPIO42
id: backlightbutton
- platform: homeassistant
id: remote_light
entity_id: $light_control
publish_initial_state: true
on_state:
then:
lvgl.widget.update:
id: light_btn
state:
checked: !lambda return x;
number:
- platform: template
name: LVGL Screen timeout
optimistic: true
id: display_timeout
unit_of_measurement: "s"
initial_value: 45
restore_value: true
min_value: 10
max_value: 180
step: 5
mode: box
sensor:
- platform: rotary_encoder
name: "Rotary Encoder"
id: rotaryencoder
resolution: 1
pin_a:
number: GPIO40
mode:
input: true
pullup: true
pin_b:
number: GPIO41
mode:
input: true
pullup: true
accuracy_decimals: 1
on_anticlockwise:
- if:
condition: lvgl.is_paused
then:
- logger.log: "LVGL resuming"
- lvgl.resume:
- lvgl.widget.redraw:
- light.turn_on: backlight
- lvgl.page.previous:
animation: OVER_LEFT
time: 250ms
on_clockwise:
- if:
condition: lvgl.is_paused
then:
- logger.log: "LVGL resuming"
- lvgl.resume:
- lvgl.widget.redraw:
- light.turn_on: backlight
- lvgl.page.next:
animation: OVER_RIGHT
time: 250ms
- platform: homeassistant
id: light_brightness
entity_id: $light_control
attribute: brightness
on_value:
- lvgl.arc.update:
id: arc_id
value: !lambda return x;
- lvgl.label.update:
id: brightness_label
text:
format: "%d%%"
args: [ 'map(x,0,255,0,100)' ]
- platform: homeassistant
id: cover_status
entity_id: $cover_control
attribute: current_position
on_value:
then:
- lvgl.arc.update:
id: cover_arc
value: !lambda return x;
- lvgl.label.update:
id: current_cover_percentage
text:
format: "%d%%"
args: [ 'map(x,0,100,0,100)' ]
- platform: homeassistant
id: cover_state
entity_id: $cover_control
- platform: homeassistant
id: light_state
entity_id: $light_control
- platform: homeassistant
id: climate_device_setpoint
entity_id: $climate_control
attribute: temperature
on_value:
- lvgl.spinbox.update:
id: spinbox_id
value: !lambda return x;
text_sensor:
- platform: homeassistant
id: climate_device
entity_id: $climate_control
filters:
- map:
- heat_cool -> Auto
- heat -> Heat
- cool -> Cool
- dry -> Dry
- fan -> Fan
- off -> Off
on_value:
then:
lvgl.label.update:
id: current_temp_label
text: !lambda return x.c_str();
light:
- platform: monochromatic
id: backlight
name: "Backlight"
output: oledbacklight
default_transition_length: 250ms
output:
- id: oledbacklight
platform: ledc
pin: GPIO9
max_power: 1
min_power: 0.1
image:
- file: https://esphome.io/_static/favicon-512x512.png
id: boot_logo
resize: 100x100
type: RGB565
use_transparency: true
lvgl:
on_idle:
timeout: !lambda "return (id(display_timeout).state * 1000);"
then:
- logger.log: "LVGL is idle"
- light.turn_off: backlight
- lvgl.pause:
top_layer:
widgets:
# make sure it's the last one in this list:
- obj:
id: boot_screen
x: 0
y: 0
width: 100%
height: 100%
bg_color: 0x000000
bg_opa: COVER
radius: 0
pad_all: 0
border_width: 0
widgets:
- img:
align: CENTER
src: boot_logo
y: -20
- spinner:
align: CENTER
y: 65
height: 50
width: 50
spin_time: 1s
arc_length: 60deg
arc_width: 8
indicator:
arc_color: 0x18bcf2
arc_width: 8
on_press:
- lvgl.widget.hide: boot_screen
rotary_encoders:
sensor: rotaryencoder
enter_button: backlightbutton
group: control_group
theme:
arc:
arc_color: very_dark_grey_color
knob:
bg_color: dark_orange_color
indicator:
arc_color: mid_orange_color
arc_width: 16
btn:
text_font: montserrat_18
bg_color: very_dark_grey_color
checked:
bg_color: ice_orange_color
label:
text_font: montserrat_18
text_color: white_color
displays:
- my_lcd
touchscreens:
- my_touchscreen
pages:
- id: lightpage
bg_color: 0x000000
widgets:
- label:
id: brightness_label
align: CENTER
text: ""
- arc:
width: 200
height: 200
align: CENTER
group: control_group
arc_width: 16
id: arc_id
value: 0
min_value: 0
max_value: 255
adjustable: true
on_release:
- homeassistant.service:
service: light.turn_on
data:
entity_id: $light_control
brightness: !lambda return int(x);
- btn:
id: light_btn
align: CENTER
y: 70
width: 50
height: 50
radius: 3000
checkable: true
widgets:
- label:
align: CENTER
text: "\uF011"
on_click:
- homeassistant.service:
service: light.toggle
data:
entity_id: $light_control
- id: climatepage
bg_color: 0x000000
widgets:
- label:
id: current_temp_label
align: CENTER
text: "CLIMATE"
y: 70
- obj:
align: CENTER
y: 0
layout:
type: FLEX
flex_flow: ROW
flex_align_cross: CENTER
width: SIZE_CONTENT
height: SIZE_CONTENT
widgets:
- btn:
id: spin_down
on_click:
- lvgl.spinbox.decrement: spinbox_id
widgets:
- label:
text: "-"
- spinbox:
id: spinbox_id
align: CENTER
text_align: CENTER
width: 50
range_from: 17
range_to: 35
step: 1
rollover: false
digits: 2
decimal_places: 0
on_value:
then:
- homeassistant.service:
service: climate.set_temperature
data:
temperature: !lambda return x;
entity_id: $climate_control
- btn:
id: spin_up
on_click:
- lvgl.spinbox.increment: spinbox_id
widgets:
- label:
text: "+"
- id: coverpage
bg_color: 0x000000
widgets:
- label:
y: 70
id: current_cover_percentage
align: CENTER
text: "Sunshade"
- arc:
width: 200
height: 200
align: CENTER
group: control_group
arc_width: 16
id: cover_arc
value: 0
min_value: 0
max_value: 100
adjustable: true
on_release:
- homeassistant.service:
service: cover.set_cover_position
data:
entity_id: $cover_control
position: !lambda return int(x);
- btn:
x: -30
width: 50
height: 50
radius: 3000
id: cover_down_btn
align: CENTER
widgets:
- label:
align: CENTER
text: "\uF078"
on_press:
- homeassistant.service:
service: cover.close_cover
data:
entity_id: $cover_control
- btn:
x: 30
width: 50
height: 50
radius: 3000
id: cover_up_btn
align: CENTER
widgets:
- label:
align: CENTER
text: "\uF077"
on_press:
- homeassistant.service:
service: cover.open_cover
data:
entity_id: $cover_control