forked from konnected-io/konnected-esphome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alarm-panel-pro-esp32-local-alarm.yaml
431 lines (378 loc) · 11.1 KB
/
alarm-panel-pro-esp32-local-alarm.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
####
##
## Konnected Alarm Panel Pro (ESP32) Local Alarm
## Firmware configuration for ESPHome
##
## filename: alarm-panel-pro-esp32-local-alarm.yaml
## GitHub: https://github.com/konnected-io/konnected-esphome
## Buy Konnected hardware: https://konnected.io
## Help & Support: https://help@konnected.io (support is provided for purchasers of Konnected hardware)
##
## Inspired by and adapted from:
## https://github.com/jesserockz/esphome-configs/blob/main/alarm.yaml
##
## Originally licensed under MIT License with the following copyright notice:
## Copyright© 2022 Jesse Hills
##
## Copyright© 2023 Konnected Inc.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
## files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
## modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
## is furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
## OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
## LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
## IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
##
substitutions:
name: alarm-panel-pro
friendly_name: Alarm Panel Pro
project_name: konnected.alarm-panel-pro-esp32-local
project_version: "0.1.0"
sensor_debounce_time: 200ms
warning_beep_pulse_time: 100ms
warning_beep_pause_time: 130ms
warning_beep_internal_only: "false"
####
# ALARM CONFIG
alarm_code: !secret alarm_master_code
disarmed_state: '0'
arming_state: '1'
armed_away_state: '2'
armed_home_state: '3'
armed_night_state: '4'
pending_state: '5'
triggered_state: '6'
# yamllint disable-line rule:line-length
state_strings: '{"disarmed", "arming", "armed_away", "armed_home", "armed_night", "pending", "triggered"}'
####
# ZONE MAPPING
# Do not edit this section.
zone1: GPIO4
zone2: GPIO2
zone3: GPIO15
zone4: GPIO13
zone5: GPIO18
zone6: GPIO14
zone7: GPIO33
zone8: GPIO32
zone9: GPIO36
zone10: GPIO39
zone11: GPIO34
zone12: GPIO35
alarm1: GPIO12
alarm2: GPIO5
out1: GPIO23
out2: GPIO5
status_led: GPIO3
####
# CONNECTION MAPPINGS
warning_beep_pin: $out1
######### Exposed to HA ##########
# sensor.alarm_state
# - disarmed
# - arming
# - armed_away
# - armed_home
# - armed_night
# - pending
# - triggered
# service.esphome_${name}_arm
# service.esphome_${name}_arm_away
# service.esphome_${name}_disarm
# data:
# code: "XXXXXXX"
##################################
switch:
- platform: template
name: ${friendly_name} Trigger Siren
id: trigger_siren
icon: mdi:bullhorn
optimistic: true
entity_category: config
restore_mode: RESTORE_DEFAULT_OFF
####
# STATE MACHINE
# The logic of armed and disarmed states and transitions is defined here
external_components:
source: github://muxa/esphome-state-machine
components:
- state_machine
state_machine:
diagram: mermaid
initial_state: 'disarmed'
states:
- name: 'disarmed'
- name: 'arming'
on_enter:
- light.turn_on:
id: warning_beep
effect: strobe
- delay: !lambda return id(arming_timeout).state * 1000;
- state_machine.transition: arm_away
on_leave:
- light.turn_off: warning_beep
- name: 'armed_away'
- name: 'armed_home'
- name: 'armed_night'
- name: 'pending'
on_enter:
- light.turn_on:
id: warning_beep
effect: strobe
- delay: !lambda return id(pending_timeout).state * 1000;
- state_machine.transition: trigger
on_leave:
- light.turn_off: warning_beep
- name: 'triggered'
on_enter:
- if:
condition:
switch.is_on: trigger_siren
then:
- switch.turn_on: alarm1
- light.turn_on:
id: warning_beep
effect: strobe
- delay: !lambda return id(trigger_timeout).state * 60 * 1000;
- state_machine.transition: arm_away
on_leave:
- switch.turn_off: alarm1
- light.turn_off: warning_beep
inputs:
- name: arm_away
transitions:
- disarmed -> arming
- arming -> armed_away
- triggered -> armed_away
- name: arm_home
transitions:
- disarmed -> armed_home
- name: arm_night
transitions:
- disarmed -> armed_night
- name: disarm
transitions:
- arming -> disarmed
- armed_away -> disarmed
- armed_home -> disarmed
- armed_night -> disarmed
- pending -> disarmed
- triggered -> disarmed
- name: trip
transitions:
- armed_away -> pending
- armed_home -> pending
- armed_night -> pending
- name: trigger
transitions:
- armed_away -> triggered
- armed_home -> triggered
- armed_night -> triggered
- pending -> triggered
- name: failed_code
on_input:
- lambda: id(incorrect_codes) += 1;
- if:
condition:
lambda: return id(incorrect_codes) >= 3;
then:
- state_machine.transition: trigger
script:
- id: evaluate_alarm
then:
- if:
condition:
and:
- or:
- state_machine.state: armed_away
- state_machine.state: armed_home
- state_machine.state: armed_night
- or:
- lambda: return id(zone1).state;
- lambda: return id(zone2).state;
- lambda: return id(zone3).state;
- lambda: return id(zone4).state;
- lambda: return id(zone5).state;
- lambda: return id(zone6).state;
- lambda: return id(zone7).state;
- lambda: return id(zone8).state;
then:
- state_machine.transition: trip
globals:
- id: alarm_state_global
type: 'uint8_t'
restore_value: true
initial_value: '0'
- id: incorrect_codes
type: 'uint8_t'
restore_value: true
initial_value: '0'
sensor:
- platform: template
id: alarm_state
update_interval: 1s
lambda: return id(alarm_state_global);
filters:
- delta: 1
on_value:
- text_sensor.template.publish:
id: alarm_state_text
state: !lambda |-
static std::array<std::string, 7> strings = ${state_strings};
int y = (int) x;
return strings[y];
- platform: template
id: incorrect_codes_sensor
name: '${friendly_name} Incorrect Codes'
lambda: return id(incorrect_codes);
update_interval: never
text_sensor:
- platform: state_machine
id: alarm_state_text
name: ${friendly_name} State
- platform: template
id: ready_state
name: ${friendly_name} Ready
disabled_by_default: true
button:
- platform: template
name: Arm Away
on_press:
then:
- state_machine.transition: arm_away
- platform: template
name: Disarm
on_press:
then:
- state_machine.transition: disarm
number:
- platform: template
id: arming_timeout
name: ${friendly_name} Arming Timeout
restore_value: true
initial_value: 60
unit_of_measurement: seconds
min_value: 0
max_value: 300
step: 1
mode: box
optimistic: true
entity_category: config
- platform: template
id: pending_timeout
name: ${friendly_name} Pending Timeout
restore_value: true
initial_value: 60
unit_of_measurement: seconds
min_value: 0
max_value: 300
step: 1
mode: box
optimistic: true
entity_category: config
- platform: template
id: trigger_timeout
name: ${friendly_name} Trigger Timeout
restore_value: true
initial_value: 5
unit_of_measurement: minutes
min_value: 1
max_value: 20
step: 1
mode: box
optimistic: true
entity_category: config
####
# PACKAGES
# Each package includes the alarm panel feature
# Remove or comment out any packages that you do not need or want.
# If you're developing/installing locally, replace the github package line with the local package include above it.
packages:
remote_package:
url: http://github.com/konnected-io/konnected-esphome
ref: master
refresh: 5min
files:
####
# CORE
# This package is required and sets up core features.
- packages/alarm-panel-esp32-base.yaml
####
# WIFI
# Enables WiFi connectivity and diagnostics. Uncommet below to enable WiFi.
- packages/wifi.yaml
####
# STATUS LED
# Enables the onboard blue status LED as an activity/error indicator
- packages/status-led.yaml
####
# INPUT ZONES
- packages/alarm-panel/zone1.yaml
- packages/alarm-panel/zone2.yaml
- packages/alarm-panel/zone3.yaml
- packages/alarm-panel/zone4.yaml
- packages/alarm-panel/zone5.yaml
- packages/alarm-panel/zone6.yaml
- packages/alarm-panel/zone7.yaml
- packages/alarm-panel/zone8.yaml
- packages/alarm-panel/zone9.yaml
- packages/alarm-panel/zone10.yaml
- packages/alarm-panel/zone11.yaml
- packages/alarm-panel/zone12.yaml
####
# OUTPUTS
- packages/alarm-panel/alarm1.yaml
- packages/alarm-panel/alarm2.yaml
####
# WARNING BEEP
# Enables a 'Warning Beep' entity, intended to be used with a piezo buzzer. This is
# implemented using a light entity with strobe effect to create a repeated beeping sound.
- packages/warning-beep.yaml
dashboard_import:
package_import_url: github://konnected-io/konnected-esphome/alarm-panel-pro-esp32-local-alarm.yaml@master
import_full_config: false
####
# WEB SEVER
# Enables the built-in web server for viewing the device state, internals and controls via web browser
# on the same local network as the device.
web_server:
include_internal: true
####
# LOGGER
# more: https://esphome.io/components/logger.html
logger:
logs:
sensor: INFO
####
# NATIVE API for HOME ASSISTANT
# Enables the native API for Home Assistant
# more: https://esphome.io/components/api.html
api:
services:
- service: arm
then:
- state_machine.transition: arm_away
- service: arm_away
then:
- state_machine.transition: arm_away
- service: disarm
variables:
code: string
then:
- if:
condition:
lambda: return code == "${alarm_code}";
then:
- state_machine.transition: disarm
else:
- state_machine.transition: failed_code
####
# OTA UPDATES
# Enables over-the-air updates
# more: https://esphome.io/components/ota.html
ota: