-
Notifications
You must be signed in to change notification settings - Fork 1
/
nspanel.yml
274 lines (242 loc) · 6.86 KB
/
nspanel.yml
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
# NSPanel YAML by marcfager. Please check github for credits: https://github.com/marcfager/nspanel-mf
# Version 2022-01-19
substitutions:
# Name the device and it's entities
device_name: nspanel
# Example config.yaml
esphome:
name: nspanel
esp32:
board: esp32dev
# Wifi settings. Add these to your secrets.yaml. fast_connect must be true for a hidden ssid.
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
api:
services:
# Show idle screen
- service: set_idle
then:
- lambda: id(disp1).send_command_printf("page 0");
# Show alarm arm screen
- service: show_arm_screen
then:
- lambda: id(disp1).send_command_printf("page 1");
- rtttl.play:
rtttl: 'one short:d=4,o=5,b=100:16e6'
# Show armed popup
- service: show_armed_popup
then:
- lambda: id(disp1).send_command_printf("page 3");
# Show disarmed popup
- service: show_disarmed_popup
then:
- lambda: id(disp1).send_command_printf("page 4");
- rtttl.play:
rtttl: 'one high short:d=4,o=5,b=100:16e7'
# Show alarm disarm screen
- service: show_code_screen
variables:
status: string
then:
- lambda: id(disp1).send_command_printf("page 2");
- lambda: id(disp1).set_component_text_printf("CodeScreen.tStatus", "%s", status.c_str());
- rtttl.play:
rtttl: 'two short:d=4,o=5,b=100:8e6,8e6'
# Show alarm triggered screen
- service: show_triggered
then:
- lambda: id(disp1).send_command_printf("page 5");
- rtttl.play:
rtttl: 'siren:d=8,o=5,b=100:d,e,d,e,d,e,d,e'
# Service to play a rtttl tone
- service: play_rtttl
variables:
song_str: string
then:
- rtttl.play:
rtttl: !lambda 'return song_str;'
# Service to update the HMI file
- service: upload_tft
then:
- lambda: 'id(disp1)->upload_tft();'
# Service to control the visible page from Home Assistant
- service: set_page
variables:
page: int
then:
- lambda: id(disp1).send_command_printf("page %i", page);
# Service to send a command directly to the display. Useful for testing
- service: send_command
variables:
cmd: string
then:
- lambda: 'id(disp1).send_command_printf("%s", cmd.c_str());'
# Logger. Disable the temperature sensor etc. to focus on the HMI development
logger:
baud_rate: 0
level: DEBUG
logs:
sensor: WARN
resistance: WARN
text_sensor: WARN
ntc: WARN
# Uart for the Nextion display
uart:
tx_pin: 16
rx_pin: 17
baud_rate: 115200
id: tf_uart
# Functionality for the Nextion display
external_components:
- source: github://pr#2956
components: [nextion]
refresh: 1h
# A reboot button is always useful
button:
- platform: restart
name: $device_name Restart
# Binary sensors
binary_sensor:
# Left button below the display
- platform: gpio
name: $device_name Left Button
pin:
number: 14
inverted: true
on_click:
- switch.toggle: relay_1
# Right button below the display
- platform: gpio
name: $device_name Right Button
pin:
number: 27
inverted: true
on_click:
- switch.toggle: relay_2
output:
# Buzzer for playing tones
- platform: ledc
id: buzzer_out
pin:
number: 21
switch:
- platform: nextion
id: arm_button
name: "Arm button"
component_name: bArm
update_interval: 100ms
- platform: nextion
id: ok_button
name: "OK button"
component_name: bOk
update_interval: 100ms
# Physical relay 1
- platform: gpio
name: $device_name Relay 1
id: relay_1
pin:
number: 22
# Physical relay 2
- platform: gpio
name: $device_name Relay 2
id: relay_2
pin:
number: 19
# Basically a 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
- platform: gpio
id: screen_power
entity_category: config
pin:
number: 4
inverted: true
restore_mode: ALWAYS_ON
# Rtttl function for buzzer
rtttl:
id: buzzer
output: buzzer_out
sensor:
# Internal temperature sensor, adc value
- platform: adc
id: ntc_source
pin: 38
update_interval: 10s
attenuation: 11db
# Internal temperature sensor, adc reading converted to resistance (calculation)
- platform: resistance
id: resistance_sensor
sensor: ntc_source
configuration: DOWNSTREAM
resistor: 11.2kOhm
# Internal temperature sensor, resistance to temperature (calculation)
- platform: ntc
id: temperature
sensor: resistance_sensor
calibration:
b_constant: 3950
reference_temperature: 25°C
reference_resistance: 10kOhm
name: $device_name Temperature
# Uptime for the display. Also updates a human readable one (further down)
- platform: uptime
name: $device_name Uptime Sensor
id: uptime_sensor
update_interval: 60s
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? (to_string(days) + "d ") : "") +
(hours ? (to_string(hours) + "h ") : "") +
(minutes ? (to_string(minutes) + "m ") : "") +
(to_string(seconds) + "s")
).c_str();
# WiFi signals strength sensor
- platform: wifi_signal
name: $device_name WiFi Signal Sensor
update_interval: 60s
text_sensor:
- platform: nextion
name: $device_name code
component_name: varCode
update_interval: 200ms
# Uptime in a human readable form. Updated from the uptime sensor
- platform: template
name: $device_name Uptime Human Readable
id: uptime_human
icon: mdi:clock-start
# ESPHome version used to compile the app
- platform: version
name: $device_name ESPHome Version
# Configure the screen itself
display:
- platform: nextion
id: disp1
uart_id: tf_uart
tft_url: "http://192.168.1.1:8123/local/nextion/alarm.tft"
# A little fun...
on_setup:
then:
- lambda: id(disp1).send_command_printf("page 0");
- wait_until:
api.connected
- switch.template.publish:
id: nextion_init
state: on
- lambda: id(disp1).send_command_printf("dim=0");