-
Notifications
You must be signed in to change notification settings - Fork 0
/
original.yaml
328 lines (299 loc) · 8.46 KB
/
original.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
# Sonoff:
# relay_gpio: GPIO12
# button_gpio: GPIO0
# led_gpio: GPIO13
# Tuya:
# button_gpio: GPIO1
# relay_gpio: GPIO14
# led_gpio: GPIO13
esphome:
name: ${devicename}
platform: ESP8266
board: esp01_1m
on_loop:
then:
- if:
condition:
not:
- script.is_running: pulse_led
then:
- script.execute: pulse_led
ota:
password: ""
time:
- platform: homeassistant
id: homeassistant_time
wifi:
ssid: ""
password: ""
manual_ip:
static_ip: ${deviceip}
gateway: 192.168.1.1
subnet: 255.255.255.0
ap:
ssid: "ESPHome ${real_devicename}"
# Enable logging
logger:
baud_rate: 0
# logs:
# light: WARN
# Enable Home Assistant API
api:
password: ""
services:
- service: start_timer_seconds
variables:
timer: int
relay_run_id: int
then:
- lambda: 'id(timer_time) = timer;'
- lambda: 'id(template_relay_id) = relay_run_id;'
- script.execute: run_timer_seconds
- service: start_timer_minutes
variables:
timer: int
relay_run_id: int
then:
- lambda: 'id(timer_time) = timer*60;'
- lambda: 'id(template_relay_id) = relay_run_id;'
- script.execute: run_timer_seconds
- service: start_timer_hours
variables:
timer: int
relay_run_id: int
then:
- lambda: 'id(timer_time) = timer*60*60;'
- lambda: 'id(template_relay_id) = relay_run_id;'
- script.execute: run_timer_seconds
- service: cancel_timer
then:
- script.execute: cancel_all
globals:
- id: timer_time
type: int
restore_value: no
initial_value: '0'
- id: template_relay_id
type: int
restore_value: no
initial_value: '0'
- id: relay_status # relay number if activated; else 0
type: int
restore_value: no
initial_value: '0'
- id: connection_status # 0 if all fine, 1 wifi disconnected, 2 api disconnected
type: int
restore_value: no
initial_value: '0'
- id: connection_progress_bar # looping progress indicator, visual only
type: int
restore_value: no
initial_value: '0'
script:
- id: pulse_led
then:
- lambda: |-
if (!(wifi_wificomponent->is_connected())) {
id(connection_status) = 1;
} else if (!(api_apiserver->is_connected())) {
id(connection_status) = 2;
} else {
id(connection_status) = 0;
}
if (id(connection_status) != 0) {
if (id(connection_progress_bar) + 1 > 4) {
id(connection_progress_bar) = 2;
} else {
id(connection_progress_bar) += 1;
}
} else {
id(connection_progress_bar) = 0;
}
- if:
condition:
lambda: 'return (id(connection_status) == 1);'
then:
- if:
condition:
lambda: 'return id(relay_status) != 0;'
then:
- script.execute: pulse_led_relay_on_api
- script.wait: pulse_led_relay_on_api
- script.execute: check_relay_then_turn_light_on_off
- script.wait: check_relay_then_turn_light_on_off
else:
- script.execute: pulse_led_standard_api
- script.wait: pulse_led_standard_api
- script.execute: check_relay_then_turn_light_on_off
- script.wait: check_relay_then_turn_light_on_off
else:
- if:
condition:
lambda: 'return (id(connection_status) == 2);'
then:
- if:
condition:
lambda: 'return id(relay_status) != 0;'
then:
- script.execute: pulse_led_relay_on_api
- script.wait: pulse_led_relay_on_api
- script.execute: check_relay_then_turn_light_on_off
- script.wait: check_relay_then_turn_light_on_off
else:
- script.execute: pulse_led_standard_api
- script.wait: pulse_led_standard_api
- script.execute: check_relay_then_turn_light_on_off
- script.wait: check_relay_then_turn_light_on_off
# else:
# - script.execute: check_relay_then_turn_light_on_off
# - script.wait: check_relay_then_turn_light_on_off
- id: pulse_led_relay_on_api
then:
- light.turn_on:
id: led_1
brightness: 100%
transition_length: 250ms
- delay: 250ms
- light.turn_on:
id: led_1
brightness: 50%
transition_length: 250ms
- delay: 250ms
- id: pulse_led_standard_api
then:
- light.turn_on:
id: led_1
brightness: 100%
transition_length: 1s
- delay: 1s
- light.turn_off:
id: led_1
transition_length: 750ms
- delay: 750ms
- id: run_timer_seconds
then:
- if:
condition:
- lambda: 'return id(timer_time) > 0;'
then:
- logger.log:
format: "Starting Relay"
- script.execute: turn_on_template_relay_id
- id: timer_end_sequence
then:
- script.execute: turn_off_template_relay_id
- lambda: 'id(timer_time) = 0;'
- lambda: 'id(template_relay_id) = 0;'
- id: cancel_all
then:
- lambda: 'id(timer_time) = 0;'
- lambda: 'id(template_relay_id) = 0;'
- id: check_relay_then_turn_light_on_off
then:
- delay: 1ms
- script.execute: update_relay_state
- script.wait: update_relay_state
- if:
condition:
lambda: 'return id(relay_status) != 0;'
then:
- light.turn_on:
id: led_1
brightness: 100%
else:
- light.turn_off:
id: led_1
- id: turn_on_template_relay_id
then: # new if for each relay
- lambda: |-
if (id(template_relay_id) == 1) {
id(template_relay_1).turn_on();
}
- id: turn_off_template_relay_id
then:
- lambda: |-
if (id(template_relay_id) == 1) {
id(template_relay_1).turn_off();
}
- id: update_relay_state
then:
- lambda: |-
if (id(template_relay_1).state) {
id(relay_status) = 1;
} else {
id(relay_status) = 0;
}
# Button triggers template which turns on led and relay
binary_sensor:
- platform: gpio
pin:
number: ${button_gpio}
mode: INPUT_PULLUP
inverted: True
id: button
on_click:
- min_length: 50ms
max_length: 750ms
then:
- switch.toggle: template_relay_1
- min_length: 3000ms
max_length: 6000ms
then:
- switch.turn_on: "${devicename}_restart"
switch:
- platform: gpio
pin: ${relay_gpio}
id: relay_1
# interlock: &interlock_group [relay_1, relay_2]
# - platform: gpio
# pin: ${relay_gpio}
# id: relay_2
# interlock: *interlock_group
- platform: restart
id: "${devicename}_restart"
- platform: template
name: "${real_devicename} Switch 1"
id: template_relay_1
lambda: |-
if (id(relay_1).state) {
return true;
} else {
return false;
}
turn_on_action:
then:
- switch.turn_on: relay_1
- script.execute: check_relay_then_turn_light_on_off
turn_off_action:
- switch.turn_off: relay_1
- script.execute: check_relay_then_turn_light_on_off
# Define led output pin
output:
- platform: esp8266_pwm
id: basic_led
inverted: True
pin: ${led_gpio}
# Setup light
light:
- platform: monochromatic
id: led_1
output: basic_led
default_transition_length: 0s
interval:
- interval: 1s
then:
- if:
condition:
- lambda: 'return id(timer_time) > 0;'
then:
- lambda: |-
id(timer_time) -= 1;
ESP_LOGD("timer", "Time Remaining: %d", id(timer_time));
- if:
condition:
- lambda: 'return id(timer_time) <= 0;'
then:
- script.execute: timer_end_sequence
#Built in webserver
web_server:
port: 80