-
Notifications
You must be signed in to change notification settings - Fork 2
/
esphome.yaml
695 lines (645 loc) · 20.7 KB
/
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
# Set some variables for convenience
substitutions:
node_name: nspanel-guest-bedroom
device_name: Guest Bedroom Switch
target_thermostat: climate.guest_bedroom_minisplit
target_lights: light.office_lights
globals:
- id: selected_color_red
type: String
- id: selected_color_green
type: String
- id: selected_color_blue
type: String
external_components:
- source: github://pr#2956
components: [nextion]
refresh: 1h
esphome:
name: $node_name
comment: $device_name
includes:
- colorwheel.h
esp32:
board: esp32dev
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable logging
logger:
level: debug
# Enable wireless updates
ota:
# Enable Home Assistant API
api:
services:
# Service to play a song
- service: play_rtttl
variables:
song_str: string
then:
- rtttl.play:
rtttl: !lambda 'return song_str;'
- service: upload_tft
then:
- lambda: 'id(disp1)->upload_tft();'
- service: send_command
variables:
cmd: string
then:
- lambda: 'id(disp1).send_command_printf("%s", cmd.c_str());'
# A reboot button is always useful
button:
- platform: restart
name: Restart $device_name
device_class: restart
- platform: template
name: $device_name TFT Upload
device_class: update
on_press:
- lambda: 'id(disp1).upload_tft();'
# Define some inputs
binary_sensor:
- platform: gpio
name: $device_name Left Button
pin:
number: 14
inverted: true
on_click:
- switch.toggle: relay_1
- platform: gpio
name: $device_name Right Button
pin:
number: 27
inverted: true
on_click:
- switch.toggle: relay_2
- platform: nextion
name: $device_name Minus Button
page_id: 0
component_id: 1
internal: true
on_release:
then:
- rtttl.play: "twobits:d=4,o=0,b=6000:a0"
- homeassistant.service:
service: climate.set_temperature
data_template:
entity_id: $target_thermostat
temperature: '{{ (state_attr("$target_thermostat", "temperature")|round(0)) - 1 }}'
- platform: nextion
name: $device_name Plus Button
page_id: 0
component_id: 2
internal: true
on_release:
then:
- rtttl.play: "twobits:d=4,o=0,b=6000:a0"
- homeassistant.service:
service: climate.set_temperature
data_template:
entity_id: $target_thermostat
temperature: '{{ (state_attr("$target_thermostat", "temperature")|round(0)) + 1 }}'
- platform: nextion
name: $device_name Heat Button
page_id: 0
component_id: 6
on_release:
then:
- if:
condition:
lambda: 'return id(current_mode).state == "heatActive";'
then:
- rtttl.play: "twobits:d=4,o=0,b=6000:a0"
- homeassistant.service:
service: climate.set_hvac_mode
data:
entity_id: $target_thermostat
hvac_mode: 'off'
else:
- rtttl.play: "twobits:d=4,o=0,b=6000:a0"
- homeassistant.service:
service: climate.set_hvac_mode
data:
entity_id: $target_thermostat
hvac_mode: heat
- platform: nextion
name: $device_name Cool Button
page_id: 0
component_id: 7
on_release:
then:
- if:
condition:
lambda: 'return id(current_mode).state == "coolActive";'
then:
- rtttl.play: "twobits:d=4,o=0,b=6000:a0"
- homeassistant.service:
service: climate.set_hvac_mode
data:
entity_id: $target_thermostat
hvac_mode: 'off'
else:
- rtttl.play: "twobits:d=4,o=0,b=6000:a0"
- homeassistant.service:
service: climate.set_hvac_mode
data:
entity_id: $target_thermostat
hvac_mode: cool
- platform: nextion
name: $device_name Humidity Button
page_id: 0
component_id: 8
on_release:
then:
- if:
condition:
lambda: 'return id(current_mode).state == "dryActive";'
then:
- rtttl.play: "twobits:d=4,o=0,b=6000:a0"
- homeassistant.service:
service: climate.set_hvac_mode
data:
entity_id: $target_thermostat
hvac_mode: 'off'
else:
- rtttl.play: "twobits:d=4,o=0,b=6000:a0"
- homeassistant.service:
service: climate.set_hvac_mode
data:
entity_id: $target_thermostat
hvac_mode: dry
- platform: nextion
name: $device_name Fan Button
page_id: 0
component_id: 9
on_release:
then:
- if:
condition:
lambda: 'return id(current_mode).state == "fanActive";'
then:
- rtttl.play: "twobits:d=4,o=0,b=6000:a0"
- homeassistant.service:
service: climate.set_hvac_mode
data:
entity_id: $target_thermostat
hvac_mode: 'off'
else:
- rtttl.play: "twobits:d=4,o=0,b=6000:a0"
- homeassistant.service:
service: climate.set_hvac_mode
data:
entity_id: $target_thermostat
hvac_mode: fan_only
- platform: nextion
name: $device_name Fan Speed Button
page_id: 0
component_id: 10
on_release:
then:
- rtttl.play: "twobits:d=4,o=0,b=6000:a0"
- homeassistant.service:
service: climate.set_fan_mode
data:
entity_id: $target_thermostat
fan_mode: !lambda |-
if (id(fan_speed).state == "1") {
return "2";
} else if (id(fan_speed).state == "2") {
return "3";
} else if (id(fan_speed).state == "3") {
return "4";
} else if (id(fan_speed).state == "4") {
return "AUTO";
} else {
return "1";
}
- platform: nextion
name: $device_name Horizontal Vane Button
page_id: 0
component_id: 11
on_release:
then:
- rtttl.play: "twobits:d=4,o=0,b=6000:a0"
- homeassistant.service:
service: climate.set_swing_mode
data:
entity_id: $target_thermostat
swing_mode: !lambda |-
if (id(horizontal_vane).state == "1") {
return "2";
} else if (id(horizontal_vane).state == "2") {
return "3";
} else if (id(horizontal_vane).state == "3") {
return "4";
} else if (id(horizontal_vane).state == "4") {
return "5";
} else if (id(horizontal_vane).state == "5") {
return "AUTO";
} else {
return "1";
}
- platform: nextion
name: $device_name Brightness Slider
page_id: 1
component_id: 4
internal: true
on_release:
then:
- lambda: !lambda |-
id(brightness_value).update();
- platform: nextion
name: $device_name Color Wheel
page_id: 1
component_id: 18
internal: true
on_release:
then:
- lambda: |-
id(color_wheel_x).update();
id(color_wheel_y).update();
- delay: 20ms
- lambda: |-
RgbColor color = posToColor(id(color_wheel_x).state, id(color_wheel_y).state);
id(selected_color_red) = String(color.r);
id(selected_color_green) = String(color.g);
id(selected_color_blue) = String(color.b);
- homeassistant.service:
service: script.set_light_rgb
data:
light_name: $target_lights
red: !lambda 'return id(selected_color_red).c_str();'
green: !lambda 'return id(selected_color_green).c_str();'
blue: !lambda 'return id(selected_color_blue).c_str();'
- platform: nextion
name: $device_name Color Temp Slider
page_id: 1
component_id: 14
internal: true
on_release:
then:
- lambda: !lambda |-
id(color_temp_value).update();
- platform: nextion
name: $device_name Prev Page 1
page_id: 0
component_id: 21
internal: true
on_release:
then:
- delay: 20ms
- script.execute: refresh
- platform: nextion
name: $device_name Next Page 1
page_id: 0
component_id: 22
internal: true
on_release:
then:
- delay: 20ms
- script.execute: refresh
- platform: nextion
name: $device_name Prev Page 2
page_id: 1
component_id: 20
internal: true
on_release:
then:
- delay: 20ms
- script.execute: refresh
- platform: nextion
name: $device_name Next Page 2
page_id: 1
component_id: 19
internal: true
on_release:
then:
- delay: 20ms
- script.execute: refresh
sensor:
- platform: wifi_signal
name: $device_name WiFi Signal
update_interval: 60s
- platform: ntc
id: temperature
sensor: resistance_sensor
calibration:
b_constant: 3950
reference_temperature: 25°C
reference_resistance: 10kOhm
name: $device_name Temperature
- platform: resistance
id: resistance_sensor
sensor: ntc_source
configuration: DOWNSTREAM
resistor: 11.2kOhm
- platform: adc
id: ntc_source
pin: 38
update_interval: 10s
attenuation: 11db
- platform: homeassistant
id: target_temperature
entity_id: $target_thermostat
attribute: temperature
on_value:
then:
- if:
condition:
lambda: 'return id(current_mode).state == "0";'
then:
- lambda: 'id(disp1).set_component_text_printf("targetTemp", "--""\xb0");'
else:
- lambda: 'id(disp1).set_component_text_printf("targetTemp", "%i""\xb0", (int)x);'
- platform: homeassistant
id: current_temperature
entity_id: $target_thermostat
attribute: current_temperature
on_value:
then:
- lambda: 'id(disp1).set_component_text_printf("currentTemp", "%i""\xb0", (int)x);'
- platform: homeassistant
id: current_brightness
entity_id: $target_lights
attribute: brightness
on_value:
then:
- lambda: 'id(disp1).send_command_printf("brightnessVal.val=%i", (int)x);'
- platform: homeassistant
id: current_color_temp
entity_id: $target_lights
attribute: color_temp
on_value:
then:
- lambda: 'id(disp1).send_command_printf("tempSlider.val=%i", (int)x);'
- platform: nextion
id: brightness_value
component_name: brightnessVal
on_value:
then:
- homeassistant.service:
service: light.turn_on
data:
entity_id: $target_lights
brightness: !lambda 'return (int)x;'
- platform: nextion
id: color_temp_value
component_name: tempSlider
on_value:
then:
- homeassistant.service:
service: light.turn_on
data:
entity_id: $target_lights
color_temp: !lambda 'return (int)x;'
- platform: nextion
id: color_wheel_x
component_name: selectedColorX
filters:
- offset: -54
- platform: nextion
id: color_wheel_y
component_name: selectedColorY
filters:
- offset: -215
text_sensor:
- platform: homeassistant
id: current_mode
entity_id: $target_thermostat
filters:
- map:
- off -> 0
- heat -> heatActive
- cool -> coolActive
- dry -> dryActive
- fan_only -> fanActive
- heat_cool -> 0
on_value:
then:
- if:
condition:
lambda: 'return x == "0";'
then:
- lambda: 'id(disp1).send_command_printf("vis heatActive,0");'
- lambda: 'id(disp1).send_command_printf("vis coolActive,0");'
- lambda: 'id(disp1).send_command_printf("vis dryActive,0");'
- lambda: 'id(disp1).send_command_printf("vis fanActive,0");'
- lambda: 'id(disp1).set_component_text_printf("targetTemp", "--""\xb0");'
else:
- lambda: 'id(disp1).send_command_printf("vis heatActive,0");'
- lambda: 'id(disp1).send_command_printf("vis coolActive,0");'
- lambda: 'id(disp1).send_command_printf("vis dryActive,0");'
- lambda: 'id(disp1).send_command_printf("vis fanActive,0");'
- lambda: 'id(disp1).send_command_printf("vis %s,1", x.c_str());'
- lambda: 'id(disp1).set_component_text_printf("targetTemp", "%i""\xb0", (int)id(target_temperature).state);'
- platform: homeassistant
id: horizontal_vane
entity_id: $target_thermostat
attribute: swing_mode
filters:
- map:
- 1 -> 1
- 2 -> 2
- 3 -> 3
- 4 -> 4
- 5 -> 5
- AUTO -> 6
- SWING -> 6
on_value:
then:
- lambda: !lambda |-
if (x == "1") {
id(disp1).send_command_printf("hVane.pic=6");
id(disp1).send_command_printf("hVane.pic2=6");
} else if (x == "2") {
id(disp1).send_command_printf("hVane.pic=7");
id(disp1).send_command_printf("hVane.pic2=7");
} else if (x == "3") {
id(disp1).send_command_printf("hVane.pic=8");
id(disp1).send_command_printf("hVane.pic2=8");
} else if (x == "4") {
id(disp1).send_command_printf("hVane.pic=9");
id(disp1).send_command_printf("hVane.pic2=9");
} else if (x == "5") {
id(disp1).send_command_printf("hVane.pic=10");
id(disp1).send_command_printf("hVane.pic2=10");
} else if (x == "6") {
id(disp1).send_command_printf("hVane.pic=11");
id(disp1).send_command_printf("hVane.pic2=11");
}
- platform: homeassistant
id: fan_speed
entity_id: $target_thermostat
attribute: fan_mode
filters:
- map:
- 1 -> 1
- 2 -> 2
- 3 -> 3
- 4 -> 4
- AUTO -> 5
- QUIET -> 5
on_value:
then:
- lambda: !lambda |-
if (x == "1") {
id(disp1).send_command_printf("fanSpeed.pic=16");
id(disp1).send_command_printf("fanSpeed.pic2=16");
} else if (x == "2") {
id(disp1).send_command_printf("fanSpeed.pic=17");
id(disp1).send_command_printf("fanSpeed.pic2=17");
} else if (x == "3") {
id(disp1).send_command_printf("fanSpeed.pic=18");
id(disp1).send_command_printf("fanSpeed.pic2=18");
} else if (x == "4") {
id(disp1).send_command_printf("fanSpeed.pic=19");
id(disp1).send_command_printf("fanSpeed.pic2=19");
} else if (x == "5") {
id(disp1).send_command_printf("fanSpeed.pic=20");
id(disp1).send_command_printf("fanSpeed.pic2=20");
}
# Define some outputs
switch:
# The two relays
- platform: gpio
name: $device_name Relay 1
id: relay_1
pin:
number: 22
on_turn_on:
- lambda: 'id(disp1).send_command_printf("leftButton.pic=13");'
on_turn_off:
- lambda: 'id(disp1).send_command_printf("leftButton.pic=15");'
- platform: gpio
name: $device_name Relay 2
id: relay_2
pin:
number: 19
on_turn_on:
- lambda: 'id(disp1).send_command_printf("rightButton.pic=13");'
on_turn_off:
- lambda: 'id(disp1).send_command_printf("rightButton.pic=15");'
# Pin 4 always needs to be on to power up the display
- platform: gpio
id: screen_power
entity_category: config
pin:
number: 4
inverted: true
restore_mode: ALWAYS_ON
number:
platform: template
name: $device_name Brightness
id: brightness
entity_category: config
unit_of_measurement: '%'
min_value: 0
max_value: 100
step: 1
initial_value: 30
set_action:
then:
- lambda: 'id(disp1).set_backlight_brightness(x/100);'
script:
- id: refresh
then:
- lambda: |-
if (id(current_mode).state == "0") {
id(disp1).set_component_text_printf("targetTemp", "--""\xb0");
id(disp1).send_command_printf("vis heatActive,0");
id(disp1).send_command_printf("vis coolActive,0");
id(disp1).send_command_printf("vis dryActive,0");
id(disp1).send_command_printf("vis fanActive,0");
} else {
id(disp1).set_component_text_printf("targetTemp", "%i""\xb0", (int)id(target_temperature).state);
id(disp1).send_command_printf("vis heatActive,0");
id(disp1).send_command_printf("vis coolActive,0");
id(disp1).send_command_printf("vis dryActive,0");
id(disp1).send_command_printf("vis fanActive,0");
id(disp1).send_command_printf("vis %s,1", id(current_mode).state.c_str());
}
id(disp1).set_component_text_printf("currentTemp", "%i""\xb0", (int)id(current_temperature).state);
if (id(relay_1).state == 1) {
id(disp1).send_command_printf("leftButton.pic=13");
} else {
id(disp1).send_command_printf("leftButton.pic=15");
}
if (id(relay_2).state == 1) {
id(disp1).send_command_printf("rightButton.pic=13");
} else {
id(disp1).send_command_printf("rightButton.pic=15");
}
if (id(horizontal_vane).state == "1") {
id(disp1).send_command_printf("hVane.pic=6");
id(disp1).send_command_printf("hVane.pic2=6");
} else if (id(horizontal_vane).state == "2") {
id(disp1).send_command_printf("hVane.pic=7");
id(disp1).send_command_printf("hVane.pic2=7");
} else if (id(horizontal_vane).state == "3") {
id(disp1).send_command_printf("hVane.pic=8");
id(disp1).send_command_printf("hVane.pic2=8");
} else if (id(horizontal_vane).state == "4") {
id(disp1).send_command_printf("hVane.pic=9");
id(disp1).send_command_printf("hVane.pic2=9");
} else if (id(horizontal_vane).state == "5") {
id(disp1).send_command_printf("hVane.pic=10");
id(disp1).send_command_printf("hVane.pic2=10");
} else if (id(horizontal_vane).state == "6") {
id(disp1).send_command_printf("hVane.pic=11");
id(disp1).send_command_printf("hVane.pic2=11");
}
if (id(fan_speed).state == "1") {
id(disp1).send_command_printf("fanSpeed.pic=16");
id(disp1).send_command_printf("fanSpeed.pic2=16");
} else if (id(fan_speed).state == "2") {
id(disp1).send_command_printf("fanSpeed.pic=17");
id(disp1).send_command_printf("fanSpeed.pic2=17");
} else if (id(fan_speed).state == "3") {
id(disp1).send_command_printf("fanSpeed.pic=18");
id(disp1).send_command_printf("fanSpeed.pic2=18");
} else if (id(fan_speed).state == "4") {
id(disp1).send_command_printf("fanSpeed.pic=19");
id(disp1).send_command_printf("fanSpeed.pic2=19");
} else if (id(fan_speed).state == "5") {
id(disp1).send_command_printf("fanSpeed.pic=20");
id(disp1).send_command_printf("fanSpeed.pic2=20");
}
id(disp1).send_command_printf("brightnessVal.val=%i", (int)id(current_brightness).state);
id(disp1).send_command_printf("tempSlider.val=%i", (int)id(current_color_temp).state);
# Configure the internal bleeper
output:
- platform: ledc
id: buzzer_out
pin:
number: 21
# Enable ringtone music support
rtttl:
id: buzzer
output: buzzer_out
# Configure UART for communicating with the screen
uart:
id: tf_uart
tx_pin: 16
rx_pin: 17
baud_rate: 115200
# Configure the screen itself
display:
- platform: nextion
id: disp1
uart_id: tf_uart
tft_url: http://192.168.1.150:8123/local/NSPanel.tft
auto_wake_on_touch: true
update_interval: 2s
on_wake:
then:
- number.set:
id: brightness
value: 85
- script.execute: refresh
on_setup:
then:
- number.set:
id: brightness
value: 85
- script.execute: refresh