-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnspanel-lab02.yaml
335 lines (292 loc) · 7.31 KB
/
nspanel-lab02.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
#Darijo NSPanel-LAB02
# Set some variables for convenience
substitutions:
node_name: nspanel-lab02
device_name: NSPanel-LAB02
tft_prefix: !secret tft_prefix
# Note: this may not be needed if the pull request has been merged.
# Check https://github.com/esphome/esphome/pull/2956 for current status.
external_components:
- source: github://pr#2956
components: [nextion]
refresh: 1h
esphome:
name: $node_name
comment: $device_name
esp32:
board: esp32dev
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable logging
logger:
# Enable wireless updates
ota:
password: !secret ota_pwd
# 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());'
# Sync the time
time:
- platform: homeassistant
id: homeassistant_time
on_time:
- seconds: 0
minutes: '*'
then:
- lambda: |-
auto time_text = id(homeassistant_time).now().strftime("%I:%M%p");
id(disp1).set_component_text("time", time_text.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_release:
lambda: 'id(disp1).send_command_printf("click screensaver,0");'
- platform: gpio
name: $device_name Right Button
pin:
number: 27
inverted: true
on_release:
lambda: 'id(disp1).send_command_printf("click screensaver,0");'
- platform: nextion
name: $device_name Dim Up Taklampa
page_id: 0
component_id: 13
- platform: nextion
name: $device_name Dim Up Fönsterlampa
page_id: 0
component_id: 14
- platform: nextion
name: $device_name Dim Up Bokhylla
page_id: 0
component_id: 15
- platform: nextion
name: $device_name Dim Up Golvlampa
page_id: 0
component_id: 16
- platform: nextion
name: $device_name On/Off Taklampa
page_id: 0
component_id: 9
- platform: nextion
name: $device_name On/Off Fönsterlampa
page_id: 0
component_id: 10
- platform: nextion
name: $device_name On/Off Bokhylla
page_id: 0
component_id: 11
- platform: nextion
name: $device_name On/Off Golvlampa
page_id: 0
component_id: 12
- platform: nextion
name: $device_name Dim Ner Taklampa
page_id: 0
component_id: 17
- platform: nextion
name: $device_name Dim Ner Fönsterlampa
page_id: 0
component_id: 18
- platform: nextion
name: $device_name Dim Ner Bokhylla
page_id: 0
component_id: 19
- platform: nextion
name: $device_name Dim Ner Golvlampa
page_id: 0
component_id: 20
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: sovrum_temperature
entity_id: sensor.temperature_158d0001a64b7c
on_value:
then:
- wait_until:
switch.is_on: nextion_init
- lambda: id(disp1).set_component_text_printf("home.temp", "%.0f", id(sovrum_temperature).state);
#Text Sensors
text_sensor:
## LIGHTS ##
# Light Taklampa
- platform: homeassistant
id: first
entity_id: light.taklampa_vardagsrum
on_value:
then:
- wait_until:
switch.is_on: nextion_init
- lambda: |-
int symbol = 2;
if (id(first).state == "on") {
symbol=3;
}
id(disp1).send_command_printf("home.p_tak.pic=%i", symbol);
# Light Fonsterlampa
- platform: homeassistant
id: second
entity_id: light.fonsterlampa_vardagsrum
on_value:
then:
- wait_until:
switch.is_on: nextion_init
- lambda: |-
int symbol = 4;
if (id(first).state == "on") {
symbol=5;
}
id(disp1).send_command_printf("home.p_fonster.pic=%i", symbol);
# Light Bokhylla
- platform: homeassistant
id: third
entity_id: light.bokhylla_vardagsrum
on_value:
then:
- wait_until:
switch.is_on: nextion_init
- lambda: |-
int symbol = 6;
if (id(first).state == "on") {
symbol=7;
}
id(disp1).send_command_printf("home.p_bok.pic=%i", symbol);
# Light Golvlampa
- platform: homeassistant
id: fourth
entity_id: light.golvlampa_vardagsrum
on_value:
then:
- wait_until:
switch.is_on: nextion_init
- lambda: |-
int symbol = 8;
if (id(first).state == "on") {
symbol=9;
}
id(disp1).send_command_printf("home.p_golv.pic=%i", symbol);
# Define some outputs
switch:
# global variable to keep track on whether the Nextion display is ready or not. Delays initial info from HA to the display.
- platform: template
name: $device_name Nextion inited
id: nextion_init
entity_category: config
restore_state: false
assumed_state: off
optimistic: true
# Physical switch #1
- platform: gpio
name: $device_name Relay 1
id: relay_1
pin:
number: 22
# Physical switch #2
- platform: gpio
name: $device_name Relay 2
id: relay_2
pin:
number: 19
# 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: 25
set_action:
then:
- lambda: 'id(disp1).set_backlight_brightness(x/100);'
# 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: $tft_prefix/$node_name.tft
on_setup:
then:
- number.set:
id: brightness
value: 25
- wait_until:
api.connected
- switch.template.publish:
id: nextion_init
state: on