-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalarmlicht.yaml
260 lines (248 loc) · 8.03 KB
/
alarmlicht.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
esphome:
name: esp-alarmlicht
on_boot:
then:
# disable all LEDs and REL1 on boot
- output.turn_off: testbutton_led
- output.turn_off: alarmlicht_led
- output.turn_off: wifi_connected_led
- output.turn_off: relay_1
http_request:
useragent: esphome/esp-alarmlicht
id: http_request_data
# set timeout to prevent - delay: 2srestart due to watchdog timeout (https://github.com/esphome/issues/issues/2853#issuecomment-1366086914)
timeout: 1s
esp32:
board: esp32-evb
framework:
type: arduino
# global variables for enabling/disabling test alerts
# and alerts via API calls
globals:
- id: global_send_divera_testalarm
type: bool
initial_value: 'true'
- id: global_send_ntfy_testalarm
type: bool
initial_value: 'true'
- id: global_send_divera_alarm
type: bool
initial_value: 'true'
- id: global_send_ntfy_alarm
type: bool
initial_value: 'false'
# is set to true when a alert is received
# will be set to false when alert has been transmitted
# will be checked on wifi reconnect
- id: global_alert_pending
type: bool
initial_value: 'false'
# as modularisation is not easy there is only send-alerts.yaml for
# handling both: real and test alerts
# global_alert_type_test is used for distinguishing between them
# global_alert_type_test = false -> alert
# global_alert_type_test = true -> test alert
# caution:
# has to be set before including send-alerts.yaml and reset afterwards. e.g
# - lambda: 'id(global_alert_type_test) = true;'
# - <<: !include {file: send-alerts.yaml,
# …
# - lambda: 'id(global_pending_alert_type_test) = false;'
- id: global_alert_type_test
type: bool
initial_value: 'false'
# wether the pending alert is test or real alert
- id: global_pending_alert_type_test
type: bool
initial_value: 'false'
# failed http request and retry handling
# set to true when request failed
- id: global_divera_http_request_failed
type: bool
initial_value: 'false'
# max number of retries when failed
- id: global_divera_http_request_max_retries
type: int
initial_value: '5'
# counter for retries
- id: global_divera_http_request_count
type: int
initial_value: '0'
substitutions:
relay_on_time: 300ms
divera_type_alert: "🚒ALARM!!!1elf (oder Einsatz)🚒"
ntfy_title_alert: "🚒ALARM!!!1elf (oder Einsatz)🚒"
ntfy_priority_alert: "urgent"
ntfy_tags_alert: "loudspeaker, rotating_light"
ntfy_body_alert: "Der DME löste aus."
divera_type_test: "🤷Testalarm (🔘 am Alarmlicht)🤷"
ntfy_title_test: "🤷Testalarm (🔘 am ESP-Alarmlicht)🤷"
ntfy_priority_test: "default"
ntfy_tags_test: "loudspeaker, construction"
ntfy_body_test: "Es drückte jemand den Testbutton am ESP-Alarmlicht und erfreut uns mit dieser Nachricht."
# Enable logging
logger:
# level: VERBOSE
level: DEBUG
# level: INFO
wifi:
networks:
- ssid: !secret first_wifi_ssid
password: !secret first_wifi_password
- ssid: !secret second_wifi_ssid
password: !secret second_wifi_password
power_save_mode: none
id: 'wifi_id'
output:
- platform: gpio
id: testbutton_led
pin: GPIO23
- platform: gpio
id: alarmlicht_led
pin: GPIO21
- platform: gpio
id: wifi_connected_led
pin: GPIO14
- platform: gpio
id: relay_1
pin: GPIO32
interval:
# let wifi_connected_led flash every 3s
- interval: 3s
then:
if:
condition:
wifi.connected:
then:
- output.turn_on: wifi_connected_led
- delay: 0.05s
- output.turn_off: wifi_connected_led
else:
- output.turn_off: wifi_connected_led
# check if there are pending alerts every 10 s
- interval: 10s
then:
if:
condition:
wifi.connected:
then:
# check if global_alert_pending flag was set and process a pending alert
if:
condition:
lambda: 'return id(global_alert_pending);'
then:
- logger.log:
format: "Pending alert found."
level: INFO
- if:
condition:
lambda: 'return id(global_pending_alert_type_test);'
then:
- lambda: 'id(global_alert_type_test) = true;'
- <<: !include {file: send-alerts.yaml,
vars:
{
divera_type: '${divera_type_test}',
ntfy_title: '${ntfy_title_test}',
ntfy_priority: '${ntfy_priority_test}',
ntfy_tags: '${ntfy_tags_test}',
ntfy_body: '${ntfy_body_test}'
}
}
else:
- lambda: 'id(global_alert_type_test) = false;'
- <<: !include {file: send-alerts.yaml,
vars:
{
divera_type: '${divera_type_alert}',
ntfy_title: '${ntfy_title_alert}',
ntfy_priority: '${ntfy_priority_alert}',
ntfy_tags: '${ntfy_tags_alert}',
ntfy_body: '${ntfy_body_alert}'
}
}
- interval: 5s
then:
# if the wifi is connected and http process failed, process it for resending the request
- while:
condition:
and:
- wifi.connected
- lambda: 'return id(global_divera_http_request_failed);'
then:
- lambda: 'id(global_alert_type_test) = false;'
- <<: !include {file: send-alerts.yaml,
vars:
{
divera_type: '${divera_type_alert}',
ntfy_title: '${ntfy_title_alert}',
ntfy_priority: '${ntfy_priority_alert}',
ntfy_tags: '${ntfy_tags_alert}',
ntfy_body: '${ntfy_body_alert}'
}
}
# delay is needed to get some time for the watchdog
# if omitted software will crash
- delay: 2s
binary_sensor:
# When the BUT1 is pressed, on-but1-press.yaml is included
# for sending test alerts via HTTP requests and turning on a LED
# and the relay
# on release, the LED will be switched off
- platform: gpio
pin: GPIO34
name: "BUT1"
filters:
- invert:
on_press:
!include
file: on-but1-press.yaml
vars:
divera_type: ${divera_type_test}
ntfy_title: ${ntfy_title_test}
ntfy_priority: ${ntfy_priority_test}
ntfy_tags: ${ntfy_tags_test}
ntfy_body: ${ntfy_body_test}
on_release:
then:
- output.turn_off: testbutton_led
# When GPIO16 is pulled down (remote for switching on the light is used),
# the alarmlicht_led is turned on and REL1 is switched on for
# activating the lights.
- platform: gpio
pin: GPIO16
name: "Funklicht"
filters:
- invert:
on_press:
- logger.log:
format: "Light switched on by remote control."
level: INFO
- output.turn_on: alarmlicht_led
- output.turn_on: relay_1
- delay: ${relay_on_time}
- output.turn_off: relay_1
on_release:
then:
- output.turn_off: alarmlicht_led
- platform: gpio
# When the GPIO18 is pulled down, on-message-receive.yaml is included
# for sending alerts via HTTP requests, turning on a LED
# and the relay
# on release, the LED will be switched off
pin: GPIO18
name: "DME Relais"
filters:
- invert:
on_press:
!include
file: on-message-receive.yaml
vars:
divera_type: ${divera_type_alert}
ntfy_title: ${ntfy_title_alert}
ntfy_priority: ${ntfy_priority_alert}
ntfy_tags: ${ntfy_tags_alert}
ntfy_body: ${ntfy_body_alert}
on_release:
then:
- output.turn_off: alarmlicht_led