forked from rh1rich/esphome-ifan04
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
456 lines (429 loc) · 11.7 KB
/
template.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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
substitutions:
devicename: ifan04
friendly_devicename: iFan04
fan_startup_boost_time: 5s
esphome:
name: $devicename
friendly_name: $friendly_devicename
includes:
- ifan_remote.h
on_boot:
priority: 600
then:
- output.turn_off: buzzer
esp8266:
board: esp8285
framework:
version: latest
early_pin_init: true
restore_from_flash: true
preferences:
flash_write_interval: 5min
# Enable logging
# But disable it via UART0, because UART0 is used by the RF receiver
logger:
baud_rate: 0
# level: VERBOSE
# Enable Home Assistant API
api:
encryption:
key: !secret "api_key"
# Setting reboot timeout to 0 seconds to disable the automatic reboot, if no api connection (Home Assistant server).
# This is essential for offline usage.
reboot_timeout: 0s
ota:
- platform: esphome
password: !secret "ota_password"
wifi:
ssid: !secret "wifi_ssid"
password: !secret "wifi_password"
fast_connect: yes
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "$devicename"
password: !secret "wifi_fallback_password"
captive_portal:
web_server:
port: 80
version: 3
# GPIO00 ... Button
# GPIO01 ... UART0 TX
# GPIO03 ... UART0 RX (RF-Remote)
# GPIO04 ... I2C SDA (TP11 D_RX on PCB backside)
# GPIO05 ... I2C SCL (TP10 D_TX on PCB backside)
# GPIO09 ... Light Relay (D)
# GPIO10 ... Buzzer
# GPIO12 ... Fan Relay 2 (D11, 3uF cap on IFAN04-H)
# GPIO13 ... LED
# GPIO14 ... Fan Relay 1 (D5, 2.5uF cap on IFAN04-H)
# GPIO15 ... Fan Relay 3 (D13, no cap)
status_led:
pin:
number: GPIO13
inverted: true
# UART0 (GPIO03) is used by the RF-receiver to send the received RF-commands
# to the ESP.
uart:
rx_pin: GPIO03
baud_rate: 9600
id: uart_bus
# I2C via the test points TP10 (= GPIO05) and TP11 (= GPIO04) on the PCB.
i2c:
sda: GPIO04
scl: GPIO05
frequency: 200kHz
output:
- platform: gpio
id: light_relay
pin:
number: GPIO09
inverted: true
- platform: gpio
id: buzzer
pin:
number: GPIO10
inverted: true
- platform: gpio
id: fan_relay_1
pin: GPIO14
- platform: gpio
id: fan_relay_2
pin: GPIO12
- platform: gpio
id: fan_relay_3
pin: GPIO15
- platform: template
id: fan_relays
type: float
write_action:
- if:
condition:
lambda: return (state < 0.3);
then:
- script.execute:
id: buzzer_play
action: fan_off
- script.execute:
id: fan_speed_set
speed: 0
- if:
condition:
lambda: return ((state >= 0.3) && (state < 0.6));
then:
- script.execute:
id: buzzer_play
action: fan_1
- script.execute:
id: fan_speed_set
speed: 1
- if:
condition:
lambda: return ((state >= 0.6) && (state < 0.9));
then:
- script.execute:
id: buzzer_play
action: fan_2
- script.execute:
id: fan_speed_set
speed: 2
- if:
condition:
lambda: return (state >= 0.9);
then:
- script.execute:
id: buzzer_play
action: fan_3
- script.execute:
id: fan_speed_set
speed: 3
light:
- platform: binary
name: 'Light'
id: light_comp
output: light_relay
fan:
- platform: speed
name: 'Fan'
id: fan_comp
output: fan_relays
speed_count: 3
switch:
- platform: template
name: 'Buzzer enabled'
id: buzzer_enabled
entity_category: config
optimistic: True
restore_mode: RESTORE_DEFAULT_ON
on_turn_on:
- script.execute:
id: buzzer_play
action: buzzer_on
on_turn_off:
- script.execute:
id: buzzer_play
action: buzzer_off
- platform: template
name: 'Light enabled'
id: light_enabled
entity_category: config
optimistic: True
restore_mode: RESTORE_DEFAULT_OFF
- platform: template
name: 'Fan startup-boost enabled'
id: fan_boost_enabled
entity_category: config
optimistic: True
restore_mode: RESTORE_DEFAULT_OFF
button:
- platform: restart
name: Restart
entity_category: diagnostic
sensor:
- platform: wifi_signal
name: 'WiFi Signal'
entity_category: diagnostic
- platform: uptime
name: 'Uptime'
entity_category: diagnostic
unit_of_measurement: s
# Expample for using a SHT3x sensor which is connected via the test pins TP10 (I2C SCL) and TP11 (I2C SDA) on the PCB.
# - platform: sht3xd
# temperature:
# name: 'Temperatur'
# humidity:
# name: 'Humidity'
binary_sensor:
- platform: gpio
name: "Button"
pin:
number: GPIO00
inverted: true
- platform: template
name: "Remote button light"
id: rf_button_light
- platform: template
name: "Remote button link"
id: rf_button_link
# Remote commands via UART0
# RX: GPIO03
#
# The numbering of the following remote control buttons
# starts with the top left button (1) and ends with the
# bottom right button (8).
#
# 1 (Light) = (AA55) 0104000104 (0A)
# 2 (Buzzer) = (AA55) 0106000101 (09)
# 3 (Fan 3) = (AA55) 0104000103 (09)
# 4 (Fan 2) = (AA55) 0104000102 (08)
# 5 (Fan 0) = (AA55) 0104000100 (06)
# 6 (Fan 1) = (AA55) 0104000101 (07)
# 7 = (AA55) 0101000102 (05)
# 8 = (AA55) 0101000102 (05)
text_sensor:
- platform: version
name: 'ESPHome Version'
entity_category: diagnostic
- platform: wifi_info
ip_address:
name: WiFi IP Address
entity_category: diagnostic
ssid:
name: WiFi SSID
entity_category: diagnostic
mac_address:
name: WiFi MAC Address
entity_category: diagnostic
dns_address:
name: WiFi DNS Address
entity_category: diagnostic
- platform: custom
lambda: |-
auto ifan_remote_sensor = new IFanRemote(id(uart_bus));
App.register_component(ifan_remote_sensor);
return {ifan_remote_sensor};
text_sensors:
name: 'Remote command'
on_value:
then:
- logger.log:
format: "Remote command '%s' received."
args: [ "x" ]
- if:
condition:
lambda: return x == "0104000104";
then:
- if:
condition:
lambda: return id(light_enabled).state;
then:
- light.toggle: light_comp
else:
- binary_sensor.template.publish:
id: rf_button_light
state: ON
- delay: 500ms
- binary_sensor.template.publish:
id: rf_button_light
state: OFF
- if:
condition:
lambda: return x == "0106000101";
then:
- switch.toggle: buzzer_enabled
- if:
condition:
lambda: return x == "0104000100";
then:
- fan.turn_off: fan_comp
- if:
condition:
lambda: return x == "0104000101";
then:
- fan.turn_on:
id: fan_comp
speed: 1
- if:
condition:
lambda: return x == "0104000102";
then:
- fan.turn_on:
id: fan_comp
speed: 2
- if:
condition:
lambda: return x == "0104000103";
then:
- fan.turn_on:
id: fan_comp
speed: 3
- if:
condition:
lambda: return x == "0101000102";
then:
- binary_sensor.template.publish:
id: rf_button_link
state: ON
- delay: 500ms
- binary_sensor.template.publish:
id: rf_button_link
state: OFF
globals:
- id: last_fan_speed
type: int
restore_value: no
initial_value: "0"
script:
- id: fan_speed_set
mode: restart
parameters:
speed: int
then:
- if:
condition:
lambda: return (speed == 0);
then:
- output.turn_off: fan_relay_1
- output.turn_off: fan_relay_2
- output.turn_off: fan_relay_3
- if:
condition:
lambda: return (speed > 0);
then:
- if:
condition:
lambda: return (id(fan_boost_enabled).state && (id(last_fan_speed) == 0));
then:
- output.turn_off: fan_relay_1
- output.turn_off: fan_relay_2
- output.turn_on: fan_relay_3
- delay: $fan_startup_boost_time
- if:
condition:
lambda: return (speed == 1);
then:
- output.turn_on: fan_relay_1
- output.turn_off: fan_relay_2
- output.turn_off: fan_relay_3
- if:
condition:
lambda: return (speed == 2);
then:
- output.turn_on: fan_relay_1
- output.turn_on: fan_relay_2
- output.turn_off: fan_relay_3
- if:
condition:
lambda: return (speed == 3);
then:
- output.turn_off: fan_relay_1
- output.turn_off: fan_relay_2
- output.turn_on: fan_relay_3
- lambda: |-
id(last_fan_speed) = speed;
- id: buzzer_play
mode: restart
parameters:
action: string
then:
- if:
condition:
lambda: return (action == "buzzer_off");
then:
- output.turn_on: buzzer
- delay: 100ms
- output.turn_off: buzzer
- delay: 50ms
- output.turn_on: buzzer
- delay: 50ms
- output.turn_off: buzzer
- if:
condition:
lambda: return (action == "buzzer_on");
then:
- output.turn_on: buzzer
- delay: 50ms
- output.turn_off: buzzer
- delay: 50ms
- output.turn_on: buzzer
- delay: 100ms
- output.turn_off: buzzer
- if:
condition:
lambda: return id(buzzer_enabled).state && (action == "fan_off");
then:
- output.turn_on: buzzer
- delay: 500ms
- output.turn_off: buzzer
- if:
condition:
lambda: return id(buzzer_enabled).state && (action == "fan_1");
then:
- output.turn_on: buzzer
- delay: 100ms
- output.turn_off: buzzer
- if:
condition:
lambda: return id(buzzer_enabled).state && (action == "fan_2");
then:
- output.turn_on: buzzer
- delay: 100ms
- output.turn_off: buzzer
- delay: 100ms
- output.turn_on: buzzer
- delay: 100ms
- output.turn_off: buzzer
- if:
condition:
lambda: return id(buzzer_enabled).state && (action == "fan_3");
then:
- output.turn_on: buzzer
- delay: 100ms
- output.turn_off: buzzer
- delay: 100ms
- output.turn_on: buzzer
- delay: 100ms
- output.turn_off: buzzer
- delay: 100ms
- output.turn_on: buzzer
- delay: 100ms
- output.turn_off: buzzer