· 4 years ago · Jun 23, 2021, 05:52 PM
1esphome:
2 name: sonoff-4ch-pro-1
3 platform: ESP8266
4 board: esp01_1m
5
6wifi:
7 ssid: "chuck"
8 password: "*******"
9 manual_ip:
10 static_ip: 192.168.0.104
11 gateway: 192.168.0.1
12 subnet: 255.255.255.0
13 power_save_mode: none
14 fast_connect: true
15
16substitutions:
17 rel1_gpio: GPIO12
18 rel2_gpio: GPIO5
19 rel3_gpio: GPIO4
20 rel4_gpio: GPIO15
21 key1_gpio: GPIO0
22 key2_gpio: GPIO9
23 key3_gpio: GPIO10
24 key4_gpio: GPIO14
25 rx_gpio: GPIO3
26 tx_gpio: GPIO1
27
28globals:
29 - id: time1
30 type: int
31 restore_value: no
32 initial_value: '3600'
33 - id: time2
34 type: int
35 restore_value: no
36 initial_value: '3600'
37 - id: time3
38 type: int
39 restore_value: no
40 initial_value: '3600'
41 - id: time4
42 type: int
43 restore_value: no
44 initial_value: '3600'
45 - id: remaining_time1
46 type: int
47 restore_value: no
48 initial_value: '3600'
49 - id: remaining_time2
50 type: int
51 restore_value: no
52 initial_value: '3600'
53 - id: remaining_time3
54 type: int
55 restore_value: no
56 initial_value: '3600'
57 - id: remaining_time4
58 type: int
59 restore_value: no
60 initial_value: '3600'
61 - id: new_time1
62 type: int
63 restore_value: no
64 initial_value: '3600'
65 - id: new_time2
66 type: int
67 restore_value: no
68 initial_value: '3600'
69 - id: new_time3
70 type: int
71 restore_value: no
72 initial_value: '3600'
73 - id: new_time4
74 type: int
75 restore_value: no
76 initial_value: '3600'
77
78uart:
79 rx_pin: $rx_gpio
80 tx_pin: $tx_gpio
81 baud_rate: 115200
82
83display:
84 - platform: nextion
85 id: irrigation
86 update_interval: 1s
87 lambda: |-
88
89 it.set_wait_for_ack(false);
90
91 if(id(set_relay1_time).state){
92 it.set_component_text_printf("button1","%2d:%02d:%02d",id(new_time1)/3600,(id(new_time1)%3600)/60,(id(new_time1)%3600)%60);
93 }
94 if(id(set_relay2_time).state){
95 it.set_component_text_printf("button2","%2d:%02d:%02d",id(new_time2)/3600,(id(new_time2)%3600)/60,(id(new_time2)%3600)%60);
96 }
97 if(id(set_relay3_time).state){
98 it.set_component_text_printf("button3","%2d:%02d:%02d",id(new_time3)/3600,(id(new_time3)%3600)/60,(id(new_time3)%3600)%60);
99 }
100 if(id(set_relay4_time).state){
101 it.set_component_text_printf("button4","%2d:%02d:%02d",id(new_time4)/3600,(id(new_time4)%3600)/60,(id(new_time4)%3600)%60);
102 }
103
104 if(id(relay1).state){
105 it.set_component_text_printf("time1","%2d:%02d:%02d",id(remaining_time1)/3600,(id(remaining_time1)%3600)/60,(id(remaining_time1)%3600)%60);
106 it.set_component_text("button5","On");
107 it.set_component_background_color("button5","1024");
108 } else{
109 it.set_component_text("time1","");
110 it.set_component_text("button5","Off");
111 it.set_component_background_color("button5","63488");
112 }
113
114 if(id(relay2).state){
115 it.set_component_text_printf("time2","%2d:%02d:%02d",id(remaining_time2)/3600,(id(remaining_time2)%3600)/60,(id(remaining_time2)%3600)%60);
116 it.set_component_text("button6","On");
117 } else{
118 it.set_component_text("time2","");
119 it.set_component_text("button6","Off");
120 }
121
122 if(id(relay3).state){
123 it.set_component_text_printf("time3","%2d:%02d:%02d",id(remaining_time3)/3600,(id(remaining_time3)%3600)/60,(id(remaining_time3)%3600)%60);
124 it.set_component_text("button7","On");
125 } else{
126 it.set_component_text("time3","");
127 it.set_component_text("button7","Off");
128 }
129
130 if(id(relay4).state){
131 it.set_component_text_printf("time4","%2d:%02d:%02d",id(remaining_time4)/3600,(id(remaining_time4)%3600)/60,(id(remaining_time4)%3600)%60);
132 it.set_component_text("button8","On");
133 } else{
134 it.set_component_text("time4","");
135 it.set_component_text("button8","Off");
136 }
137
138binary_sensor:
139 - platform: gpio
140 id: key1
141 pin:
142 number: $key1_gpio
143 mode: INPUT_PULLUP
144 inverted: True
145 filters:
146 - delayed_on: 125ms
147 on_press:
148 then:
149 - switch.toggle: relay1
150 - platform: gpio
151 id: key2
152 pin:
153 number: $key2_gpio
154 mode: INPUT_PULLUP
155 inverted: True
156 filters:
157 - delayed_on: 125ms
158 on_press:
159 then:
160 - switch.toggle: relay2
161 - platform: gpio
162 id: key3
163 pin:
164 number: $key3_gpio
165 mode: INPUT_PULLUP
166 inverted: True
167 filters:
168 - delayed_on: 125ms
169 on_press:
170 then:
171 - switch.toggle: relay3
172 - platform: gpio
173 id: key4
174 pin:
175 number: $key4_gpio
176 mode: INPUT_PULLUP
177 inverted: True
178 filters:
179 - delayed_on: 125ms
180 on_press:
181 then:
182 - switch.toggle: relay4
183 - platform: status
184 name: "Sonoff 4CH Pro 1 WiF1"
185
186 - platform: nextion
187 page_id: 0
188 component_id: 2
189 nextion_id: irrigation
190 id: button1
191 filters:
192 - delayed_on_off: 125ms
193 on_press:
194 then:
195 - switch.toggle: set_relay1_time
196 - lambda: |-
197
198 if (id(new_time1) >= 7200) {
199 id(new_time1) = 900;
200 } else {
201 id(new_time1) += 900;
202 }
203 - globals.set:
204 id: new_time1
205 value: !lambda "return id(new_time1);"
206 - globals.set:
207 id: time1
208 value: !lambda "return id(new_time1);"
209 - platform: nextion
210 page_id: 0
211 component_id: 3
212 nextion_id: irrigation
213 id: button2
214 filters:
215 - delayed_on_off: 125ms
216 on_press:
217 then:
218 - switch.toggle: set_relay2_time
219 - lambda: |-
220
221 if (id(new_time2) >= 7200) {
222 id(new_time2) = 900;
223 } else {
224 id(new_time2) += 900;
225 }
226 - globals.set:
227 id: new_time2
228 value: !lambda "return id(new_time2);"
229 - platform: nextion
230 page_id: 0
231 component_id: 4
232 nextion_id: irrigation
233 id: button3
234 filters:
235 - delayed_on_off: 125ms
236 on_press:
237 then:
238 - switch.toggle: set_relay3_time
239 - lambda: |-
240
241 if (id(new_time3) >= 7200) {
242 id(new_time3) = 900;
243 } else {
244 id(new_time3) += 900;
245 }
246 - globals.set:
247 id: new_time3
248 value: !lambda "return id(new_time3);"
249 - platform: nextion
250 page_id: 0
251 component_id: 5
252 nextion_id: irrigation
253 id: button4
254 filters:
255 - delayed_on_off: 125ms
256 on_press:
257 then:
258 - switch.toggle: set_relay4_time
259 - lambda: |-
260
261 if (id(new_time4) >= 7200) {
262 id(new_time4) = 900;
263 } else {
264 id(new_time4) += 900;
265 }
266 - globals.set:
267 id: new_time4
268 value: !lambda "return id(new_time4);"
269
270 - platform: nextion
271 page_id: 0
272 component_id: 6
273 nextion_id: irrigation
274 id: button5
275 filters:
276 - delayed_on_off: 125ms
277 on_press:
278 then:
279 - switch.toggle: relay1
280
281 - platform: nextion
282 page_id: 0
283 component_id: 7
284 nextion_id: irrigation
285 id: button6
286 filters:
287 - delayed_on_off: 125ms
288 on_press:
289 then:
290 - switch.toggle: relay2
291
292 - platform: nextion
293 page_id: 0
294 component_id: 8
295 nextion_id: irrigation
296 id: button7
297 filters:
298 - delayed_on_off: 125ms
299 on_press:
300 then:
301 - switch.toggle: relay3
302
303 - platform: nextion
304 page_id: 0
305 component_id: 9
306 nextion_id: irrigation
307 id: button8
308 filters:
309 - delayed_on_off: 125ms
310 on_press:
311 then:
312 - switch.toggle: relay4
313
314switch:
315 - platform: gpio
316 id: relay1
317 name: "irrigation_relay1"
318 pin: $rel1_gpio
319 interlock: [relay2,relay3,relay4]
320 restore_mode: ALWAYS_OFF
321 on_turn_on:
322 then:
323 - globals.set:
324 id: remaining_time1
325 value: !lambda "return id(time1);"
326 - platform: gpio
327 id: relay2
328 name: "irrigation_relay2"
329 pin: $rel2_gpio
330 interlock: [relay1,relay3,relay4]
331 restore_mode: ALWAYS_OFF
332 on_turn_on:
333 then:
334 - globals.set:
335 id: remaining_time2
336 value: !lambda "return id(time2);"
337 - platform: gpio
338 id: relay3
339 name: "irrigation_relay3"
340 pin: $rel3_gpio
341 interlock: [relay1,relay2,relay4]
342 restore_mode: ALWAYS_OFF
343 on_turn_on:
344 - globals.set:
345 id: remaining_time3
346 value: !lambda "return id(time3);"
347 - platform: gpio
348 id: relay4
349 name: "irrigation_relay4"
350 pin: $rel4_gpio
351 interlock: [relay1,relay2,relay3]
352 restore_mode: ALWAYS_OFF
353 on_turn_on:
354 - globals.set:
355 id: remaining_time4
356 value: !lambda "return id(time4);"
357
358 - platform: template
359 name: "Set Relay1 Time"
360 id: set_relay1_time
361 turn_on_action:
362 - then:
363 - switch.template.publish:
364 id: set_relay1_time
365 state: ON
366 - delay: 2s
367 turn_off_action:
368 - then:
369 - switch.template.publish:
370 id: set_relay1_time
371 state: OFF
372 - platform: template
373 name: "Set Relay2 Time"
374 id: set_relay2_time
375 turn_on_action:
376 - then:
377 - globals.set:
378 id: time2
379 value: !lambda "return id(new_time2);"
380 - switch.template.publish:
381 id: set_relay2_time
382 state: ON
383 - delay: 2s
384 turn_off_action:
385 - then:
386 - switch.template.publish:
387 id: set_relay2_time
388 state: OFF
389 - platform: template
390 name: "Set Relay3 Time"
391 id: set_relay3_time
392 turn_on_action:
393 - then:
394 - globals.set:
395 id: time3
396 value: !lambda "return id(new_time3);"
397 - switch.template.publish:
398 id: set_relay3_time
399 state: ON
400 - delay: 2s
401 turn_off_action:
402 - then:
403 - switch.template.publish:
404 id: set_relay3_time
405 state: OFF
406 - platform: template
407 name: "Set Relay4 Time"
408 id: set_relay4_time
409 turn_on_action:
410 - then:
411 - globals.set:
412 id: time4
413 value: !lambda "return id(new_time4);"
414 - switch.template.publish:
415 id: set_relay4_time
416 state: ON
417 - delay: 2s
418 turn_off_action:
419 - then:
420 - switch.template.publish:
421 id: set_relay4_time
422 state: OFF
423
424interval:
425 - interval: 1s
426 then:
427 - lambda: |-
428
429 if(id(relay1).state) {
430 id(remaining_time1)=id(remaining_time1)-1;
431 if(id(remaining_time1)<=0){
432 id(relay1).turn_off();
433 }
434 }
435 if(id(relay2).state) {
436 id(remaining_time2)=id(remaining_time2)-1;
437 if(id(remaining_time2)<=0){
438 id(relay2).turn_off();
439 }
440 }
441 if(id(relay3).state) {
442 id(remaining_time3)=id(remaining_time3)-1;
443 if(id(remaining_time3)<=0){
444 id(relay3).turn_off();
445 }
446 }
447 if(id(relay4).state) {
448 id(remaining_time4)=id(remaining_time4)-1;
449 if(id(remaining_time4)<=0){
450 id(relay4).turn_off();
451 }
452 }
453
454captive_portal:
455
456logger:
457 baud_rate: 0
458
459api:
460
461ota:
462
463output:
464 # Register the blue LED as a dimmable output ....
465 - platform: esp8266_pwm
466 id: blue_led
467 pin: GPIO13
468 inverted: True
469
470light:
471 # ... and then make a light out of it.
472 - platform: monochromatic
473 name: "Set Time Blue LED"
474 output: blue_led
475
476web_server:
477 port: 80
478
479