-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtemplate.yaml
476 lines (448 loc) · 12.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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
substitutions:
devicename: ifan04
friendly_devicename: iFan04
fan_startup_boost_time: 5s
# Morse codes for the different buzzer sounds
code_buzzer_on: "E" # .
code_buzzer_off: "I" # ..
code_fan_off: "T" # -
code_fan_1: "N" # -.
code_fan_2: "D" # -..
code_fan_3: "B" # -...
code_rc_unpair: "O" # ---
code_short: "E" # .
code_long: "T" # -
external_components:
- source:
type: git
url: https://github.com/rh1rich/esphome-ifan-remote
- source:
type: git
url: https://github.com/rh1rich/esphome-morse-code
esphome:
project:
name: "rh1rich.iFan04"
version: "1.0.0"
name: $devicename
friendly_name: $friendly_devicename
on_boot:
priority: 600
then:
- output.turn_off: buzzer
esp8266:
board: esp8285
framework:
version: latest
early_pin_init: false
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
actions:
- action: play_morse_code
variables:
text_string: string
then:
- morse_code.start:
text: !lambda 'return text_string;'
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 Control)
# 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:
- if:
condition:
lambda: return id(buzzer_enabled).state;
then:
- morse_code.start: $code_fan_off
- script.execute:
id: fan_speed_set
speed: 0
- if:
condition:
lambda: return ((state >= 0.3) && (state < 0.6));
then:
- if:
condition:
lambda: return id(buzzer_enabled).state;
then:
- morse_code.start: $code_fan_1
- script.execute:
id: fan_speed_set
speed: 1
- if:
condition:
lambda: return ((state >= 0.6) && (state < 0.9));
then:
- if:
condition:
lambda: return id(buzzer_enabled).state;
then:
- morse_code.start: $code_fan_2
- script.execute:
id: fan_speed_set
speed: 2
- if:
condition:
lambda: return (state >= 0.9);
then:
- if:
condition:
lambda: return id(buzzer_enabled).state;
then:
- morse_code.start: $code_fan_3
- script.execute:
id: fan_speed_set
speed: 3
morse_code:
output: buzzer
dit_duration: 50
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:
- morse_code.start: $code_buzzer_on
on_turn_off:
- morse_code.start: $code_buzzer_off
- platform: template
name: 'Light enabled'
id: light_enabled
entity_category: config
optimistic: True
restore_mode: RESTORE_DEFAULT_ON
- 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: uptime
name: 'Uptime'
entity_category: diagnostic
unit_of_measurement: s
- platform: wifi_signal
id: wifi_signal_db
name: 'WiFi Signal dB'
entity_category: diagnostic
# Sensor for the WiFi signal strength in percent (%)
- platform: copy
id: wifi_signal_rel
source_id: wifi_signal_db
name: "WiFi Signal"
entity_category: diagnostic
filters:
- lambda: |-
return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "%"
device_class: 'signal_strength'
# Expample for using a SHT3x sensor which is connected via the test pins TP10 (I2C SCL) and TP11 (I2C SDA) on the PCB.
# Also enable i2c component!
# - platform: sht3xd
# temperature:
# name: 'Temperature'
# humidity:
# name: 'Humidity'
binary_sensor:
- platform: gpio
name: "Button"
pin:
number: GPIO00
inverted: true
- platform: template
name: "RC button light"
id: rc_button_light
filters:
- delayed_off: 300ms
- platform: template
name: "RC button RF/WiFi"
id: rc_button_rfwifi
filters:
- delayed_off: 300ms
- platform: template
name: "RC button WiFi (long)"
id: rc_button_wifi_long
filters:
- delayed_off: 300ms
- platform: template
name: "RC button RF (long)"
id: rc_button_rf_long
filters:
- delayed_off: 300ms
# 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) 0104 000104 (0A)
# 2 (Mute) = (AA55) 0106 000101 (09)
# 3 (Fan high) = (AA55) 0104 000103 (09)
# 4 (Fan mid) = (AA55) 0104 000102 (08)
# 5 (Fan off) = (AA55) 0104 000100 (06)
# 6 (Fan low) = (AA55) 0104 000101 (07)
# 7 (RF Clearing) = (AA55) 0101 000102 (05)
# 7 (RF Clearing 5s) = (AA55) 0107 000101 (0A) clears the connection between remote control and receiver!!
# 8 (WiFi Pairing) = (AA55) 0101 000102 (05)
# 8 (WiFi Pairing 5s) = (AA55) 0101 000101 (04)
ifan_remote:
on_command:
then:
# - logger.log:
# format: "RC command '%04X:%06X' received."
# args: [ 'command.high','command.low' ]
- if:
condition:
lambda: return (command.high == 0x0104 && command.low == 0x000100);
then:
- fan.turn_off: fan_comp
- if:
condition:
lambda: return (command.high == 0x0104 && command.low == 0x000101);
then:
- fan.turn_on:
id: fan_comp
speed: 1
- if:
condition:
lambda: return (command.high == 0x0104 && command.low == 0x000102);
then:
- fan.turn_on:
id: fan_comp
speed: 2
- if:
condition:
lambda: return (command.high == 0x0104 && command.low == 0x000103);
then:
- fan.turn_on:
id: fan_comp
speed: 3
- if:
condition:
lambda: return (command.high == 0x0104 && command.low == 0x000104);
then:
- if:
condition:
lambda: return id(light_enabled).state;
then:
- light.toggle: light_comp
else:
- if:
condition:
lambda: return id(buzzer_enabled).state;
then:
- morse_code.start: $code_short
- binary_sensor.template.publish:
id: rc_button_light
state: ON
- binary_sensor.template.publish:
id: rc_button_light
state: OFF
- if:
condition:
lambda: return (command.high == 0x0106 && command.low == 0x000101);
then:
- switch.toggle: buzzer_enabled
- if:
condition:
lambda: return (command.high == 0x0101 && command.low == 0x000102);
then:
- if:
condition:
lambda: return id(buzzer_enabled).state;
then:
- morse_code.start: $code_short
- binary_sensor.template.publish:
id: rc_button_rfwifi
state: ON
- binary_sensor.template.publish:
id: rc_button_rfwifi
state: OFF
- if:
condition:
lambda: return (command.high == 0x0101 && command.low == 0x000101);
then:
- if:
condition:
lambda: return id(buzzer_enabled).state;
then:
- morse_code.start: $code_long
- binary_sensor.template.publish:
id: rc_button_wifi_long
state: ON
- binary_sensor.template.publish:
id: rc_button_wifi_long
state: OFF
- if:
condition:
lambda: return (command.high == 0x0107 && command.low == 0x000101);
then:
- morse_code.start: $code_rc_unpair
- binary_sensor.template.publish:
id: rc_button_rf_long
state: ON
- binary_sensor.template.publish:
id: rc_button_rf_long
state: OFF
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
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
else:
- 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: # enable cap 1
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: # enable cap 1 & 2
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: # no caps
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;