· 4 years ago · Apr 06, 2021, 08:40 AM
1substitutions:
2 rel1_gpio: GPIO12
3 rel2_gpio: GPIO5
4 rel3_gpio: GPIO4
5 rel4_gpio: GPIO15
6 key1_gpio: GPIO0
7 key2_gpio: GPIO9
8 key3_gpio: GPIO10
9 key4_gpio: GPIO14
10 led_gpio: GPIO13
11 rx_gpio: GPIO3
12 tx_gpio: GPIO1
13
14esphome:
15 name: nawodnienie
16 platform: ESP8266
17 board: esp01_1m
18
19 on_boot:
20 priority: -100.0
21 then:
22 # Set light to half brightness when first ready.
23 - light.turn_on:
24 id: status_led
25 brightness: 50%
26
27 # Wait to check for a Home Assistant API connection.
28 - delay: 15s
29 - if:
30 condition:
31 api.connected:
32 then:
33 # If connected, then flash the LED, and leave it at full brightness.
34 - logger.log: "$project is connected to the Home Assistant API!"
35 - light.turn_on:
36 id: status_led
37 brightness: 100%
38 - delay: 0.5s
39 - light.turn_off: status_led
40 - delay: 0.5s
41 - light.turn_on:
42 id: status_led
43 brightness: 100%
44 - delay: 0.5s
45 - light.turn_off: status_led
46 - delay: 0.5s
47 - light.turn_on:
48 id: status_led
49 brightness: 100%
50 - delay: 0.5s
51 - light.turn_off: status_led
52 - delay: 0.5s
53 - light.turn_on:
54 id: status_led
55 brightness: 100%
56
57 # Turn off the LED when the device is shutting down (like for a firmware update).
58 on_shutdown:
59 then:
60 - light.turn_off: status_led
61
62
63uart:
64 rx_pin: $rx_gpio
65 tx_pin: $tx_gpio
66 baud_rate: 9600
67
68globals:
69 - id: time1
70 type: int
71 restore_value: no
72 initial_value: '1800'
73 - id: time2
74 type: int
75 restore_value: no
76 initial_value: '1800'
77 - id: time3
78 type: int
79 restore_value: no
80 initial_value: '1800'
81 - id: remaining_time1
82 type: int
83 restore_value: no
84 initial_value: '1800'
85 - id: remaining_time2
86 type: int
87 restore_value: no
88 initial_value: '1800'
89 - id: remaining_time3
90 type: int
91 restore_value: no
92 initial_value: '1800'
93
94
95wifi:
96 ssid: ssid
97 password: passwd
98 fast_connect: true
99 use_address: IP
100 manual_ip:
101 static_ip: IP
102 subnet: subnet
103 gateway: gateway
104
105 # Enable fallback hotspot (captive portal) in case wifi connection fails
106 ap:
107 ssid: Nawodnienie Fallback
108 password: passwd
109
110captive_portal:
111
112api:
113 services:
114 - service: set_time_1
115 variables:
116 time: int
117 then:
118 globals.set:
119 id: time1
120 value: !lambda "return time;"
121 - service: set_time_2
122 variables:
123 time: int
124 then:
125 globals.set:
126 id: time2
127 value: !lambda "return time;"
128 - service: set_time_3
129 variables:
130 time: int
131 then:
132 globals.set:
133 id: time3
134 value: !lambda "return time;"
135
136sensor:
137 - platform: template
138 name: "Pozostały czas Strefa 1 sekundy"
139 id: czas_strefa_1_sek
140 update_interval: 5s
141 lambda: |-
142 return id(remaining_time1);
143
144text_sensor:
145 - platform: template
146 name: "Pozostały czas Strefa 1"
147 id: czas_strefa_1
148 update_interval: 5s
149 lambda: |-
150 std::string str;
151 str = to_string(id(remaining_time1)/60) + ":" + to_string(id(remaining_time1)%60);
152 return str;
153 - platform: template
154 name: "Pozostały czas Strefa 2"
155 id: czas_strefa_2
156 update_interval: 5s
157 lambda: |-
158 std::string str;
159 str = to_string(id(remaining_time2)/60) + ":" + to_string(id(remaining_time2)%60);
160 return str;
161 - platform: template
162 name: "Pozostały czas Strefa 3"
163 id: czas_strefa_3
164 update_interval: 5s
165 lambda: |-
166 std::string str;
167 str = to_string(id(remaining_time3)/60) + ":" + to_string(id(remaining_time3)%60);
168 return str;
169
170
171binary_sensor:
172 - platform: gpio
173 id: key1
174 pin:
175 number: $key1_gpio
176 mode: INPUT_PULLUP
177 inverted: True
178 filters:
179 - delayed_on: 100ms
180 - delayed_off: 100ms
181 on_click:
182 min_length: 50ms
183 max_length: 350ms
184 then:
185 - globals.set:
186 id: time1
187 value: "900"
188 - switch.toggle: relay1
189 - platform: gpio
190 id: key2
191 pin:
192 number: $key2_gpio
193 mode: INPUT_PULLUP
194 inverted: True
195 filters:
196 - delayed_on: 100ms
197 - delayed_off: 100ms
198 on_click:
199 min_length: 50ms
200 max_length: 350ms
201 then:
202 - globals.set:
203 id: time2
204 value: "900"
205 - switch.toggle: relay2
206 - platform: gpio
207 id: key3
208 pin:
209 number: $key3_gpio
210 mode: INPUT_PULLUP
211 inverted: True
212 filters:
213 - delayed_on: 100ms
214 - delayed_off: 100ms
215 on_click:
216 min_length: 100ms
217 max_length: 500ms
218 then:
219 - globals.set:
220 id: time3
221 value: "900"
222 - switch.toggle: relay3
223
224switch:
225 - platform: gpio
226 id: relay1
227 name: "Nawodnienie strefa 1"
228 pin: $rel1_gpio
229 on_turn_on:
230 then:
231 - globals.set:
232 id: remaining_time1
233 value: !lambda "return id(time1);"
234 on_turn_off:
235 then:
236 - globals.set:
237 id: remaining_time1
238 value: !lambda "return 0;"
239 - platform: gpio
240 id: relay2
241 name: "Nawodnienie strefa 2"
242 pin: $rel2_gpio
243 on_turn_on:
244 then:
245 - globals.set:
246 id: remaining_time2
247 value: !lambda "return id(time2);"
248 on_turn_off:
249 then:
250 - globals.set:
251 id: remaining_time2
252 value: !lambda "return 0;"
253 - platform: gpio
254 id: relay3
255 name: "Nawodnienie strefa 3"
256 pin: $rel3_gpio
257 on_turn_on:
258 - globals.set:
259 id: remaining_time3
260 value: !lambda "return id(time3);"
261 on_turn_off:
262 then:
263 - globals.set:
264 id: remaining_time3
265 value: !lambda "return 0;"
266
267interval:
268 - interval: 5s
269 then:
270 - lambda: |-
271 if(id(relay1).state) {
272 id(remaining_time1)=id(remaining_time1)-5;
273 if(id(remaining_time1)<=0){
274 id(relay1).turn_off();
275 }
276 }
277 if(id(relay2).state) {
278 id(remaining_time2)=id(remaining_time2)-5;
279 if(id(remaining_time2)<=0){
280 id(relay2).turn_off();
281 }
282 }
283 if(id(relay3).state) {
284 id(remaining_time3)=id(remaining_time3)-5;
285 if(id(remaining_time3)<=0){
286 id(relay3).turn_off();
287 }
288 }
289
290ota:
291
292logger:
293
294output:
295 - platform: esp8266_pwm
296 id: led_diode
297 pin: $led_gpio
298 inverted: True
299
300light:
301 - platform: monochromatic
302 internal: True
303 output: led_diode
304 id: status_led