generated from esphome/esphome-project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
nspanel.yaml
1171 lines (1081 loc) · 42.7 KB
/
nspanel.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
# These substitutions allow the end user to override certain values
substitutions:
friendly_name: 'NSPanel'
device_name: 'nspanel'
node_name: 'nspanel'
device_description: 'SONOFF NSPanel - stock TFT firmware 1.4.0 - WiFi, BT, HMI touch'
project_base: 'SONOFF'
project_name: 'NSPanel86'
##########################################################
# Home assistant entities exposed to NSPanel
# replace these with your own
##########################################################
hass_light_white: 'light.corridor'
hass_light_rgb_01: 'light.balcony'
hass_light_rgb_02: 'light.twinkly'
hass_plug_01: 'switch.gate'
hass_plug_grouped_01: 'switch.click_and_grow'
hass_plug_grouped_02: 'switch.daylight'
hass_cover_01: 'cover.shade'
hass_scene: 'scene.night'
hass_climate: 'climate.livingroom'
hass_sensor_humidity: 'sensor.humidity' # indoor humidity for index screen
hass_weather: 'weather.home' # weather entity to get the conditon icon
hass_sensor_weather: 'sensor.weather' # see below
# You must create a template sensor in Home Assistant to grab the weather attributes
# template:
# - sensor:
# - unique_id: weather
# name: Weather
# state: >-
# {{ states('weather.home') | replace('_',' ') | capitalize }}
# attributes:
# forecast_high: >-
# {{ states.weather.home.attributes.forecast[0].temperature }}
# forecast_low: >-
# {{ states.weather.home.attributes.forecast[0].templow }}
##########################################################
# /end customizing
##########################################################
esphome:
name: $device_name
comment: $device_description
friendly_name: $friendly_name
# Automatically add the mac address to the name
# so you can use a single firmware for all devices
name_add_mac_suffix: true
# This will allow for (future) project identification,
# configuration and updates.
project:
name: ${project_base}.${project_name}
version: "1.4.0"
esp32:
board: esp32dev
# To be able to get logs from the device via serial and api.
logger:
# API is a requirement of the dashboard import.
api:
id: api_id
services:
- service: set_ledc_frequency
variables:
my_frequency: float
then:
- output.turn_on: ${device_name}_buzzer_out
- output.ledc.set_frequency:
id: ${device_name}_buzzer_out
frequency: !lambda "return my_frequency;"
- service: set_output_level
variables:
my_level: float
then:
- output.turn_on: ${device_name}_buzzer_out
- output.set_level:
id: ${device_name}_buzzer_out
level: !lambda "return my_level;"
- service: send_json
variables:
my_type: int
my_json: string
then:
- lambda: 'id(ns_panel).send_json_command(my_type,my_json);'
# JSON commands list:
# https://blakadder.github.io/nspanel/
# https://blakadder.com/nspanel-hacking/
# https://gist.github.com/blakadder/7928279bd95ad47b54f705b7a121a7e1
# https://github.com/blakadder/nspanel/blob/main/nextion-objects-readtext.txt
- service: play_rtttl
variables:
song_str: string
then:
- output.turn_on: ${device_name}_buzzer_out
- rtttl.play:
rtttl: !lambda "return song_str;"
- output.turn_off: ${device_name}_buzzer_out
- service: weather_data
variables:
icon: int
temperature: int
min: int
max: int
then:
- lambda: id(ns_panel).send_weather_data((nspanel::WeatherIcon)icon, temperature, min, max);
# OTA is required for Over-the-Air updating
ota:
# This should point to the public location of this yaml file.
dashboard_import:
package_import_url: github://velijv/esphome-configs/nspanel.yaml@main
wifi:
# Set up a wifi access point using the device name above
ap:
ssid: ${friendly_name}
password: "12345678"
# In combination with the `ap` this allows the user
# to provision wifi credentials to the device.
captive_portal:
##########################################################
# Most projects should not remove anything from above here
# and should just modify the name, project name/version
# and git url for the dashboard_import
##########################################################
# Sets up Bluetooth LE (Only on ESP32) to allow the user
# to provision wifi credentials to the device.
esp32_improv:
authorizer: none
# Sets up the improv via serial client for Wi-Fi provisioning.
# Handy if your device has a usb port for the user to add credentials when they first get it.
improv_serial:
#################################################################################################
# Before installation, you must add some configs in your Home Assistant:
#################################################################################################
# https://github.com/DeanoXX/esphome-config/blob/main/homeassistant_service.yaml
# ESPHome cant send the RGB values as an array so need an interim script.
# script:
# set_light_on_rgb:
# alias: NSPanel ESPHome RGB light set
# sequence:
# - service: light.turn_on
# target:
# entity_id: '{{ entity_name }}'
# data_template:
# brightness: '{{ brightness }}'
# rgb_color:
# - '{{ red }}'
# - '{{ green }}'
# - '{{ blue }}'
#################################################################################################
# the NSPanel component:
#################################################################################################
# https://github.com/esphome/esphome/pull/2702
external_components:
- source: github://pr#2702
components: ["nspanel"]
refresh: 0s
time:
- platform: sntp
id: sntp_time
timezone: Europe/Tallinn
uart:
tx_pin: 16
rx_pin: 17
baud_rate: 115200
# NSPanel Component for access to panel.
# Updates temperature, date, time, Relay indicators
# Provides JSON interface to panel
nspanel:
id: ns_panel
time_id: sntp_time
temperature: ${device_name}_temperature
eco_mode_switch: ${device_name}_eco_mode
screen_power_switch: ${device_name}_screen_power
relays:
- ${device_name}_relay_1
- ${device_name}_relay_2
on_json_message:
then:
# Widget 1 (type:0x86 id:hass_light_white)
- if:
condition:
lambda: 'return (type == 0x86 && root.containsKey("id") && strcasecmp(root["id"], "hass_light_white") == 0);'
then:
- if:
condition:
lambda: 'return (root["params"].containsKey("switch") && root["params"]["switch"] == "on");'
then:
- homeassistant.service:
service: light.turn_on
data:
entity_id: $hass_light_white
- if:
condition:
lambda: 'return (root["params"].containsKey("switch") && root["params"]["switch"] == "off");'
then:
- homeassistant.service:
service: light.turn_off
data:
entity_id: $hass_light_white
- if:
condition:
lambda: 'return (root["params"].containsKey("white"));'
then:
- homeassistant.service:
service: light.turn_on
data:
entity_id: $hass_light_white
brightness: !lambda 'return int(root["params"]["white"]["br"].as<float>() / 100 * 255);'
# Widget 2 (type:0x86 id:light_rgb_01)
- if:
condition:
lambda: 'return (type == 0x86 && root.containsKey("id") && strcasecmp(root["id"], "light_rgb_01") == 0);'
then:
- if:
condition:
lambda: 'return (root["params"].containsKey("switch") && root["params"]["switch"] == "on" && !root["params"].containsKey("bright"));'
then:
- homeassistant.service:
service: light.turn_on
data:
entity_id: $hass_light_rgb_01
- if:
condition:
lambda: 'return (root["params"].containsKey("switch") && root["params"]["switch"] == "off");'
then:
- homeassistant.service:
service: light.turn_off
data:
entity_id: $hass_light_rgb_01
- if:
condition:
lambda: 'return (root["params"].containsKey("bright"));'
then:
- homeassistant.service:
service: script.set_light_on_rgb
data:
entity_name: $hass_light_rgb_01
brightness: !lambda 'return int(root["params"]["bright"].as<float>() / 100 * 255);'
red: !lambda 'return root["params"]["colorR"].as<int>();'
green: !lambda 'return root["params"]["colorG"].as<int>();'
blue: !lambda 'return root["params"]["colorB"].as<int>();'
# Widget 3 (type:0x86 id:light_rgb_02)
- if:
condition:
lambda: 'return (type == 0x86 && root.containsKey("id") && strcasecmp(root["id"], "light_rgb_02") == 0);'
then:
- if:
condition:
lambda: 'return (root["params"].containsKey("switch") && root["params"]["switch"] == "on" && !root["params"].containsKey("bright"));'
then:
- homeassistant.service:
service: light.turn_on
data:
entity_id: $hass_light_rgb_02
- if:
condition:
lambda: 'return (root["params"].containsKey("switch") && root["params"]["switch"] == "off");'
then:
- homeassistant.service:
service: light.turn_off
data:
entity_id: $hass_light_rgb_02
- if:
condition:
lambda: 'return (root["params"].containsKey("bright"));'
then:
- homeassistant.service:
service: script.set_light_on_rgb
data:
entity_name: $hass_light_rgb_02
brightness: !lambda 'return int(root["params"]["bright"].as<float>() / 100 * 255);'
red: !lambda 'return root["params"]["colorR"].as<int>();'
green: !lambda 'return root["params"]["colorG"].as<int>();'
blue: !lambda 'return root["params"]["colorB"].as<int>();'
# Widget 4 (type:0x86 id:plug_01)
- if:
condition:
lambda: 'return (type == 0x86 && root.containsKey("id") && strcasecmp(root["id"], "hass_plug_01") == 0);'
then:
- if:
condition:
lambda: 'return (root["params"].containsKey("switch") && root["params"]["switch"] == "on");'
then:
- homeassistant.service:
service: switch.turn_on
data:
entity_id: $hass_plug_01
- if:
condition:
lambda: 'return (root["params"].containsKey("switch") && root["params"]["switch"] == "off");'
then:
- homeassistant.service:
service: switch.turn_off
data:
entity_id: $hass_plug_01
# Widget 5 (type:0x86 id:group_01 = plug_2 + plug_03)
- if:
condition:
lambda: 'return (type == 0x86 && root.containsKey("id") && strcasecmp(root["id"], "group_01") == 0);'
then:
- if:
condition:
lambda: 'return (root["params"].containsKey("switches") && root["params"]["switches"][0]["switch"] == "on");'
then:
- homeassistant.service:
service: switch.turn_on
data:
entity_id: $hass_plug_grouped_01
- if:
condition:
lambda: 'return (root["params"].containsKey("switches") && root["params"]["switches"][0]["switch"] == "off");'
then:
- homeassistant.service:
service: switch.turn_off
data:
entity_id: $hass_plug_grouped_01
- if:
condition:
lambda: 'return (root["params"].containsKey("switches") && root["params"]["switches"][1]["switch"] == "on");'
then:
- homeassistant.service:
service: switch.turn_on
data:
entity_id: $hass_plug_grouped_02
- if:
condition:
lambda: 'return (root["params"].containsKey("switches") && root["params"]["switches"][1]["switch"] == "off");'
then:
- homeassistant.service:
service: switch.turn_off
data:
entity_id: $hass_plug_grouped_02
# Widget 6 (type:0x86 id:cover_1)
- if:
condition:
lambda: 'return (type == 0x86 && root.containsKey("id") && strcasecmp(root["id"], "hass_cover_01") == 0);'
then:
- if:
condition:
lambda: 'return (root["params"].containsKey("switch") && root["params"]["switch"] == "on");'
then:
- homeassistant.service:
service: cover.open_cover
data:
entity_id: $hass_cover_01
- if:
condition:
lambda: 'return (root["params"].containsKey("switch") && root["params"]["switch"] == "off");'
then:
- homeassistant.service:
service: cover.close_cover
data:
entity_id: $hass_cover_01
- if:
condition:
lambda: 'return (root["params"].containsKey("switch") && root["params"]["switch"] == "pause");'
then:
- homeassistant.service:
service: cover.stop_cover
data:
entity_id: $hass_cover_01
- if:
condition:
lambda: 'return (root["params"].containsKey("setclose"));'
then:
- homeassistant.service:
service: input_number.set_value
data:
entity_id: input_number.cover_1_pos
value: !lambda 'return 100 - root["params"]["setclose"].as<int>();'
# Widget 7 (type:0x86 scene:song)
- if:
condition:
lambda: 'return (type == 0x86 && root.containsKey("id") && strcasecmp(root["id"], "song") == 0);'
then:
- rtttl.play:
rtttl: 'Lamourt:d=4,o=5,b=160:4f#, 4p, 4f#, 8f#, 8d6, 4c#6, 4p, 4c#6, 8c#6, 8d6, 4b, 4p, 4b, 8b, 8a, 4b, 8b, 8a, 8b, 8a, 8b, 8a, 4f#'
# Widget 8 - Scene Sleep
# lambda: 'return (type == 0x86 && root.containsKey("id") && strcasecmp(root["id"], "scene_sleep") == 0);'
- if:
condition:
lambda: 'return (type == 0x86 && root.containsKey("id") && strcasecmp(root["id"], "scene_sleep") == 0);'
then:
- homeassistant.service:
service: scene.turn_on
data:
entity_id: $hass_scene
# Thermostat (type:0x84)
- if:
condition:
lambda: 'return (type == 0x84);'
then:
- if:
condition:
lambda: 'return (root.containsKey("ATCEnable") && root["ATCEnable"] == 1);'
then:
- homeassistant.service:
service: climate.turn_on
data:
entity_id: $hass_climate
- if:
condition:
lambda: 'return (root.containsKey("ATCEnable") && root["ATCEnable"] == 0);'
then:
- homeassistant.service:
service: climate.turn_off
data:
entity_id: $hass_climate
- if:
condition:
lambda: 'return (root.containsKey("ATCExpect0"));'
then:
- homeassistant.service:
service: climate.set_temperature
data:
entity_id: $hass_climate
temperature: !lambda 'return root["ATCExpect0"].as<int>();'
hvac_mode: heat
output:
# Buzzer for playing tones
- platform: ledc
id: ${device_name}_buzzer_out
pin:
number: 21
rtttl:
id: ${device_name}_buzzer
output: ${device_name}_buzzer_out
on_finished_playback:
- output.turn_off: ${device_name}_buzzer_out
number:
- platform: template
entity_category: config
name: LEDC Frequency
icon: mdi:sine-wave
id: ledc_frequency
optimistic: true
min_value: 1220
max_value: 19531
step: 100
set_action:
then:
- output.turn_on: ${device_name}_buzzer_out
- output.ledc.set_frequency:
id: ${device_name}_buzzer_out
frequency: !lambda "return x;" # Hz
- platform: template
entity_category: config
name: LEDC Level
icon: mdi:cosine-wave
id: ledc_level
optimistic: true
min_value: 0
max_value: 1
step: 0.1
set_action:
then:
- output.turn_on: ${device_name}_buzzer_out
- output.set_level:
id: ${device_name}_buzzer_out
level: !lambda "return x;" # %
switch:
- platform: gpio
name: Left
icon: mdi:arrow-left-bold-box
id: ${device_name}_relay_1
restore_mode: ALWAYS_ON
pin:
number: 22
- platform: gpio
name: Right
icon: mdi:arrow-right-bold-box
id: ${device_name}_relay_2
restore_mode: ALWAYS_ON
pin:
number: 19
- platform: gpio
# Panel Screen Power
name: Screen
id: ${device_name}_screen_power
entity_category: config
icon: mdi:monitor-speaker-off
pin:
number: 4
inverted: true
restore_mode: ALWAYS_ON
on_turn_on:
# Initiliase Screen - These timings could be more aggressive
then:
- delay: 6s
- script.execute: nspanel_init
- delay: 3s
- script.execute: nspanel_weather
- script.execute: nspanel_humidity
# Must send Wifi State for widgets to update (particulalry after power-on of screen only
# code taken from within NSPanel component code
- lambda: |-
uint8_t rssi = 0;
rssi = (wifi::global_wifi_component->wifi_rssi() * -1) / 20.0f;
std::string json_str = json::build_json([rssi](JsonObject root) {
root["wifiState"] = "connected";
root["rssiLevel"] = rssi;
});
id(ns_panel).send_json_command(0x85, json_str);
- platform: template
# Template switch to enable/disable screen dimming
name: Screensaver Climate
id: ${device_name}_climate_screensave
icon: mdi:thermostat
# entity_category: config
restore_state: false
optimistic: true
restore_mode: ALWAYS_OFF
on_turn_on:
then:
- script.execute: nspanel_climate
on_turn_off:
then:
- script.execute: nspanel_weather
- platform: template
# Template switch to enable/disable screen dimming
name: Energy Saving Mode
id: ${device_name}_eco_mode
icon: mdi:leaf
entity_category: config
restore_state: true
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
- platform: template
name: Left Indicator
id: ${device_name}_left_indicator
entity_category: config
icon: mdi:arrow-left-box
optimistic: true
restore_state: true
restore_mode: RESTORE_DEFAULT_OFF
turn_on_action:
lambda: |-
id(ns_panel).send_json_command(0x87, "{\"switches\":[{\"outlet\":0,\"switch\":\"on\"}]}");
turn_off_action:
lambda: |-
id(ns_panel).send_json_command(0x87, "{\"switches\":[{\"outlet\":0,\"switch\":\"off\"}]}");
- platform: template
name: Right Indicator
id: ${device_name}_right_indicator
entity_category: config
icon: mdi:arrow-right-box
optimistic: true
restore_state: true
restore_mode: RESTORE_DEFAULT_OFF
turn_on_action:
lambda: |-
id(ns_panel).send_json_command(0x87, "{\"switches\":[{\"outlet\":1,\"switch\":\"on\"}]}");
turn_off_action:
lambda: |-
id(ns_panel).send_json_command(0x87, "{\"switches\":[{\"outlet\":1,\"switch\":\"off\"}]}");
button:
- platform: template
name: Factory Test Mode
id: ${device_name}_factory_test_mode
icon: mdi:fit-to-screen-outline
entity_category: diagnostic
# disabled_by_default: true
on_press:
then: # Initiliase Factory Test Mode
- lambda: |-
id(ns_panel).send_json_command(0x80, "{\"queryInfo\":\"factory\"}");
- platform: restart
name: Restart
icon: mdi:restart
id: ${device_name}_restart # id addded for nspanel stock
device_class: restart
entity_category: diagnostic
disabled_by_default: true
binary_sensor:
# NS Panel Hard Switches
- platform: gpio
id: ${device_name}_button_1
name: Left Button
icon: mdi:arrow-left-bold-box-outline
pin:
number: 14
inverted: true
on_press:
then:
if:
condition:
api.connected:
then:
- homeassistant.service:
service: light.toggle
data:
entity_id: $hass_light_rgb_01
else:
- switch.toggle: ${device_name}_relay_1
on_multi_click:
- timing:
- ON for at least 3s
then:
- switch.toggle: ${device_name}_relay_1
- timing:
- ON for at least 5s
then:
- button.press: ${device_name}_restart
- platform: gpio
id: ${device_name}_button_2
name: Right Button
icon: mdi:arrow-right-bold-box-outline
pin:
number: 27
inverted: true
on_press:
then:
if:
condition:
api.connected:
then:
- homeassistant.service:
service: light.toggle
data:
entity_id: $hass_light_white
else:
- switch.toggle: ${device_name}_relay_2
on_multi_click:
- timing:
- ON for at least 3s
then:
- switch.toggle: ${device_name}_relay_2
- timing:
- ON for at least 5s
then:
- button.press: ${device_name}_restart
# HA Tracking sensors for device states
# Update nspanel on state change
- platform: homeassistant
id: hass_light_white
name: $hass_light_white
entity_id: $hass_light_white
on_press:
then:
- switch.turn_on: ${device_name}_right_indicator
- logger.log: "Turning ON Right indicator"
- lambda: 'id(ns_panel).send_json_command(0x86,"{\"id\":\"hass_light_white\",\"params\":{\"switch\":\"on\"}}");'
on_release:
then:
- switch.turn_off: ${device_name}_right_indicator
- logger.log: "Turning OFF Right indicator"
- lambda: 'id(ns_panel).send_json_command(0x86,"{\"id\":\"hass_light_white\",\"params\":{\"switch\":\"off\"}}");'
- platform: homeassistant
id: hass_light_rgb_01
name: $hass_light_rgb_01
entity_id: $hass_light_rgb_01
on_press:
then:
- switch.turn_on: ${device_name}_left_indicator
- logger.log: "Turning ON Left indicator"
- lambda: 'id(ns_panel).send_json_command(0x86,"{\"id\":\"light_rgb_01\",\"params\":{\"switch\":\"on\"}}");'
on_release:
then:
- switch.turn_off: ${device_name}_left_indicator
- logger.log: "Turning OFF Left indicator"
- lambda: 'id(ns_panel).send_json_command(0x86,"{\"id\":\"light_rgb_01\",\"params\":{\"switch\":\"off\"}}");'
- platform: homeassistant
id: hass_light_rgb_02
name: $hass_light_rgb_02
entity_id: $hass_light_rgb_02
on_press:
then:
- lambda: 'id(ns_panel).send_json_command(0x86,"{\"id\":\"light_rgb_02\",\"params\":{\"switch\":\"on\"}}");'
on_release:
then:
- lambda: 'id(ns_panel).send_json_command(0x86,"{\"id\":\"light_rgb_02\",\"params\":{\"switch\":\"off\"}}");'
- platform: homeassistant
id: hass_plug_01_switch
name: $hass_plug_01
entity_id: $hass_plug_01
on_press:
then:
- lambda: 'id(ns_panel).send_json_command(0x86,"{\"id\":\"hass_plug_01\",\"params\":{\"switch\":\"on\"}}");'
on_release:
then:
- lambda: 'id(ns_panel).send_json_command(0x86,"{\"id\":\"hass_plug_01\",\"params\":{\"switch\":\"off\"}}");'
- platform: homeassistant
id: plug_08_switch
name: $hass_plug_grouped_02
entity_id: $hass_plug_grouped_02
on_press:
then:
- lambda: 'id(ns_panel).send_json_command(0x86,"{\"id\":\"group_01\",\"params\":{\"switches\":[{\"switch\":\"on\",\"outlet\":0}]}}");'
on_release:
then:
- lambda: 'id(ns_panel).send_json_command(0x86,"{\"id\":\"group_01\",\"params\":{\"switches\":[{\"switch\":\"off\",\"outlet\":0}]}}");'
- platform: homeassistant
id: plug_11_switch
entity_id: $hass_plug_grouped_02
name: $hass_plug_grouped_02
on_press:
then:
- lambda: 'id(ns_panel).send_json_command(0x86,"{\"id\":\"group_01\",\"params\":{\"switches\":[{\"switch\":\"on\",\"outlet\":1,\"name\":\"11\"}]}}");'
on_release:
then:
- lambda: 'id(ns_panel).send_json_command(0x86,"{\"id\":\"group_01\",\"params\":{\"switches\":[{\"switch\":\"off\",\"outlet\":1}]}}");'
sensor:
# nspanel related temperature sensors
# Internal temperature sensor, adc value
- platform: adc
id: ${device_name}_ntc_source
name: NTC source
internal: true
pin: 38
update_interval: 10s
attenuation: 11db
# Internal temperature sensor, adc reading converted to resistance (calculation)
- platform: resistance
id: ${device_name}_resistance_sensor
name: Resistance sensor
internal: true
sensor: ${device_name}_ntc_source
configuration: DOWNSTREAM
resistor: 11.2kOhm
# Internal temperature sensor, resistance to temperature (calculation)
- platform: ntc
id: ${device_name}_temperature
sensor: ${device_name}_resistance_sensor
calibration:
b_constant: 3950
reference_temperature: 21°C
reference_resistance: 10kOhm
name: Temperature
filters:
- median:
window_size: 60
send_every: 60
send_first_at: 6
on_value:
then:
- script.execute: nspanel_humidity
# Home Assistant Humidity sensor to update panel screensaver
- platform: homeassistant
id: sensor_humidity
entity_id: ${hass_sensor_humidity}
name: ${hass_sensor_humidity}
on_value:
then:
- script.execute: nspanel_humidity
# Home Assistant Light State Sensors to update panel
- platform: homeassistant
# Light $hass_light brightness (0-255)
id: hass_light_white_bright
name: $hass_light_white brightness
entity_id: $hass_light_white
attribute: brightness
on_value:
then:
- script.execute: ha_hass_light_white_update
- platform: homeassistant
# Light $hass_light_rgb brightness (0-255)
id: hass_light_rgb_01_bright
name: $hass_light_rgb_01 brightness
entity_id: $hass_light_rgb_01
attribute: brightness
on_value:
then:
- script.execute: ha_hass_light_rgb_01_update
- platform: homeassistant
# Light $hass_light_rgb brightness (0-255)
id: hass_light_rgb_02_bright
name: $hass_light_rgb_02 brightness
entity_id: $hass_light_rgb_02
attribute: brightness
on_value:
then:
- script.execute: ha_hass_light_rgb_02_update
- platform: homeassistant
# Light $hass_light_rgb brightness (0-255)
id: hass_cover_01_pos
name: $hass_cover_01 position
entity_id: $hass_cover_01
attribute: current_position
on_value:
then:
- script.execute: ha_hass_cover_01_update_pos
- platform: homeassistant
# Thermostat set temp
id: climate
name: $hass_climate
entity_id: $hass_climate
attribute: temperature
internal: true
on_value:
then:
- script.execute: ha_thermostat_update_temp
- platform: homeassistant
id: hass_weather_temperature
name: Weather temperature
entity_id: $hass_weather
attribute: temperature
internal: true
on_value:
then:
- script.execute: nspanel_weather
# states.weather.home.attributes[0]["temperature"]
- platform: homeassistant
id: hass_weather_forecast_high
name: Weather forecast high
entity_id: $hass_sensor_weather
attribute: forecast_high
internal: true
on_value:
then:
- script.execute: nspanel_weather
# states.weather.home.attributes[0]["templow"]
- platform: homeassistant
id: hass_weather_forecast_low
name: Weather forecast low
entity_id: $hass_sensor_weather
attribute: forecast_low
internal: true
on_value:
then:
- script.execute: nspanel_weather
text_sensor:
# Text Sensors to track attirbutes from HA (HA -> Panel)
- platform: homeassistant
name: ${hass_light_rgb_01} rgb_color
id: hass_light_rgb_01_rgb
entity_id: $hass_light_rgb_01
attribute: rgb_color
internal: true
on_value:
then:
- script.execute: ha_hass_light_rgb_01_update
- platform: homeassistant
name: ${hass_light_rgb_02} rgb_color
id: hass_light_rgb_02_rgb
entity_id: $hass_light_rgb_02
attribute: rgb_color
internal: true
on_value:
then:
- script.execute: ha_hass_light_rgb_02_update
- platform: homeassistant
id: hass_cover_01_state
name: ${hass_cover_01} state
entity_id: $hass_cover_01
internal: true
on_value:
then:
- script.execute: ha_hass_cover_01_update_state
- platform: homeassistant
id: climate_state
name: ${hass_climate} state
entity_id: $hass_climate
internal: true
on_value:
then:
- script.execute: ha_thermostat_update_state
# Home Assistant weather entity to map icons on screensaver
- platform: homeassistant
entity_id: $hass_weather
name: Weather icon
id: hass_weather_icon
internal: true
filters:
- map:
- clear-night -> 1
- cloudy -> 7
- exceptional -> 1
- fog -> 11
- hail -> 24
- lightning -> 15
- lightning-rainy -> 15
- partlycloudy -> 2
- pouring -> 12
- rainy -> 12
- snowy -> 22
- snowy-rainy -> 29
- sunny -> 1
- windy -> 32
- windy-variant -> 11
on_value:
then:
- script.execute: nspanel_weather
script:
- id: nspanel_humidity
then:
- lambda: |-
if (id(sensor_humidity).has_state()) {
id(ns_panel).send_json_command(0x83, "{\"temperature\":"+to_string((int) id(${device_name}_temperature).state)+",\"humidity\":"+to_string((int) id(sensor_humidity).state)+"}");
}
else {
ESP_LOGE("nspanel_weather", "Humidity error");
id(ns_panel).send_json_command(0x83, "{\"temperature\":69,\"humidity\":420}");
}
- id: ha_hass_light_white_update
then:
- lambda: |-
if (id(hass_light_white).state) {
int i_brightness = int(id(hass_light_white_bright).state / 255 * 100);
id(ns_panel).send_json_command(0x86,"{\"id\":\"hass_light_white\",\"params\":{\"switch\":\"on\",\"ltype\":\"white\",\"white\":{\"br\":" + to_string(i_brightness) + "}}}");
} else {
id(ns_panel).send_json_command(0x86,"{\"id\":\"hass_light_white\",\"params\":{\"switch\":\"off\"}}");
}
- id: ha_hass_light_rgb_01_update
# Decode RGB Attribute ((r,g,b) and send to panel
then:
- lambda: |-
if (id(hass_light_rgb_01).state) {
int i_brightness = int(id(hass_light_rgb_01_bright).state / 255 * 100);
std::string s = id(hass_light_rgb_01_rgb).state;
std::string r = "255";
std::string g = "0";
std::string b = "0";
int p1 = s.find(",");
if (p1 > 0) {
int p2 = s.find(",",p1+1);
r = s.substr(1, p1-1).erase(0,s.find_first_not_of(" "));
g = s.substr(p1+2,p2-p1-2).erase(0,s.find_first_not_of(" "));
b = s.substr(p2+2,s.length()-2).erase(0,s.find_first_not_of(" "));
}
id(ns_panel).send_json_command(0x86,"{\"id\":\"light_rgb_01\",\"params\":{\"switch\":\"on\",\"light_type\":1,\"mode\":1,\"bright\":" + to_string(i_brightness) + ",\"colorR\":" + to_string(r) + ",\"colorG\":" + to_string(g) + ",\"colorB\":" + to_string(b) + "}}");
} else {
id(ns_panel).send_json_command(0x86,"{\"id\":\"light_rgb_01\",\"params\":{\"switch\":\"off\"}}");
}
- id: ha_hass_light_rgb_02_update