forked from Blackymas/NSPanel_HA_Blueprint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nspanel_esphome.yaml
2317 lines (2158 loc) · 93.5 KB
/
nspanel_esphome.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
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
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#####################################################################################################
##### NSPANEL ESPHOME created by Blackymas - https://github.com/Blackymas/NSPanel_HA_Blueprint #####
##### ADVANCED CONFIG + FULL ESPHOME CODE! #####
##### 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:
##### DON'T CHANGE THIS #####
version: "4.0.2"
#############################
##### WIFI SETUP #####
wifi:
networks:
- id: wifi_default
ssid: ${wifi_ssid}
password: ${wifi_password}
power_save_mode: none
ap:
ssid: "${device_name}"
password: ${wifi_password}
##### ESPHOME CONFIGURATION #####
esphome:
name: ${device_name}
min_version: 2023.5.0
##### TYPE OF ESP BOARD #####
esp32:
board: esp32dev
captive_portal:
web_server:
id: web_server_std
port: 80
auth:
username: admin
password: ${wifi_password}
##### OTA PASSWORD #####
ota:
id: ota_std
password: ${wifi_password}
safe_mode: true
reboot_timeout: 3min
num_attempts: 3
##### LOGGER #####
logger:
id: logger_std
##### ENABLE RINGTONE MUSIC SUPPORT #####
rtttl:
id: buzzer
output: buzzer_out
##### CONFIGURE INTERNAL BUZZER #####
output:
##### BUZZER FOR PLAYING RINGTONES #####
- platform: ledc
id: buzzer_out
pin:
number: 21
##### UART FOR NEXTION DISPLAY #####
uart:
id: tf_uart
tx_pin: 16
rx_pin: 17
baud_rate: 115200
##### Keeps time display updated #####
time:
- id: time_provider
platform: homeassistant
on_time:
- seconds: 0
then:
- script.execute:
id: refresh_datetime
on_time_sync:
then:
- component.update: api_timestamp
- component.update: device_timestamp
- logger.log: "System clock synchronized"
- script.execute:
id: refresh_datetime
##### START - BUTTON CONFIGURATION #####
button:
###### REBOOT BUTTON #####
- name: ${device_name} Restart
platform: restart
id: restart_nspanel
##### UPDATE TFT DISPLAY #####
- name: ${device_name} Update TFT display
platform: template
icon: mdi:file-sync
id: tft_update
entity_category: config
on_press:
- logger.log: "Button pressed: Update TFT display"
- binary_sensor.template.publish:
id: nextion_init
state: false
- delay: 16ms
- lambda: id(disp1).upload_tft();
##### EXIT REPARSE TFT DISPLAY #####
- name: ${device_name} Exit reparse
platform: template
icon: mdi:file-sync
id: tft_reparse_off
entity_category: config
on_press:
- logger.log: "Button pressed: Exit reparse"
- uart.write:
id: tf_uart
data: "DRAKJHSUYDGBNCJHGJKSHBDN"
- uart.write:
id: tf_uart
data: [0xFF, 0xFF, 0xFF]
##### START - API CONFIGURATION #####
api:
id: api_server
reboot_timeout: 0s
services:
##### SERVICE TO UPDATE THE HMI FILE ##############
- service: upload_tft
then:
- logger.log: "Service: upload_tft"
- binary_sensor.template.publish:
id: nextion_init
state: false
- lambda: 'id(disp1)->upload_tft();'
##### SERVICE TO UPDATE THE TFT FILE from URL #####
- service: upload_tft_url
variables:
url: string
then:
- logger.log: "Service: upload_tft_url"
- binary_sensor.template.publish:
id: nextion_init
state: false
- lambda: 'id(disp1)->set_tft_url(url.c_str());'
- lambda: 'id(disp1)->upload_tft();'
##### Service to send a command "printf" directly to the display #####
- service: send_command_printf
variables:
cmd: string
then:
- lambda: 'id(disp1).send_command_printf("%s", cmd.c_str());'
##### Service to send a command "text_printf" directly to the display #####
- service: send_command_text_printf
variables:
component: string
message: string
then:
- lambda: 'id(disp1).set_component_text_printf(component.c_str(), "%s", message.c_str());'
##### Service to send a command "component_value (Dualstate Button)" directly to the display #####
- service: send_command_value
variables:
component: string
message: int
then:
- lambda: 'id(disp1).set_component_value(component.c_str(), message);'
##### Service to send a command "hide componente" directly to the display #####
- service: send_command_hide ### unused ###
variables:
component: string
then:
- lambda: 'id(disp1).hide_component(component.c_str());'
##### Service to send a command "show componente" directly to the display #####
- service: send_command_show ### unused ###
variables:
component: string
then:
- lambda: 'id(disp1).show_component(component.c_str());'
##### Service to send a command "show ALL componente" directly to the display #####
- service: send_command_show_all ### unused ###
then:
- lambda: id(disp1).show_component("255");
##### Service to send a command "font color" directly to the display #####
- service: set_component_color
variables:
component: string
foreground: int[]
background: int[]
then:
- lambda: id(set_component_color).execute(component, foreground, background);
##### Service to show a notification-message on the screen #####
- service: notification_show
variables:
label: string
text: string
then:
- lambda: |-
ESP_LOGV("service.notification_show", "Starting");
id(disp1).send_command_printf("is_notification=1");
id(disp1).goto_page("notification");
id(disp1).set_component_text_printf("notification.notifi_label", "%s", label.c_str());
id(display_wrapped_text).execute("notification.notifi_text01", text.c_str(), id(display_mode) == 2 ? 23 : 32);
id(notification_label).publish_state(label.c_str());
id(notification_text).publish_state(text.c_str());
id(timer_reset_all).execute(id(current_page).state.c_str());
- switch.turn_on: notification_unread
- if:
condition:
- switch.is_on: notification_sound
then:
- rtttl.play: "two short:d=4,o=5,b=100:16e6,16e6"
##### Service to clear the notification #####
- service: notification_clear
then:
- logger.log: "Service: notification_clear"
- ¬ification_clear
lambda: |-
id(disp1).send_command_printf("is_notification=0");
id(notification_label).publish_state("");
id(notification_text).publish_state("");
- switch.turn_off: notification_unread
##### Service to open information for settings-page(s)
- service: open_entity_settings_page
variables:
page: string
page_label: string
page_icon: string
page_icon_color: int[]
entity: string
back_page: string
then:
- lambda: |-
id(entity_id) = entity;
std::string cmd_page = std::string("page ") + page.c_str();
id(disp1).send_command_printf(cmd_page.c_str());
id(disp1).set_component_text_printf("page_label", "%s", page_label.c_str());
id(disp1).set_component_text_printf("back_page", "%s", back_page.c_str());
if (page == "climate")
{
if (entity == "embedded_climate") id(addon_climate_set_climate_friendly_name).execute(page_label.c_str());
id(disp1).set_component_value("embedded", (entity == "embedded_climate") ? 1 : 0);
}
else
{
if ((page_icon.c_str() != std::string()) and (page_icon.c_str() != ""))
id(disp1).set_component_text_printf("icon_state", "%s", page_icon.c_str());
id(set_component_color).execute("icon_state", page_icon_color, {});
}
##### Service to play a rtttl tones #####
# Example tones : https://codebender.cc/sketch:109888#RTTTL%20Songs.ino
- service: play_rtttl
variables:
song_str: string
then:
- rtttl.play:
rtttl: !lambda 'return song_str;'
# Service to show a QR code on the display (ex. for WiFi password)
- service: qrcode
variables:
title: string
qrcode: string
show: bool
then:
- lambda: |-
id(disp1).set_component_text_printf("qrcode.qrcode_label", "%s", title.c_str());
id(disp1).set_component_text_printf("qrcode.qrcode_value", "%s", qrcode.c_str());
if (show) id(disp1).goto_page("qrcode");
#### Service to set climate state ####
- service: set_climate
variables:
current_temp: float
target_temp: float
temp_step: int
total_steps: int
temp_offset: int
climate_icon: string
embedded_climate: bool
entity: string
then:
- lambda: |-
if (id(current_page).state == "climate") id(entity_id) = entity;
- script.execute:
id: set_climate
current_temp: !lambda "return current_temp;"
target_temp: !lambda "return target_temp;"
temp_step: !lambda "return temp_step;"
total_steps: !lambda "return total_steps;"
temp_offset: !lambda "return temp_offset;"
climate_icon: !lambda "return climate_icon;"
embedded_climate: !lambda "return embedded_climate;"
#### Service to set the buttons ####
- service: set_button
variables:
btn_id: string
btn_pic: int
btn_bg: int[]
btn_icon_font: int[]
btn_txt_font: int[]
btn_bri_font: int[]
btn_icon: string
btn_label: string
btn_bri_txt: string
then:
- lambda: |-
std::string btnicon = btn_id.c_str() + std::string("icon");
std::string btntext = btn_id.c_str() + std::string("text");
std::string btnbri = btn_id.c_str() + std::string("bri");
id(disp1).send_command_printf("%spic.pic=%i", btn_id.c_str(), btn_pic);
id(set_component_color).execute(btnicon.c_str(), btn_icon_font, btn_bg);
id(set_component_color).execute(btntext.c_str(), btn_txt_font, btn_bg);
id(set_component_color).execute(btnbri.c_str(), btn_bri_font, btn_bg);
id(disp1).set_component_text_printf(btnicon.c_str(), "%s", btn_icon.c_str());
id(display_wrapped_text).execute(btntext.c_str(), btn_label.c_str(), 10);
if (strcmp(btn_bri_txt.c_str(), "0") != 0)
id(disp1).set_component_text_printf(btnbri.c_str(), "%s", btn_bri_txt.c_str());
else
id(disp1).set_component_text_printf(btnbri.c_str(), " ");
##### SERVICE TO WAKE UP THE DISPLAY #####
- service: wake_up
variables:
reset_timer: bool
then:
- lambda: |-
if (id(current_page).state == "screensaver") id(disp1).goto_page(id(wakeup_page_name).state.c_str());
if (reset_timer)
id(timer_reset_all).execute(id(wakeup_page_name).state.c_str());
else
{
id(timer_sleep).execute(id(wakeup_page_name).state.c_str(), int(id(timeout_sleep).state));
id(timer_dim).execute(id(wakeup_page_name).state.c_str(), int(id(timeout_dim).state));
}
#### Service to set the entities ####
- service: set_entity
variables:
ent_id: string
ent_icon: string
ent_label: string
ent_value: string
ent_value_xcen: string
then:
- lambda: |-
std::string enticon = ent_id.c_str() + std::string("_pic");
std::string entlabel = ent_id.c_str() + std::string("_label");
std::string entxcen = ent_id.c_str() + std::string(".xcen=") + ent_value_xcen.c_str();
id(disp1).set_component_text_printf(enticon.c_str(), "%s", ent_icon.c_str());
if (strcmp(ent_icon.c_str(), "0") != 0) id(disp1).set_component_text_printf(enticon.c_str(), "%s", ent_icon.c_str());
id(disp1).set_component_text_printf(entlabel.c_str(), "%s", ent_label.c_str());
id(disp1).set_component_text_printf(ent_id.c_str(), "%s", ent_value.c_str());
if (strcmp(ent_value_xcen.c_str(), "0") != 0) id(disp1).send_command_printf("%s", entxcen.c_str());
##### Service for transferring global settings from the blueprint to ESPHome #####
- service: global_settings
variables:
blueprint_version: string
relay1_local_control: bool
relay1_icon: string
relay1_icon_color: int
relay1_fallback: bool
relay2_local_control: bool
relay2_icon: string
relay2_icon_color: int
relay2_fallback: bool
date_color: int
time_format: string
time_color: int
embedded_climate: bool
embedded_indoor_temperature: bool
temperature_unit_is_fahrenheit: bool
mui_please_confirm: string
then:
- lambda: |-
// Blueprint version
id(version_blueprint) = blueprint_version;
id(check_versions).execute();
// Relays
id(relay1_local).publish_state(relay1_local_control);
id(relay2_local).publish_state(relay2_local_control);
id(home_relay1_icon) = relay1_icon.c_str();
id(home_relay2_icon) = relay2_icon.c_str();
id(home_relay1_icon_color) = relay1_icon_color;
id(home_relay2_icon_color) = relay2_icon_color;
id(relay_1_fallback) = relay1_fallback;
id(relay_2_fallback) = relay2_fallback;
// Localization
id(mui_time_format) = time_format;
// Date/Time colors
id(home_date_color) = date_color;
id(home_time_color) = time_color;
// Embedded thermostat
id(is_embedded_thermostat) = embedded_climate;
// Indoor temperature
id(embedded_indoor_temp) = embedded_indoor_temperature;
id(temp_unit_fahrenheit) = temperature_unit_is_fahrenheit;
id(display_embedded_temp).execute();
// Confirm page
id(display_wrapped_text).execute("confirm.title", mui_please_confirm.c_str(), 15);
// Refresh colors of global components
id(disp1).set_component_font_color("home.date", id(home_date_color));
id(disp1).set_component_font_color("home.time", id(home_time_color));
id(disp1).set_component_font_color("home.icon_top_01", id(home_relay1_icon_color));
id(disp1).set_component_font_color("home.icon_top_02", id(home_relay2_icon_color));
// Update home page
id(update_page_home).execute();
- if:
condition:
- text_sensor.state: # Is boot page visible?
id: current_page
state: 'boot'
then:
- lambda: |-
id(disp1).set_component_text_printf("boot.bluep_version", "%s", blueprint_version.c_str());
- wait_until:
condition:
- not:
- text_sensor.state: # Is boot page visible?
id: current_page
state: 'boot'
timeout: 2s
- if:
condition:
- text_sensor.state: # Avoid this being called twice by multiple boot triggers
id: current_page
state: 'boot'
then:
- if:
condition:
switch.is_on: notification_sound
then:
- rtttl.play:
rtttl: 'two short:d=4,o=5,b=100:16e6,16e6'
- lambda: |-
ESP_LOGD("service.global_settings", "Jump to wake-up page: %s", id(wakeup_page_name).state.c_str());
id(disp1).goto_page(id(wakeup_page_name).state.c_str());
id(timer_reset_all).execute(id(wakeup_page_name).state.c_str());
#### Service to populate the page Home #####
- service: page_home
variables:
notification_icon: string
notification_icon_color_normal: int[]
notification_icon_color_unread: int[]
qrcode: bool
qrcode_icon: string
qrcode_icon_color: int[]
entities_pages: bool
entities_pages_icon: string
entities_pages_icon_color: int[]
alarm_state: string
then:
- lambda: |-
// Notification button
id(disp1).send_command_printf("is_notification=%i", (id(notification_text).state.empty() and id(notification_label).state.empty()) ? 0 : 1);
id(disp1).set_component_text_printf("home.bt_notific", "%s", notification_icon.c_str());
id(set_component_color).execute("home.bt_notific", id(notification_unread).state ? notification_icon_color_unread : notification_icon_color_normal, {});
id(home_notify_icon_color_normal) = notification_icon_color_normal;
id(home_notify_icon_color_unread) = notification_icon_color_unread;
// QRCode button
id(disp1).send_command_printf("is_qrcode=%i", (qrcode) ? 1 : 0);
id(disp1).set_component_text_printf("home.bt_qrcode", "%s", qrcode_icon.c_str());
id(set_component_color).execute("home.bt_qrcode", qrcode_icon_color, {});
// Entities pages button
id(disp1).send_command_printf("is_entities=%i", (entities_pages) ? 1 : 0);
id(disp1).set_component_text_printf("home.bt_entities", "%s", entities_pages_icon.c_str());
id(set_component_color).execute("home.bt_entities", entities_pages_icon_color, {});
// Alarm button
id(disp1).send_command_printf("is_alarm=%i", (alarm_state=="" or alarm_state.empty()) ? 0 : 1);
id(update_alarm_icon).execute("home.bt_alarm", alarm_state.c_str());
#### Service to populate the page Settings #####
- service: page_settings
variables:
reboot: string
#sleep_mode: string
brightness: string
bright: string
dim: string
then:
- lambda: |-
if (not reboot.empty()) id(disp1).set_component_text_printf("settings.lbl_reboot", " %s", reboot.c_str());
id(disp1).set_component_text_printf("settings.lbl_brightness", " %s", brightness.c_str());
id(display_wrapped_text).execute("settings.lbl_bright", bright.c_str(), id(display_mode) == 2 ? 25 : 10);
id(display_wrapped_text).execute("settings.lbl_dim", dim.c_str(), id(display_mode) == 2 ? 25 : 10);
#### Service to populate the alarm settings page #####
- service: alarm_settings
variables:
page_title: string
state: string
supported_features: int
code_format: string
code_arm_required: bool
entity: string
mui_alarm: string[] #std::vector<std::string> #std::map
then:
- lambda: |-
// set alarm icon on home page
id(disp1).send_command_printf("is_alarm=%i", (state=="" or state.empty()) ? 0 : 1);
id(update_alarm_icon).execute("home.bt_alarm", state.c_str());
// Is page Alarm visible?
if (id(current_page).state=="alarm")
{ // Update alarm page
id(entity_id) = entity;
// Alarm page - Header
id(update_alarm_icon).execute("icon_state", state.c_str());
id(disp1).set_component_text_printf("page_label", "%s", page_title.c_str());
id(disp1).set_component_text_printf("code_format", "%s", code_format.c_str());
if (code_arm_required) id(disp1).set_component_text_printf("code_arm_req", "1"); else id(disp1).set_component_text_printf("code_arm_req", "0");
// Alarm page - Button's icons
id(disp1).set_component_text_printf("bt_home_icon", "\uE689"); //mdi:shield-home
id(disp1).set_component_text_printf("bt_away_icon", "\uE99C"); //mdi:shield-lock
id(disp1).set_component_text_printf("bt_night_icon", "\uF827"); //mdi:shield-moon
id(disp1).set_component_text_printf("bt_vacat_icon", "\uE6BA"); //mdi:shield-airplane
id(disp1).set_component_text_printf("bt_bypass_icon", "\uE77F"); //mdi:shield-half-full
id(disp1).set_component_text_printf("bt_disarm_icon", "\uE99D"); //mdi:shield-off
// Alarm page - Button's text
id(display_wrapped_text).execute("bt_home_text", mui_alarm[0].c_str(), 10);
id(display_wrapped_text).execute("bt_away_text", mui_alarm[1].c_str(), 10);
id(display_wrapped_text).execute("bt_night_text", mui_alarm[2].c_str(), 10);
id(display_wrapped_text).execute("bt_vacat_text", mui_alarm[3].c_str(), 10);
id(display_wrapped_text).execute("bt_bypass_text", mui_alarm[4].c_str(), 10);
id(display_wrapped_text).execute("bt_disarm_text", mui_alarm[5].c_str(), 10);
// Alarm page - Buttons
if (supported_features & 1) // Alarm - Button - Home
{
id(disp1).send_command_printf("bt_home_pic.pic=%i", (state=="armed_home") ? 43 : 42);
id(disp1).set_component_background_color("bt_home_text", (state=="armed_home") ? 19818 : 52857);
id(disp1).set_component_background_color("bt_home_icon", (state=="armed_home") ? 19818 : 52857);
id(disp1).set_component_font_color("bt_home_text", (state=="armed_home") ? 65535 : 0);
id(disp1).set_component_font_color("bt_home_icon", (state=="armed_home") ? 65535 : 0);
if (state=="armed_home") id(disp1).hide_component("bt_home"); else id(disp1).show_component("bt_home");
}
if (supported_features & 2) // Alarm - Button - Away
{
id(disp1).send_command_printf("bt_away_pic.pic=%i", (state=="armed_away") ? 43 : 42);
id(disp1).set_component_background_color("bt_away_text", (state=="armed_away") ? 19818 : 52857);
id(disp1).set_component_background_color("bt_away_icon", (state=="armed_away") ? 19818 : 52857);
id(disp1).set_component_font_color("bt_away_text", (state=="armed_away") ? 65535 : 0);
id(disp1).set_component_font_color("bt_away_icon", (state=="armed_away") ? 65535 : 0);
if (state=="armed_away") id(disp1).hide_component("bt_away"); else id(disp1).show_component("bt_away");
}
if (supported_features & 4) // Alarm - Button - Night
{
id(disp1).send_command_printf("bt_night_pic.pic=%i", (state=="armed_night") ? 43 : 42);
id(disp1).set_component_background_color("bt_night_text", (state=="armed_night") ? 19818 : 52857);
id(disp1).set_component_background_color("bt_night_icon", (state=="armed_night") ? 19818 : 52857);
id(disp1).set_component_font_color("bt_night_text", (state=="armed_night") ? 65535 : 0);
id(disp1).set_component_font_color("bt_night_icon", (state=="armed_night") ? 65535 : 0);
if (state=="armed_night") id(disp1).hide_component("bt_night"); else id(disp1).show_component("bt_night");
}
if (supported_features & 32) // Alarm - Button - Vacation
{
id(disp1).send_command_printf("bt_vacat_pic.pic=%i", (state=="armed_vacation") ? 43 : 42);
id(disp1).set_component_background_color("bt_vacat_text", (state=="armed_vacation") ? 19818 : 52857);
id(disp1).set_component_background_color("bt_vacat_icon", (state=="armed_vacation") ? 19818 : 52857);
id(disp1).set_component_font_color("bt_vacat_text", (state=="armed_vacation") ? 65535 : 0);
id(disp1).set_component_font_color("bt_vacat_icon", (state=="armed_vacation") ? 65535 : 0);
if (state=="armed_vacation") id(disp1).hide_component("bt_vacat"); else id(disp1).show_component("bt_vacat");
}
if (supported_features & 16) // Alarm - Button - Custom bypass
{
id(disp1).send_command_printf("bt_bypass_pic.pic=%i", (state=="armed_bypass") ? 43 : 42);
id(disp1).set_component_background_color("bt_bypass_text", (state=="armed_bypass") ? 19818 : 52857);
id(disp1).set_component_background_color("bt_bypass_icon", (state=="armed_bypass") ? 19818 : 52857);
id(disp1).set_component_font_color("bt_bypass_text", (state=="armed_bypass") ? 65535 : 0);
id(disp1).set_component_font_color("bt_bypass_icon", (state=="armed_bypass") ? 65535 : 0);
if (state=="armed_bypass") id(disp1).hide_component("bt_bypass"); else id(disp1).show_component("bt_bypass");
}
if ( true ) // Alarm - Button - Disarm
{
id(disp1).send_command_printf("bt_disarm_pic.pic=%i", (state=="disarmed") ? 43 : 42);
id(disp1).set_component_background_color("bt_disarm_text", (state=="disarmed") ? 19818 : 52857);
id(disp1).set_component_background_color("bt_disarm_icon", (state=="disarmed") ? 19818 : 52857);
id(disp1).set_component_font_color("bt_disarm_text", (state=="disarmed") ? 65535 : 0);
id(disp1).set_component_font_color("bt_disarm_icon", (state=="disarmed") ? 65535 : 0);
if (state=="disarmed") id(disp1).hide_component("bt_disarm"); else id(disp1).show_component("bt_disarm");
}
}
#### Service to populate the media player page #####
- service: media_player
variables:
entity: string
state: string
is_volume_muted: bool
friendly_name: string
volume_level: int
media_title: string
media_artist: string
media_duration: float
media_position: float
media_position_delta: float
supported_features: int
then:
- lambda: |-
if (id(current_page).state == "media_player")
{
id(entity_id) = entity;
id(disp1).set_component_text_printf("page_label", "%s", friendly_name.c_str());
id(display_wrapped_text).execute("track", media_title.c_str(), id(display_mode) == 2 ? 16 : 27);
id(display_wrapped_text).execute("artist", media_artist.c_str(), id(display_mode) == 2 ? 26 : 40);
// on/off button
if (supported_features & 128 and state == "off") //TURN_ON
{
id(set_component_color).execute("bt_on_off", { 65535 }, {} );
id(disp1).show_component("bt_on_off");
}
else if (supported_features & 256 and state != "off") //TURN_OFF
{
id(set_component_color).execute("bt_on_off", { 10597 }, {} );
id(disp1).show_component("bt_on_off");
}
else id(disp1).hide_component("bt_on_off");
// play/pause button
if ((supported_features & 512 or supported_features & 16384) and state != "playing" and state != "off") //PLAY_MEDIA+PLAY
{
id(disp1).set_component_text_printf("bt_play_pause", "%s", "\uE409"); // mdi:play
id(disp1).show_component("bt_play_pause");
}
else if (supported_features & 1 and state == "playing" ) //PAUSE
{
id(disp1).set_component_text_printf("bt_play_pause", "%s", "\uE3E3"); // mdi:pause
id(disp1).show_component("bt_play_pause");
}
else id(disp1).hide_component("bt_play_pause");
// bt_prev button - PREVIOUS_TRACK
if (supported_features & 16 and state != "off") id(disp1).show_component("bt_prev"); else id(disp1).hide_component("bt_prev");
// bt_next button - NEXT_TRACK
if (supported_features & 32 and state != "off") id(disp1).show_component("bt_next"); else id(disp1).hide_component("bt_next");
// Stop button - STOP
//if (supported_features & 4096 and (state == "playing" or state == "paused")) id(disp1).show_component("bt_stop"); else id(disp1).hide_component("bt_stop");
// mute/unmute button - VOLUME_MUTE
id(disp1).set_component_value("is_muted", (is_volume_muted) ? 1 : 0);
if (supported_features & 8 and is_volume_muted) // unmute
{
id(disp1).set_component_text_printf("bt_mute", "%s", "\uEE07"); // mdi:volume-variant-off
id(disp1).show_component("bt_mute");
}
else if (supported_features & 8) // mute
{
id(disp1).set_component_text_printf("bt_mute", "%s", "\uE57E"); // mdi:volume-low
id(disp1).show_component("bt_mute");
}
else id(disp1).hide_component("bt_mute");
// VOLUME_SET
if (supported_features & 4)
{
if (volume_level != id(last_volume_level))
{
id(last_volume_level) = volume_level;
id(disp1).set_component_text_printf("vol_text", "%i%%", volume_level);
id(disp1).set_component_value("vol_slider", volume_level);
}
id(disp1).show_component("vol_slider");
id(disp1).show_component("bt_vol_down");
id(disp1).show_component("bt_vol_up");
id(disp1).show_component("vol_text");
}
else
{
id(disp1).hide_component("vol_slider");
id(disp1).hide_component("bt_vol_down");
id(disp1).hide_component("bt_vol_up");
id(disp1).hide_component("vol_text");
}
if (media_duration > 0)
{
if (media_duration != id(last_media_duration) or media_position != id(last_media_position))
{
id(last_media_duration) = media_duration;
id(last_media_position) = media_position;
id(disp1).set_component_value("prg_current", int(round(min(media_position + media_position_delta, media_duration))));
}
id(disp1).set_component_value("prg_total", int(round(media_duration)));
id(disp1).send_command_printf("prg_timer.en=%i", (state == "playing") ? 1 : 0);
id(disp1).show_component("time_current");
id(disp1).show_component("time_total");
id(disp1).show_component("time_progress");
}
else
{
id(disp1).send_command_printf("prg_timer.en=0");
id(disp1).hide_component("time_current");
id(disp1).hide_component("time_total");
id(disp1).hide_component("time_progress");
}
}
##### START - GLOBALS CONFIGURATION #####
globals:
###### Last volume level from Home Assistant ######
- id: last_volume_level
type: int
restore_value: false
initial_value: '-1'
###### Last duration from Home Assistant ######
- id: last_media_duration
type: int
restore_value: false
initial_value: '-1'
###### Last duration from Home Assistant ######
- id: last_media_position
type: int
restore_value: false
initial_value: '-1'
###### Relay fallback even when buttons have other entities? ######
- id: relay_1_fallback
type: bool
restore_value: true
initial_value: 'false'
- id: relay_2_fallback
type: bool
restore_value: true
initial_value: 'false'
##### Display mode (1 = EU, 2 = US, 3 = US Landscape)
- id: display_mode
type: int
restore_value: true
initial_value: '0'
##### Is dimmed #####
- id: is_dim_brightness
type: bool
restore_value: false
initial_value: 'false'
##### Entity Id of the entity displayed on the detailed pages
- id: entity_id
type: std::string
restore_value: no
initial_value: ''
##### Is embedded thermostat set as main climate entity? #####
- id: is_embedded_thermostat
type: bool
restore_value: true
initial_value: 'false'
##### Save Display Brightness for NSPanel reboot #####
- id: display_brightness_global
type: int
restore_value: true
initial_value: '100'
##### Save Display DIM Brightness for NSPanel reboot
- id: display_dim_brightness_global
type: int
restore_value: true
initial_value: '10'
##### Temperature unit #####
##### Is embedded sensor used for indoor temperature? #####
- id: embedded_indoor_temp
type: bool
restore_value: true
initial_value: 'false'
- id: temp_unit_fahrenheit
type: bool
restore_value: true
initial_value: 'false'
##### Date/time formats #####
#- id: mui_date_format
# type: std::string
# restore_value: no
# initial_value: '"%A, %d.%m"'
- id: home_date_color
type: int
restore_value: true
initial_value: '65535'
- id: mui_time_format
type: std::string
restore_value: no
initial_value: '"%H:%M"'
- id: home_time_color
type: int
restore_value: true
initial_value: '65535'
##### Relay icons #####
- id: home_relay1_icon
type: std::string
restore_value: false
initial_value: ''
- id: home_relay1_icon_color
type: int
restore_value: true
initial_value: '65535'
- id: home_relay2_icon
type: std::string
restore_value: false
initial_value: ''
- id: home_relay2_icon_color
type: int
restore_value: true
initial_value: '65535'
- id: home_notify_icon_color_normal
type: std::vector<int>
restore_value: false
- id: home_notify_icon_color_unread
type: std::vector<int>
restore_value: false
##### Versions #####
- id: version_blueprint
type: std::string
restore_value: false
initial_value: ''
- id: version_tft
type: std::string
restore_value: false
initial_value: ''
##### START - BINARY SENSOR CONFIGURATION #####
binary_sensor:
###### LEFT BUTTON BELOW DISPLAY TO TOGGLE RELAY#####
- name: ${device_name} Left Button
platform: gpio
id: left_button
pin:
number: 14
inverted: true
on_multi_click:
- timing: &long_click-timing
- ON for at least 0.8s
then:
- logger.log: "Left button - Long click"
- script.execute:
id: ha_button
page: !lambda return id(current_page).state;
component: "hw_bt_left"
command: "long_click"
- timing: &short_click-timing
- ON for at most 0.8s
then:
- logger.log: "Left button - Short click"
- if:
condition:
or:
- switch.is_on: relay1_local
- and:
- lambda: !lambda return id(relay_1_fallback);
- or:
- not:
- api.connected:
- not:
- wifi.connected:
then:
- switch.toggle: relay_1
- script.execute:
id: ha_button
page: !lambda return id(current_page).state;
component: "hw_bt_left"
command: "short_click"
##### RIGHT BUTTON BELOW DISPLAY TO TOGGLE RELAY #####
- name: ${device_name} Right Button
platform: gpio
id: right_button
pin:
number: 27
inverted: true
on_multi_click:
- timing: *long_click-timing
then:
- logger.log: "Right button - Long click"
- script.execute:
id: ha_button
page: !lambda return id(current_page).state;
component: "hw_bt_right"
command: "long_click"
- timing: *short_click-timing
then:
- logger.log: "Right button - Short click"
- if:
condition:
or:
- switch.is_on: relay2_local
- and:
- lambda: !lambda return id(relay_2_fallback);
- or:
- not:
- api.connected:
- not:
- wifi.connected:
then:
- switch.toggle: relay_2
- script.execute:
id: ha_button
page: !lambda return id(current_page).state;
component: "hw_bt_right"
command: "short_click"
##### Restart NSPanel Button - Setting Page #####
- name: ${device_name} Restart
platform: nextion
page_id: 7
component_id: 9
internal: true
on_click:
- button.press: restart_nspanel
##### Restart NSPanel Button - Boot Page #####
- name: ${device_name} Restart
platform: nextion
page_id: 8
component_id: 4
internal: true
on_click:
- button.press: restart_nspanel
## Delays initial info from HA to the display #####
- name: ${device_name} Nextion display
id: nextion_init
platform: template
device_class: connectivity
publish_initial_state: true
entity_category: diagnostic
icon: mdi:tablet-dashboard
##### API connection status
- name: ${device_name} Status
platform: status
id: api_status
on_state:
then:
- script.execute:
id: refresh_wifi_icon
##### START - SENSOR CONFIGURATION #####
sensor:
##### touchevent sensor, Reset the page timeout #####
- id: touchevent
platform: nextion
nextion_id: disp1