-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnspanel_esphome_hw_display.yaml
More file actions
724 lines (662 loc) · 25.1 KB
/
nspanel_esphome_hw_display.yaml
File metadata and controls
724 lines (662 loc) · 25.1 KB
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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
#####################################################################################################
##### NSPanel Easy - https://github.com/edwardtfn/NSPanel-Easy #####
#####################################################################################################
##### ESPHOME CORE - HARDWARE - Display #####
##### PLEASE only make changes if it is necessary and also the required knowledge is available. #####
##### For normal use with the Blueprint, no changes are necessary. #####
#####################################################################################################
---
substitutions:
##############################
## Change only in your ##
## local yaml substitutions ##
##############################
THEME_DARK_LABEL: Dark
THEME_DARK_COLOR_PCO_MAIN: ${COLOR_WHITE} # Foreground font color for main information
THEME_DARK_COLOR_PCO_SECONDARY: ${COLOR_GRAY_LIGHT} # Foreground font color for secondary information
THEME_DARK_COLOR_PCO_NAVIGATION: ${COLOR_GRAY_MOSS} # Foreground font color for navigation components, like back button or page index
THEME_DARK_COLOR_PCO_UNSUPPORTED: ${COLOR_GRAY_DARKEST} # Foreground font color for unsupported or unavailable components
THEME_LIGHT_LABEL: Light (Under construction)
THEME_LIGHT_COLOR_PCO_MAIN: ${COLOR_BLACK} # BLACK - main text on white bg
THEME_LIGHT_COLOR_PCO_SECONDARY: ${COLOR_GRAY_MEDIUM} # Mid gray for secondary
THEME_LIGHT_COLOR_PCO_NAVIGATION: ${COLOR_GRAY_DARK} # Colors::GRAY_DARK for navigation
THEME_LIGHT_COLOR_PCO_UNSUPPORTED: ${COLOR_GRAY_LIGHT} # Light gray - visually "faded"
BAUD_RATE: '115200'
BOOT_STEP_HW_DISPLAY: '5'
button_back_font: "8"
COLOR_BLACK: '0' # Colors::BLACK
COLOR_BLUE_INDIGO: '10597' # Colors::BLUE_INDIGO
COLOR_CYAN_BRIGHT: '7519' # Colors::CYAN_BRIGHT
COLOR_GRAY_DARK: '16904' # Colors::GRAY_DARK
COLOR_GRAY_DARKEST: '6339' # Colors::GRAY_DARKEST
COLOR_GRAY_LIGHT: '52857' # Colors::GRAY_LIGHT
COLOR_GRAY_MEDIUM: '29614' # Colors::GRAY_MEDIUM — mid gray, secondary text on light backgrounds
COLOR_GRAY_MOSS: '33808' # Colors::GRAY_MOSS
COLOR_RED_PRIMARY: '63488' # Colors::RED
COLOR_WHITE: '65535' # Colors::WHITE
COLOR_YELLOW_GOLDEN: '64992' # Colors::YELLOW_GOLDEN
DISPLAY_CHARSET_CJK: 2
DISPLAY_CHARSET_INTERNATIONAL: 1
GPIO_DISPLAY_NEXTION_RX_PIN: 17
GPIO_DISPLAY_NEXTION_TX_PIN: 16
GPIO_DISPLAY_POWER_PIN:
number: 4
inverted: true
TAG_HW_DISPLAY: nspanel.hw.display
api:
actions:
# Wake Up Service
- action: wake_up
variables:
reset_timer: bool # Determines whether to reset the sleep and dimming timers upon waking the display.
then:
- lambda: wakeup->execute(reset_timer);
binary_sensor:
- id: nextion_init # Delays initial info from HA to the display
name: Nextion display
platform: template
device_class: connectivity
entity_category: diagnostic
icon: mdi:tablet-dashboard
lambda: |-
return is_device_ready_for_tasks();
on_release:
then:
- lambda: system_flags.nextion_ready = false;
display:
- id: disp1
platform: nextion
uart_id: tf_uart
command_spacing: 5ms
# dump_device_info: true # To-do: Enable when pr#13566 is released
max_commands_per_loop: 15
update_interval: never
on_setup:
then:
- lambda: |-
current_page_id = get_page_id("boot");
wakeup_page_id = get_page_id(wakeup_page_name->current_option());
wait_for_display->stop();
ESP_LOGI("${TAG_HW_DISPLAY}", "Nextion setup triggered");
system_flags.nextion_ready = true;
nextion_init->publish_state(true);
disp1->send_command_printf("button_back_font=%i", id(button_back_font));
on_page:
then:
- lambda: |-
ESP_LOGI("${TAG_HW_DISPLAY}", "Page changed: '%s'->'%s'", page_names[current_page_id], page_names[x]);
ESP_LOGW_IF("${TAG_HW_DISPLAY}", (x == current_page_id), "Same page");
page_change->execute(x);
on_touch:
then:
- script.execute: timer_reset_all
esphome:
platformio_options:
build_flags:
- -D NSPANEL_EASY_HW_DISPLAY
globals:
- id: button_back_font
type: uint8_t
restore_value: true
initial_value: ${button_back_font}
- id: theme_pending_apply
type: bool
restore_value: false
initial_value: 'false'
number:
- id: display_brightness # Screen brightness when in use
name: Display Brightness
platform: template
entity_category: config
unit_of_measurement: '%'
min_value: 1
max_value: 100
initial_value: 100
step: 1
restore_value: true
optimistic: true
update_interval: never
on_value:
then:
- lambda: |-
disp1->send_command_printf("brightness=%i", int(x));
- if:
condition:
- lambda: return current_page_id != get_page_id("screensaver");
then:
- script.execute:
id: set_brightness
brightness: !lambda return x;
- id: display_dim_brightness # Screen brightness when dimmed down
name: Display Brightness Dimdown
platform: template
entity_category: config
unit_of_measurement: '%'
min_value: 1
max_value: 100
initial_value: 25
step: 1
restore_value: true
optimistic: true
on_value:
then:
- lambda: |-
disp1->send_command_printf("brightness_dim=%i", int(x));
- if:
condition:
- lambda: return current_page_id != get_page_id("screensaver");
then:
- script.execute:
id: set_brightness
brightness: !lambda return x;
script:
- id: !extend action_component_val
then:
- lambda: |-
if (page != "mem") return;
if (component == "button_back_font") {
id(button_back_font) = static_cast<uint8_t>(val);
disp1->send_command_printf("button_back_font=%i", id(button_back_font));
return;
}
- id: !extend boot_wrap_up
then:
- script.execute: theme_update
- script.wait: theme_update
- id: !extend dump_config
then:
# Report UART
- lambda: |-
ESP_LOGCONFIG("${TAG_HW_DISPLAY}", "UART:");
ESP_LOGCONFIG("${TAG_HW_DISPLAY}", " Baud rate: %" PRIu32 " bps", tf_uart->get_baud_rate());
ESP_LOGCONFIG("${TAG_HW_DISPLAY}", " Queue size: %d", tf_uart->available());
# Report Nextion status
- lambda: |-
ESP_LOGCONFIG("${TAG_HW_DISPLAY}", "Nextion:");
ESP_LOGCONFIG("${TAG_HW_DISPLAY}", " Theme: %s", background_type->current_option());
ESP_LOGCONFIG("${TAG_HW_DISPLAY}", " Queue size: %d", disp1->queue_size());
if (disp1->is_setup())
ESP_LOGCONFIG("${TAG_HW_DISPLAY}", " Is setup: True");
else {
ESP_LOGW("${TAG_HW_DISPLAY}", " Is setup: False");
ESP_LOGW("${TAG_HW_DISPLAY}", " Is detected: %s", YESNO(disp1->is_detected()));
//exit_reparse->execute();
}
if (nextion_init->state) {
ESP_LOGCONFIG("${TAG_HW_DISPLAY}", " Init: True");
} else
ESP_LOGW("${TAG_HW_DISPLAY}", " Init: False");
if (version_tft > 0)
ESP_LOGCONFIG("${TAG_HW_DISPLAY}", " TFT: %" PRIu8, version_tft);
else
ESP_LOGW("${TAG_HW_DISPLAY}", " TFT: UNKNOWN");
# Report wake-up page
- lambda: |-
ESP_LOGCONFIG("${TAG_HW_DISPLAY}", "Wake-up page: %s", page_names[wakeup_page_id]);
- id: event_from_display
mode: restart
parameters:
params: std::vector<std::string>
params_count: uint8_t
then:
# Extended by:
# - page_alarm
# - page_boot
# - page_climate
# - page_cover
# - page_fan
# - page_home
- lambda: |-
ESP_LOGV("${TAG_HW_DISPLAY}", "New event from display:");
ESP_LOGV("${TAG_HW_DISPLAY}", " params: %d", params_count);
if (params_count < 1) {
ESP_LOGW("${TAG_HW_DISPLAY}", "Bad params");
return;
}
const std::string page = params[0].c_str();
ESP_LOGV("${TAG_HW_DISPLAY}", " page: %s", page.c_str());
if (params_count >= 2) {
const std::string& event = params[1];
if (event == "short_click" || event == "long_click") {
if (params_count != 3) {
ESP_LOGW("${TAG_HW_DISPLAY}", "Bad params");
return;
}
// Button click event
ESP_LOGD("${TAG_HW_DISPLAY}", "%s->HA", event.c_str());
fire_ha_event("button_click", {
{"page", page.c_str()},
{"command", event.c_str()},
{"component", params[2].c_str()}
});
ESP_LOGV("${TAG_HW_DISPLAY}", "Event sent");
} else if (page != "button" and
page != "home" and
page != "light" and
page != "switch") {
// Generic event
ESP_LOGD("${TAG_HW_DISPLAY}", "Send generic event to Home Assistant");
fire_ha_event("button_click", {
{"page", page.c_str()},
{"event", params[1].c_str()},
{"component", params_count > 2 ? params[2].c_str() : ""},
{"value", params_count > 3 ? params[3].c_str() : ""},
{"entity", detailed_entity->state.c_str()}
});
ESP_LOGD("${TAG_HW_DISPLAY}", "Home Assistant generic event sent");
}
} // params_count >= 2
- id: goto_page
mode: restart
parameters:
page_id: uint8_t
then:
- lambda: |-
ESP_LOGV("${TAG_HW_DISPLAY}", "Go to page '%s' (id: %" PRIu8 ")", page_names[page_id], page_id);
if (page_id == current_page_id) {
ESP_LOGW("${TAG_HW_DISPLAY}", "Already the current page");
return;
}
ESP_LOGVV("${TAG_HW_DISPLAY}", "Send page id '%" PRIu8 "' to Nextion", page_id);
disp1->goto_page(page_id);
- id: page_change
mode: restart
parameters:
new_page_id: uint8_t
then:
- lambda: |-
// Report new page to logs
ESP_LOGV("${TAG_HW_DISPLAY}", "New page: %s", page_names[new_page_id]);
current_page->publish_state(page_names[new_page_id]);
if (current_page_id != new_page_id) {
last_page_id = current_page_id;
current_page_id = new_page_id;
}
// Stop previous constructors
ESP_LOGV("${TAG_HW_DISPLAY}", "Stop previous constructors");
stop_page_constructors->execute();
// Reset globals
ESP_LOGV("${TAG_HW_DISPLAY}", "Reset globals");
if (new_page_id != get_page_id("alarm") &&
new_page_id != get_page_id("button") &&
new_page_id != get_page_id("climate") &&
new_page_id != get_page_id("cover") &&
new_page_id != get_page_id("fan") &&
new_page_id != get_page_id("light") &&
new_page_id != get_page_id("media_player") &&
new_page_id != get_page_id("switch") &&
new_page_id != get_page_id("water_heater") &&
new_page_id != get_page_id("confirm") &&
new_page_id != get_page_id("keyb_num")) {
detailed_entity->publish_state("");
disp1->send_command("back_page_id=1");
} else { // Report detailed entity
ESP_LOGD("${TAG_HW_DISPLAY}", "Entity shown: %s", detailed_entity->state.c_str());
}
if (new_page_id != get_page_id("media_player")) {
last_volume_level = 0;
last_media_duration = 0;
last_media_position = 0;
}
// Reset timers
if (current_page_id != get_page_id("screen_saver")) {
ESP_LOGV("${TAG_HW_DISPLAY}", "Reset timers");
timer_reset_all->execute();
}
# Wait for other constructors to stop before telling the blueprint about a new page
- script.wait: stop_page_constructors
- lambda: |-
// Report new page to Blueprint
if (last_page_id != UINT8_MAX and last_page_id != new_page_id) {
ESP_LOGV("${TAG_HW_DISPLAY}", "Report new page to Blueprint");
fire_ha_event("page_changed", {
{"page", page_names[new_page_id]},
{"entity", detailed_entity->state.c_str()}
});
}
// Update buttons bars on screen
ESP_LOGV("${TAG_HW_DISPLAY}", "Update buttons bars on screen");
refresh_hardware_buttons_bars->execute(3);
- id: set_brightness
mode: single
parameters:
brightness: uint8_t
then:
- lambda: |-
if (brightness <= 100 and brightness_current != brightness) {
ESP_LOGD("${TAG_HW_DISPLAY}", "Brightness: %" PRIu8 "%%->%" PRIu8 "%%", brightness_current, brightness);
brightness_current = brightness;
disp1->set_backlight_brightness(brightness / 100.0f);
}
- id: set_component_font_color_DEPRECATED
mode: single
parameters:
component_id: string
color: uint16_t
then:
- lambda: disp1->set_component_font_color(component_id.c_str(), color);
- id: !extend stop_all
then:
- lambda: |-
stop_page_constructors->execute();
event_from_display->stop();
goto_page->stop();
page_change->stop();
set_brightness->stop();
set_component_font_color_DEPRECATED->stop();
theme_update->stop();
theme_update_all->stop();
theme_update_dark->stop();
theme_update_light->stop();
timer_dim->stop();
timer_page->stop();
timer_reset_all->stop();
wait_for_uart_available->stop();
wait_for_version_tft->stop();
wakeup->stop();
- id: stop_page_constructors
mode: single
then: # Page home is an exception, as it can be constructed in the background
- id: theme_update
then:
- lambda: |-
ESP_LOGI("${TAG_HW_DISPLAY}", "Apply theme: %s", background_type->current_option());
if (display_mode == 4) { // To do: Implement logic for new format
ESP_LOGI("${TAG_HW_DISPLAY}", "New format - No themes yet");
return;
}
current_theme = (background_type->current_option() == "${THEME_LIGHT_LABEL}") ?
ThemeMode::LIGHT : ThemeMode::DARK;
theme_update_all->execute();
- script.wait: theme_update_all
- lambda: |-
if (current_theme == ThemeMode::LIGHT) {
theme_update_light->execute();
} else {
theme_update_dark->execute();
}
- script.wait: theme_update_dark
- script.wait: theme_update_light
- lambda: |-
if (current_page_id == get_page_id("boot")) {
id(theme_pending_apply) = true;
return;
}
// Call page theme_apply
disp1->send_command("theme_apply.previous_page.val=dp");
disp1->send_command("page theme_apply");
- id: theme_update_all
mode: restart
then:
- lambda: |-
ESP_LOGI("${TAG_HW_DISPLAY}", "Applying theme: %s", (current_theme == ThemeMode::LIGHT) ? "LIGHT" : "DARK");
disp1->send_command_printf("theme=%" PRIu8, (current_theme == ThemeMode::LIGHT) ? 1 : 0);
- id: theme_update_dark
mode: restart
then:
- lambda: |-
ESP_LOGI("${TAG_HW_DISPLAY}", "Applying DARK theme");
disp1->send_command("color_pco_main=${THEME_DARK_COLOR_PCO_MAIN}");
disp1->send_command("color_pco_secondary=${THEME_DARK_COLOR_PCO_SECONDARY}");
disp1->send_command("color_pco_navigation=${THEME_DARK_COLOR_PCO_NAVIGATION}");
disp1->send_command("color_pco_unsupported=${THEME_DARK_COLOR_PCO_UNSUPPORTED}");
- id: theme_update_light
mode: restart
then:
- lambda: |-
ESP_LOGI("${TAG_HW_DISPLAY}", "Applying LIGHT theme");
disp1->send_command("color_pco_main=${THEME_LIGHT_COLOR_PCO_MAIN}");
disp1->send_command("color_pco_secondary=${THEME_LIGHT_COLOR_PCO_SECONDARY}");
disp1->send_command("color_pco_navigation=${THEME_LIGHT_COLOR_PCO_NAVIGATION}");
disp1->send_command("color_pco_unsupported=${THEME_LIGHT_COLOR_PCO_UNSUPPORTED}");
###### Timers ######
- id: timer_dim # Handles the brightness dimming after a timeout
mode: restart
then:
- lambda: set_brightness->execute(display_brightness->state);
- delay: !lambda return (int(timeout_dim->state) *1000);
- lambda: |-
if (
timeout_dim->state >= 1 and
current_page_id != get_page_id("screensaver") and
current_page_id != get_page_id("boot")
) {
set_brightness->execute(display_dim_brightness->state);
}
- id: timer_page # Handles the fallback to home page after a timeout
mode: restart
then:
- delay: !lambda return (int(timeout_page->state) *1000);
- lambda: |-
if (timeout_page->state >= 1) {
ESP_LOGV("${TAG_HW_DISPLAY}", "Timed out on page: %s", page_names[current_page_id]);
if (current_page_id != get_page_id("boot") and
current_page_id != get_page_id("confirm") and
current_page_id != get_page_id("home") and
current_page_id != get_page_id("notification") and
current_page_id != get_page_id("screensaver")) {
ESP_LOGD("${TAG_HW_DISPLAY}", "Fallback to page Home");
goto_page->execute(get_page_id("home"));
}
}
- id: timer_reset_all # Global timer reset - Triggered with a touch on the screen
mode: single
then:
# Extended by:
# - page_screensaver
- lambda: |-
ESP_LOGV("${TAG_HW_DISPLAY}", "Reset timers");
timer_page->execute();
timer_dim->execute();
- id: wait_for_display
mode: single
then:
- if:
condition:
- lambda: return !disp1->is_setup();
then:
- switch.turn_on: screen_power
- delay: 19s
- while:
condition:
- lambda: return !disp1->is_setup();
then:
- lambda: |-
ESP_LOGE("${TAG_HW_DISPLAY}", "Display is not set. Restarting.");
screen_power->turn_off();
- delay: 2s
- switch.turn_on: screen_power
- delay: 19s
- id: wait_for_uart_available
mode: single
then:
- repeat:
count: 60 # seconds
then:
- lambda: |-
if (tf_uart->available() < 1) wait_for_uart_available->stop();
if (iteration % 5 == 0) boot_log->execute("Boot", "Waiting for UART empty queue");
- delay: 1s
- id: wait_for_version_tft
mode: single
then:
- script.execute:
id: boot_log
category: Boot
log_message: Check TFT version
- repeat:
count: 180 # seconds
then:
- lambda: |-
if (version_tft > 0) wait_for_version_tft->stop();
if (iteration % 5 == 0) boot_log->execute("Boot", "Waiting for TFT version");
- delay: 1s
- id: !extend wait_for_versions
then:
- script.execute: wait_for_version_tft
- script.wait: wait_for_version_tft
- id: wakeup
mode: single
parameters:
reset_timer: bool
then:
- lambda: |-
ESP_LOGV("${TAG_HW_DISPLAY}", "Wake-up (%s->%s)", page_names[current_page_id], page_names[wakeup_page_id]);
ESP_LOGV("${TAG_HW_DISPLAY}", " reset timer: %s", YESNO(reset_timer));
if (version_tft == 0) {
ESP_LOGE("${TAG_HW_DISPLAY}", "TFT version invalid");
return;
}
if (display_mode == 4) { // To do: Implement logic for new format
ESP_LOGI("${TAG_HW_DISPLAY}", "New format - Just go to home page");
goto_page->execute(get_page_id("home"));
return;
}
if (current_page_id == get_page_id("screensaver") or current_page_id == get_page_id("boot")) {
ESP_LOGD("${TAG_HW_DISPLAY}", "Wake-up on page %s", page_names[wakeup_page_id]);
if (wakeup_page_id == get_page_id("climate")) {
detailed_entity->publish_state((id(is_embedded_thermostat)) ? "embedded_climate" : "");
disp1->set_component_value("climate.embedded", id(is_embedded_thermostat) ? 1 : 0);
}
if (id(theme_pending_apply)) {
// Call page theme_apply
disp1->send_command_printf("theme_apply.previous_page.val=%" PRIu8, wakeup_page_id);
disp1->send_command("page theme_apply");
} else {
goto_page->execute(wakeup_page_id);
}
}
if (reset_timer) {
timer_reset_all->execute();
} else {
timer_sleep->execute();
timer_dim->execute();
}
- id: !extend watchdog_round
then:
- script.execute: wait_for_display
select:
- id: background_type
name: Background type
platform: template
options:
- ${THEME_DARK_LABEL}
- ${THEME_LIGHT_LABEL}
initial_option: ${THEME_DARK_LABEL}
optimistic: true
restore_value: true
internal: false
disabled_by_default: false
entity_category: config
icon: mdi:theme-light-dark
update_interval: never
on_value:
then:
- script.execute: theme_update
- id: wakeup_page_name
name: Wake-up page
platform: template
options:
- buttonpage01
- buttonpage02
- buttonpage03
- buttonpage04
- climate
- entitypage01
- entitypage02
- entitypage03
- entitypage04
- home
- qrcode
- utilities
initial_option: home
optimistic: true
restore_value: true
internal: false
entity_category: config
icon: mdi:page-next-outline
update_interval: never
on_value:
then:
- lambda: |-
wakeup_page_id = get_page_id(x.c_str());
wait_to_be_ready->execute();
- script.wait: wait_to_be_ready
# Extended by:
# - page_screensaver
switch:
- id: screen_power # Controls the display's power source
name: Nextion display - Power
platform: gpio
entity_category: diagnostic
pin: ${GPIO_DISPLAY_POWER_PIN}
restore_mode: ALWAYS_ON
disabled_by_default: true
internal: true
on_turn_off:
then:
- lambda: nextion_init->publish_state(false);
text_sensor:
- id: current_page # Current page name
name: Current Page
platform: template
icon: mdi:tablet-dashboard
internal: false
disabled_by_default: false
update_interval: never
- id: detailed_entity # Entity Id of the entity displayed on the detailed pages
name: Detailed Entity
platform: template
icon: mdi:tablet-dashboard
internal: false
disabled_by_default: false
update_interval: never
- id: disp1_local_event
name: NSPanel local event
platform: nextion
nextion_id: disp1
component_name: localevent
internal: true
update_interval: never
on_value:
then:
- lambda: |-
// Check format by first character
if (x.empty()) {
ESP_LOGE("${TAG_HW_DISPLAY}", "Empty message");
return;
}
if (x[0] == '{') {
ESP_LOGE("${TAG_HW_DISPLAY}", "Legacy json format used");
if (system_flags.version_check_ok) {
ESP_LOGE("${TAG_HW_DISPLAY}", "Please report a bug on the project's GitHub repo");
} else {
ESP_LOGE("${TAG_HW_DISPLAY}", "Please upload a compatible TFT");
}
return;
}
// ============================================================
// CSV Format (New - preferred)
// ============================================================
static std::vector<std::string> params;
params.clear();
size_t start = 0;
size_t pos = 0;
// Split by ',' delimiter
while ((pos = x.find(',', start)) != std::string::npos) {
params.push_back(x.substr(start, pos - start));
start = pos + 1;
}
params.push_back(x.substr(start)); // Last part
if (params.size() < 2) {
ESP_LOGE("${TAG_HW_DISPLAY}", "Invalid CSV format: %s", x.c_str());
return;
}
// Call new CSV handler
event_from_display->execute(params, static_cast<uint8_t>(params.size()));
uart:
- id: tf_uart # UART for Nextion display
tx_pin: ${GPIO_DISPLAY_NEXTION_TX_PIN}
rx_pin: ${GPIO_DISPLAY_NEXTION_RX_PIN}
baud_rate: ${BAUD_RATE}
...