forked from Blackymas/NSPanel_HA_Blueprint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nspanel_esphome.yaml
939 lines (855 loc) · 30.6 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
#####################################################################################################
##### 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. #####
#####################################################################################################
##### ADVANCED CONFIGURATION - activate only when you know what you do ##############################
substitutions:
baud_rate: "115200" # requires 115200 if tft is installed but can be changed to 9600 if tft upload fails and nextion switches to 9600
# ## usage of secrets-file ## -> comment in ###### Change ME ######
# device_name: "nspanel-name" # Wird im Blueprint benötigt!
# wifi_ssid: !secret nspanel_wifi_ssid # add in your esphome secrets file.
# wifi_password: !secret nspanel_wifi_password # add in your esphome secrets file. -> per default this is also used for ota_password and web_password
# ota_password: !secret nspanel_ota_password # add in your esphome secrets file. - manual change in code required to activate
# web_password: !secret nspanel_web_password # add in your esphome secrets file. - manual change in code required to activate
# api_password: !secret nspanel_api_password # add in your esphome secrets file. - manual change in code required to activate
# nextion_update_url: !secret nspanel_update_url # add in your esphome secrets file. Example: "http://"HOME ASSISTANT IP":8123/local/nspanel/nspanel.tft"
# ## static ip config ##
# ip: "10.0.0.7"
# gw: "10.0.0.138"
# subnet: "255.255.255.0"
# dns: "10.0.0.138"
# domain: ".local"
###### USE THIS ONLY FOR YOUR FIRST TFT UPLOAD
###### AND IF EXIT-REPARSE BUTTON FAILS
###### ONCE IT WORKED, REMOVE THESE LINES
###### https://github.com/esphome/esphome/pull/2956
# external_components:
# - source: github://pr#2956
# components: [nextion]
# refresh: 1h
##################################################
##### if you rename this file to .nspanel_esphome.yaml then you can activate nested config
##### use the ADVANCED CONFIG-Section as device configuration
##### https://esphome.io/guides/configuration-types.html#yaml-insertion-operator
# <<: !include .nspanel_esphome.yaml
##### END OF ADVANCED CONFIGURATION ##############################################################
##### WIFI SETUP #####
wifi:
ssid: ${wifi_ssid}
password: ${wifi_password}
power_save_mode: none
##### advanced config - uncomment to use static IP-Config #####
# manual_ip:
# static_ip: ${ip}
# gateway: ${gw}
# subnet: ${subnet}
# dns1: ${dns}
# domain: ${domain}
##### Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${device_name}"
password: ${wifi_password}
##### ESPHOME CONFIGURATION #####
esphome:
name: ${device_name}
min_version: 2022.10.2
##### TYPE OF ESP BOARD #####
esp32:
board: esp32dev
captive_portal:
web_server:
port: 80
auth:
username: admin
password: ${wifi_password}
##### advanced config - change to use web_password #####
# password: ${web_password}
##### OTA PASSWORD #####
ota:
password: ${wifi_password}
##### advanced config - change to use ota_password #####
# password: ${ota_password}
safe_mode: true
reboot_timeout: 3min
num_attempts: 3
##### LOGGER #####
logger:
baud_rate: 0
# level: WARN
##### CONFIGURE INTERNAL BUZZER #####
output:
##### BUZZER FOR PLAYING RINGTONES #####
- platform: ledc
id: buzzer_out
pin:
number: 21
##### ENABLE RINGTONE MUSIC SUPPORT #####
rtttl:
id: buzzer
output: buzzer_out
##### UART FOR NEXTION DISPLAY #####
uart:
tx_pin: 16
rx_pin: 17
baud_rate: ${baud_rate}
id: tf_uart
# debug:
# direction: BOTH
# dummy_receiver: false
# after:
# delimiter: "\n"
# sequence:
# - lambda: UARTDebug::log_string(direction, bytes);
##### 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:
- 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:
- uart.write:
id: tf_uart
data: "DRAKJHSUYDGBNCJHGJKSHBDN"
- uart.write:
id: tf_uart
data: [0xFF, 0xFF, 0xFF]
##### START - API CONFIGURATION #####
api:
##### advanced config - activate to use api_password #####
# password: ${api_password}
services:
##### SERVICE TO UPDATE THE HMI FILE ##############
- service: upload_tft
then:
- 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:
- 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:
- wait_until:
binary_sensor.is_on: nextion_init
- 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:
- wait_until:
binary_sensor.is_on: nextion_init
- 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:
- wait_until:
binary_sensor.is_on: nextion_init
- 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:
- wait_until:
binary_sensor.is_on: nextion_init
- 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:
- wait_until:
binary_sensor.is_on: nextion_init
- lambda: 'id(disp1).show_component("255");'
##### Service to send a command "font color" directly to the display #####
- service: send_command_font_color
variables:
component: string
message: int
then:
- wait_until:
binary_sensor.is_on: nextion_init
- lambda: 'id(disp1).set_component_font_color(component.c_str(), message);'
##### Service to send a command "background color" directly to the display #####
- service: send_command_background_color
variables:
component: string
message: int
then:
- wait_until:
binary_sensor.is_on: nextion_init
- lambda: 'id(disp1).set_component_background_color(component.c_str(), message);'
##### Service to show a notification-message on the screen #####
- service: notification_show
variables:
label: string
text: string
then:
- wait_until:
binary_sensor.is_on: nextion_init
- lambda: |-
id(disp1).send_command_printf("page notification");
id(disp1).set_component_text_printf("notification.notifi_label", "%s", label.c_str());
id(disp1).set_component_text_printf("notification.notifi_text01", "%s", text.c_str());
id(notification_label).publish_state(label.c_str());
id(notification_text).publish_state(text.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:
- wait_until:
binary_sensor.is_on: nextion_init
- lambda: |-
id(notification_label).publish_state("");
id(notification_text).publish_state("");
- switch.turn_off: notification_unread
##### Service to set entity-information for settings-page(s)
- service: set_settings_entity
variables:
entity: string
then:
- wait_until:
binary_sensor.is_on: nextion_init
- lambda: |-
id(settings_entity).publish_state(entity.c_str());
##### 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: qr_code
variables:
qrdata: string
then:
- wait_until:
binary_sensor.is_on: nextion_init
- lambda: |-
id(disp1).send_command_printf("page qrcode");
id(disp1).set_component_text_printf("qrcode.qrcode_value", "%s", qrdata.c_str());
#### Service to send thermostat cycle state ####
- service: send_thermostat_cycle_state
variables:
value: float
then:
- wait_until:
binary_sensor.is_on: nextion_init
- lambda: |-
//ESP_LOGD("nextion", "thermostat sendig value %f", value);
int v = int(2 * std::min(std::max(value - 13.5, 0.0), 5.0));
int left = v + (v ? 19 : 16); // 16 is empty left.
v = int(2 * std::min(std::max(value - 18.0, 0.0), 4.0));
int mid = v + (v ? 29 : 17); // 17 is empty mid.
v = int(2 * std::min(std::max(value - 21.5, 0.0), 5.5));
int right = v + (v ? 37 : 18); // 18 is empty right.
// sends the 3 images to the display
//ESP_LOGD("nextion", "thermostat left %i", left);
//ESP_LOGD("nextion", "thermostat mid %i", mid);
//ESP_LOGD("nextion", "thermostat right %i", right);
id(disp1).send_command_printf("climate_left.pic=%i", left);
id(disp1).send_command_printf("climate_middle.pic=%i", mid);
id(disp1).send_command_printf("climate_right.pic=%i", right);
// send target-temp
id(disp1).set_component_text_printf("target_temp", "%.1f°", value);
id(display_target_temp).publish_state(value);
#### 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:
- wait_until:
binary_sensor.is_on: nextion_init
- lambda: |-
// ESP_LOGD("nextion", "set button %s", btn_id.c_str());
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(disp1).set_component_background_color(btnicon.c_str(), btn_bg);
id(disp1).set_component_background_color(btntext.c_str(), btn_bg);
id(disp1).set_component_background_color(btnbri.c_str(), btn_bg);
id(disp1).set_component_font_color(btnicon.c_str(), btn_icon_font);
id(disp1).set_component_font_color(btntext.c_str(), btn_txt_font);
id(disp1).set_component_font_color(btnbri.c_str(), btn_bri_font);
id(disp1).set_component_text_printf(btnicon.c_str(), "%s", btn_icon.c_str());
id(disp1).set_component_text_printf(btntext.c_str(), "%s", btn_label.c_str());
// id(disp1).set_component_text_printf(btnbri.c_str(), "%s", btn_bri_txt.c_str());
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_display
variables:
option: string
then:
- lambda: |-
DynamicJsonDocument doc(1024);
deserializeJson(doc, id(disp1_nspanel_event).state);
std::string page = doc["page"];
if (page == "screensaver") {
id(disp1).send_command_printf("page home");
} else {
if (page == "home"){
id(disp1).send_command_printf("dim=brightness.val");
}
}
- if:
condition:
- lambda: 'return option == "keep_wake";'
then:
- lambda: id(disp1).send_command_printf("home.dimtimer.en=1");
- lambda: id(disp1).send_command_printf("home.sleeptimer.en=1");
- if:
condition:
- lambda: 'return option == "keep_page";'
then:
- lambda: id(disp1).send_command_printf("home.dimtimer.en=1");
- lambda: id(disp1).send_command_printf("home.sleeptimer.en=1");
- lambda: |-
id(page_timer)->execute(int(id(page_timeout).state));
#### Service to set the entities ####
- service: set_entity
variables:
ent_id: string
ent_icon: string
ent_label: string
ent_value: string
then:
- wait_until:
binary_sensor.is_on: nextion_init
- lambda: |-
// ESP_LOGD("nextion", "set entity %s", ent_id.c_str());
std::string enticon = ent_id.c_str() + std::string("_pic");
std::string entlabel = ent_id.c_str() + std::string("_label");
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());
##### START - GLOBALS CONFIGURATION #####
globals:
##### 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 Correction #####
- id: temperature_correction_global
type: float
restore_value: true
initial_value: '0.0'
##### 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_click:
then:
- if:
condition:
and:
- switch.is_on: relay1_fallback
- not:
api.connected:
then:
- switch.toggle: relay_1
- if:
condition:
switch.is_on: relay_1
then:
- lambda: id(disp1).send_command_printf("home.left_bt_pic.pic=78");
- lambda: id(disp1).send_command_printf("home.icon_top_01","\U0000E3A5");
else:
- lambda: id(disp1).send_command_printf("home.left_bt_pic.pic=77");
- lambda: id(disp1).send_command_printf("home.icon_top_01","\U0000FFFF");
##### RIGHT BUTTON BELOW DISPLAY TO TOGGLE RELAY #####
- name: ${device_name} Right Button
platform: gpio
id: right_button
pin:
number: 27
inverted: true
on_click:
then:
- if:
condition:
and:
- switch.is_on: relay2_fallback
- not:
api.connected:
then:
- switch.toggle: relay_2
- if:
condition:
switch.is_on: relay_2
then:
- lambda: id(disp1).send_command_printf("home.right_bt_pic.pic=78");
- lambda: id(disp1).send_command_printf("home.icon_top_02","\U0000E3A8");
else:
- lambda: id(disp1).send_command_printf("home.right_bt_pic.pic=77");
- lambda: id(disp1).send_command_printf("home.icon_top_02","\U0000FFFF");
##### JUMP PAGE TO SETTING PAGE #####
- name: $device_name setting page
platform: nextion
page_id: 0
component_id: 52
internal: true
on_multi_click:
- timing:
- ON for at least 1s #LONG Press
then:
- lambda: 'id(disp1).send_command_printf("page settings");'
##### Restart NSPanel Button - Setting Page #####
- name: ${device_name} Restart
platform: nextion
page_id: 7
component_id: 13
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
##### Sleep mode NSPanel Button #####
- name: ${device_name} Sleep mode
platform: nextion
page_id: 7
component_id: 14
internal: true
on_click:
- logger.log: "Sleep mode - Nextion toggle"
- switch.toggle: sleep_mode
##### global variable to keep track on whether the Nextion display is ready or not.
## 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
##### START - SENSOR CONFIGURATION #####
sensor:
##### Uptime #####
- name: ${device_name} uptime
platform: uptime
disabled_by_default: true
##### WIFI Signal stregth
- name: ${device_name} RSSI
platform: wifi_signal
update_interval: 60s
on_value:
- if:
condition:
wifi.connected:
then:
- lambda: id(disp1).set_component_text_printf("home.wifi_icon", "%s", "\U0000E5A8");
else:
- lambda: id(disp1).set_component_text_printf("home.wifi_icon", "%s", "\U0000FFFF");
##### INTERNAL TEMPERATURE SENSOR, ADC VALUE #####
- id: ntc_source
platform: adc
pin: 38
update_interval: 60s
attenuation: 11db
##### INTERNAL TEMPERATURE SENSOR, adc reading converted to resistance (calculation)#####
- id: resistance_sensor
platform: resistance
sensor: ntc_source
configuration: DOWNSTREAM
resistor: 11.2kOhm
##### INTERNAL TEMPERATURE SENSOR, resistance to temperature (calculation) #####
- name: ${device_name} Temperature
platform: ntc
id: temp_nspanel
sensor: resistance_sensor
calibration:
b_constant: 3950
reference_temperature: 25°C
reference_resistance: 10kOhm
filters:
- lambda: return x + id(temperature_correction_global);
#on_value:
# then:
# - wait_until:
# binary_sensor.is_on: nextion_init
# - lambda: id(disp1).set_component_text_printf("home.current_temp", "%.1f°", id(temp_nspanel).state); # onboard temp (thermostat temp) to home page.
# - lambda: id(disp1).set_component_text_printf("climate.current_temp", "%.1f", id(temp_nspanel).state);
##### current value of page-climate target_temp #####
- name: ${device_name} Display Target Temperature
platform: template
id: display_target_temp
lambda: return {};
update_interval: 10s
###### Display Brightness GET VALUE FROM NSPanel SLIDER #####
- name: ${device_name} brightness Slider
platform: nextion
id: brightslider
variable_name: brightslider
internal: true
on_value:
then:
- wait_until:
binary_sensor.is_on: nextion_init
- number.set:
id: display_brightness
value: !lambda 'return int(x);'
# send text field percentage of current_lightslider_val
- lambda: id(disp1).set_component_text_printf("settings.a03", "%i", id(display_brightness_global));
###### Display DIM Brightness GET VALUE FROM NSPanel SLIDER #####
- name: ${device_name} dim brightness slider
platform: nextion
id: dimslider
variable_name: dimslider
internal: true
on_value:
then:
- wait_until:
binary_sensor.is_on: nextion_init
- number.set:
id: display_dim_brightness
value: !lambda 'return int(x);'
# send text field percentage of current_lightslider_val
- lambda: id(disp1).set_component_text_printf("settings.a04", "%i", id(display_dim_brightness_global));
##### START - TEXT SENSOR CONFIGURATION #####
text_sensor:
##### ESPhome version used to compile the app #####
- platform: version
name: ${device_name} ESPhome Version
disabled_by_default: true
- platform: wifi_info
ip_address:
name: ${device_name} IP
disabled_by_default: true
id: ip_address
ssid:
name: ${device_name} SSID
disabled_by_default: true
bssid:
name: ${device_name} BSSID
disabled_by_default: true
- name: ${device_name} Notification Label
platform: template
id: notification_label
- name: ${device_name} Notification Text
platform: template
id: notification_text
- name: ${device_name} Settings Entity
platform: template
id: settings_entity
##### NSPanel event sensor, the main action sensor - push to HA #####
- name: ${device_name} NSPanel event
platform: nextion
nextion_id: disp1
id: disp1_nspanel_event
component_name: nspanelevent
internal: false
filters:
- lambda: |-
x = x.c_str();
x.shrink_to_fit();
return x;
on_value:
then:
- lambda: |-
id(page_timer)->execute(int(id(page_timeout).state));
##### touchevent sensor, Reset the page timeout #####
- id: disp1_touchevent
platform: nextion
nextion_id: disp1
#name: ${device_name} touchevent
component_name: touchevent
internal: true
filters:
- lambda: |-
x = x.c_str();
x.shrink_to_fit();
return x;
on_value:
then:
- lambda: |-
id(page_timer)->execute(int(id(page_timeout).state));
##### START - SWITCH CONFIGURATION #####
switch:
##### Notification unread #####
- name: ${device_name} Notification unread
platform: template
id: notification_unread
entity_category: config
restore_state: true
optimistic: true
##### Notification sound #####
- name: ${device_name} Notification sound
platform: template
id: notification_sound
entity_category: config
restore_state: true
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
##### Confirmation Message #####
- name: ${device_name} Confirmation Message
platform: template
id: confirmation_message
entity_category: config
restore_state: false
optimistic: true
##### PHYSICAL SWITCH 1 #####
- name: ${device_name} Relay 1
platform: gpio
id: relay_1
pin:
number: 22
restore_mode: RESTORE_DEFAULT_OFF
##### PHYSICAL SWITCH 2 ######
- name: ${device_name} Relay 2
platform: gpio
id: relay_2
pin:
number: 19
restore_mode: RESTORE_DEFAULT_OFF
##### DISPLAY ALWAYS ON #####
- name: ${device_name} Screen Power
platform: gpio
id: screen_power
entity_category: config
pin:
number: 4
inverted: true
restore_mode: ALWAYS_ON
internal: true
##### Switch Display Sleep mode #####
- name: ${device_name} Sleep mode
platform: template
device_class: switch
id: sleep_mode
entity_category: config
restore_mode: RESTORE_DEFAULT_OFF
restore_state: true
optimistic: false
turn_on_action: &sleep_mode-turn_on
- logger.log: "Sleep mode - Turn on"
- lambda: id(disp1).send_command_printf("home.sleepmodus.val=1");
- lambda: id(disp1).set_component_value("settings.bt1",1);
- switch.template.publish:
id: sleep_mode
state: ON
turn_off_action: &sleep_mode-turn_off
- logger.log: "Sleep mode - Turn off"
- lambda: id(disp1).send_command_printf("home.sleepmodus.val=0");
- lambda: id(disp1).set_component_value("settings.bt1",0);
- switch.template.publish:
id: sleep_mode
state: OFF
##### Relay Local control Fallback #####
- name: ${device_name} Relay 1 Local Fallback
platform: template
id: relay1_fallback
entity_category: config
restore_state: true
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
- name: ${device_name} Relay 2 Local Fallback
platform: template
id: relay2_fallback
entity_category: config
restore_state: true
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
##### START - NUMBER CONFIGURATION #####
number:
##### SCREEN BRIGHTNESS #####
- platform: template
name: ${device_name} Display Brightness
id: display_brightness
entity_category: config
unit_of_measurement: '%'
min_value: 1
max_value: 100
step: 1
restore_value: true
optimistic: true
set_action:
then:
- lambda: 'id(disp1).set_backlight_brightness(x/100);'
- lambda: 'id(disp1).send_command_printf("home.brightness.val=%i", int(x));'
- globals.set:
id: display_brightness_global
value: !lambda 'return int(x);'
##### SCREEN BRIGHTNESS DIMMED DOWN #####
- platform: template
name: ${device_name} Display Brightness Dimdown
id: display_dim_brightness
entity_category: config
unit_of_measurement: '%'
min_value: 1
max_value: 100
step: 1
restore_value: true
optimistic: true
set_action:
then:
- lambda: 'id(disp1).send_command_printf("home.brightdd.val=%i", int(x));'
- globals.set:
id: display_dim_brightness_global
value: !lambda 'return int(x);'
##### Temperature Correction #####
- platform: template
name: ${device_name} Temperature Correction
id: temperature_correction
entity_category: config
unit_of_measurement: '°C'
min_value: -10
max_value: 10
step: 0.5
restore_value: true
optimistic: true
set_action:
then:
- globals.set:
id: temperature_correction_global
value: !lambda 'return x;'
##### page-timeout #####
- platform: template
name: ${device_name} Page Timeout
id: page_timeout
entity_category: config
min_value: 0
max_value: 60
initial_value: 10
step: 1
restore_value: true
optimistic: true
##### START - DISPLAY START CONFIGURATION #####
display:
- id: disp1
platform: nextion
uart_id: tf_uart
tft_url: ${nextion_update_url}
on_setup:
then:
- logger.log: "Nextion start - Jump to page 8"
- lambda: id(disp1).send_command_printf("page 8");
- logger.log: "Nextion start - Publish ESPHome version"
- lambda: id(disp1).set_component_text_printf("boot.esph_version", "%s", "3.3"); ### esphome-version ###
- logger.log: "Nextion start - Wait for Home Assistant API"
- wait_until:
api.connected
- logger.log: "Nextion start - Publish IP address"
- lambda: id(disp1).set_component_text_printf("boot.ip_addr", "%s", id(ip_address).state.c_str());
- delay: 1s
- logger.log: "Nextion start - Set display brigntess"
- number.set:
id: display_brightness
value: !lambda 'return id(display_brightness_global);'
- logger.log: "Nextion start - Set display dim brightness"
- number.set:
id: display_dim_brightness
value: !lambda 'return id(display_dim_brightness_global);'
- logger.log: "Nextion start - Update settings page"
- lambda: id(disp1).set_component_text_printf("settings.a03", "%i", id(display_brightness_global));
- lambda: id(disp1).set_component_text_printf("settings.a04", "%i", id(display_dim_brightness_global));
- lambda: id(disp1).send_command_printf("settings.brightslider.val=%i", id(display_brightness_global));
- lambda: id(disp1).send_command_printf("settings.dimslider.val=%i", id(display_dim_brightness_global));
- if:
condition:
switch.is_off: sleep_mode
then: *sleep_mode-turn_off
else: *sleep_mode-turn_on
- delay: 1s
- logger.log: "Nextion start - Inform Home Assistant display is ready"
- binary_sensor.template.publish:
id: nextion_init
state: true
- logger.log: "Nextion start - Done!"
### Script for page_timer
script:
- id: page_timer
mode: restart
parameters:
delay: int
then:
- lambda: ESP_LOGD("nspanel", "start page-timer delay %i", int(id(page_timeout).state));
- delay: !lambda return delay *1000;
- lambda: |-
DynamicJsonDocument doc(1024);
deserializeJson(doc, id(disp1_nspanel_event).state);
std::string page = doc["page"];
if (page == "home" or page == "screensaver" or page == "boot" or int(id(page_timeout).state) == 0) {
ESP_LOGD("nspanel", "no page-jump");
} else {
ESP_LOGD("nspanel", "timer->home");
id(disp1).send_command_printf("page 0");
}