· 4 years ago · Jun 27, 2021, 08:16 PM
1esphome:
2 name: sonoff-4ch-pro-1
3 platform: ESP8266
4 board: esp01_1m
5
6wifi:
7 ssid: "chuck"
8 password: "264060303"
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 id: uart_2
80 rx_pin: $rx_gpio
81 tx_pin: $tx_gpio
82 baud_rate: 9600
83
84display:
85 - platform: nextion
86 id: nextion1
87 uart_id: uart_2
88 lambda: |-
89
90 it.set_component_text_printf("button1","%2d:%02d:%02d",id(time1)/3600,(id(time1)%3600)/60,(id(time1)%3600)%60);
91
92binary_sensor:
93 - platform: gpio
94 id: key1
95 pin:
96 number: $key1_gpio
97 mode: INPUT_PULLUP
98 inverted: True
99 filters:
100 - delayed_on: 125ms
101 on_press:
102 then:
103 - switch.toggle: relay1
104 - platform: gpio
105 id: key2
106 pin:
107 number: $key2_gpio
108 mode: INPUT_PULLUP
109 inverted: True
110 filters:
111 - delayed_on: 125ms
112 on_press:
113 then:
114 - switch.toggle: relay2
115 - platform: gpio
116 id: key3
117 pin:
118 number: $key3_gpio
119 mode: INPUT_PULLUP
120 inverted: True
121 filters:
122 - delayed_on: 125ms
123 on_press:
124 then:
125 - switch.toggle: relay3
126 - platform: gpio
127 id: key4
128 pin:
129 number: $key4_gpio
130 mode: INPUT_PULLUP
131 inverted: True
132 filters:
133 - delayed_on: 125ms
134 on_press:
135 then:
136 - switch.toggle: relay4
137 - platform: status
138 name: "Sonoff 4CH Pro 1 WiF1"
139
140
141switch:
142 - platform: gpio
143 id: relay1
144 name: "irrigation_relay1"
145 pin: $rel1_gpio
146 interlock: [relay2,relay3,relay4]
147 restore_mode: ALWAYS_OFF
148 on_turn_on:
149 then:
150 - globals.set:
151 id: remaining_time1
152 value: !lambda "return id(time1);"
153 - platform: gpio
154 id: relay2
155 name: "irrigation_relay2"
156 pin: $rel2_gpio
157 interlock: [relay1,relay3,relay4]
158 restore_mode: ALWAYS_OFF
159 on_turn_on:
160 then:
161 - globals.set:
162 id: remaining_time2
163 value: !lambda "return id(time2);"
164 - platform: gpio
165 id: relay3
166 name: "irrigation_relay3"
167 pin: $rel3_gpio
168 interlock: [relay1,relay2,relay4]
169 restore_mode: ALWAYS_OFF
170 on_turn_on:
171 - globals.set:
172 id: remaining_time3
173 value: !lambda "return id(time3);"
174 - platform: gpio
175 id: relay4
176 name: "irrigation_relay4"
177 pin: $rel4_gpio
178 interlock: [relay1,relay2,relay3]
179 restore_mode: ALWAYS_OFF
180 on_turn_on:
181 - globals.set:
182 id: remaining_time4
183 value: !lambda "return id(time4);"
184
185 - platform: template
186 name: "Set Relay1 Time"
187 id: set_relay1_time
188 turn_on_action:
189 - then:
190 - switch.template.publish:
191 id: set_relay1_time
192 state: ON
193 - delay: 2s
194 turn_off_action:
195 - then:
196 - switch.template.publish:
197 id: set_relay1_time
198 state: OFF
199 - platform: template
200 name: "Set Relay2 Time"
201 id: set_relay2_time
202 turn_on_action:
203 - then:
204 - globals.set:
205 id: time2
206 value: !lambda "return id(new_time2);"
207 - switch.template.publish:
208 id: set_relay2_time
209 state: ON
210 - delay: 2s
211 turn_off_action:
212 - then:
213 - switch.template.publish:
214 id: set_relay2_time
215 state: OFF
216 - platform: template
217 name: "Set Relay3 Time"
218 id: set_relay3_time
219 turn_on_action:
220 - then:
221 - globals.set:
222 id: time3
223 value: !lambda "return id(new_time3);"
224 - switch.template.publish:
225 id: set_relay3_time
226 state: ON
227 - delay: 2s
228 turn_off_action:
229 - then:
230 - switch.template.publish:
231 id: set_relay3_time
232 state: OFF
233 - platform: template
234 name: "Set Relay4 Time"
235 id: set_relay4_time
236 turn_on_action:
237 - then:
238 - globals.set:
239 id: time4
240 value: !lambda "return id(new_time4);"
241 - switch.template.publish:
242 id: set_relay4_time
243 state: ON
244 - delay: 2s
245 turn_off_action:
246 - then:
247 - switch.template.publish:
248 id: set_relay4_time
249 state: OFF
250
251interval:
252 - interval: 1s
253 then:
254 - lambda: |-
255
256 if(id(relay1).state) {
257 id(remaining_time1)=id(remaining_time1)-1;
258 if(id(remaining_time1)<=0){
259 id(relay1).turn_off();
260 }
261 }
262 if(id(relay2).state) {
263 id(remaining_time2)=id(remaining_time2)-1;
264 if(id(remaining_time2)<=0){
265 id(relay2).turn_off();
266 }
267 }
268 if(id(relay3).state) {
269 id(remaining_time3)=id(remaining_time3)-1;
270 if(id(remaining_time3)<=0){
271 id(relay3).turn_off();
272 }
273 }
274 if(id(relay4).state) {
275 id(remaining_time4)=id(remaining_time4)-1;
276 if(id(remaining_time4)<=0){
277 id(relay4).turn_off();
278 }
279 }
280
281captive_portal:
282
283logger:
284 baud_rate: 0
285
286api:
287
288ota:
289
290output:
291 - platform: esp8266_pwm
292 id: blue_led
293 pin: GPIO13
294 inverted: True
295
296light:
297 - platform: monochromatic
298 name: "Set Time Blue LED"
299 output: blue_led
300
301web_server:
302 port: 80
303
304