-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfan-controller.yaml
231 lines (201 loc) · 11.1 KB
/
fan-controller.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
substitutions:
friendly_name: Fan Controller
name: fan-controller
esphome:
name: ${name}
#########################
# ESP AND NETWORK SETUP
esp8266:
board: d1_mini
# pid climate log update is noisy, dial it back to warn
logger:
level: DEBUG
logs:
dallas: DEBUG
# uncomment if you prefer native api
#api:
# i prefer mqtt over native api
mqtt:
broker: "###### your broker address here #####"
discovery: true
discovery_prefix: homeassistant
log_topic:
topic: ${name}/log
level: WARN
web_server:
port: 80
# default HA integration, OTA updater and backup http web portal
ota:
on_begin:
then:
- logger.log: "OTA start"
on_progress:
then:
- logger.log:
format: "OTA progress %0.1f%%"
args: ["x"]
on_end:
then:
- logger.log: "OTA end"
captive_portal:
wifi:
# Read the wifi/pass from secrets.yaml:
# wifi_ssid: "My Wifi XX"
# wifi_password: "XXXXXXX"
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: true
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: FanController
text_sensor:
# Send IP Address
- platform: wifi_info
ip_address:
name: IP Address
ssid:
name: SSID
# Send Uptime in raw seconds
- platform: template
name: Uptime
id: uptime_human
icon: mdi:clock-start
dallas:
- pin: D0
update_interval: 10s
sensor:
# Send WiFi signal strength & uptime to HA
- platform: wifi_signal
name: WiFi Strength
update_interval: 60s
# RPM Signal from Fan
- platform: pulse_counter
pin:
number: D2
mode:
input: true
pullup: true
name: Measured Speed
id: fan_pulse
unit_of_measurement: 'RPM'
accuracy_decimals: 1
filters:
- multiply: 0.5
count_mode:
rising_edge: INCREMENT
falling_edge: DISABLE
update_interval: 10s
# This is a bit of overkill. It sends a human readable
# uptime string
# 1h 41m 32s instead of 6092 seconds
- platform: uptime
name: Uptime
id: uptime_sensor
update_interval: 60s
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
# Custom C++ code to generate the result
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? to_string(days) + "d " : "") +
(hours ? to_string(hours) + "h " : "") +
(minutes ? to_string(minutes) + "m " : "") +
(to_string(seconds) + "s")
).c_str();
- platform: dallas
#address: 0x1c0000031edd2a28
index: 0
resolution: 9
name: "Temperature"
id: fan_temperature
accuracy_decimals: 1
#alternative use lambda with map
on_value:
# map min temp whn fan should start 30°C to max temp 50°C when it should have max speed
- lambda: !lambda |
auto pct = constrain(map(x, id(start_temp).state, id(max_temp).state, 1, 100),0,100);
if( id(automatic).state ) {
if (pct>1) {
auto call = id(the_fan).turn_on(); call.set_speed(pct); call.perform();
} else {
auto call = id(the_fan).turn_off(); call.set_speed(1); call.perform();
}
ESP_LOGD("custom", "Setting speed to %i %%", pct);
}
output:
# Wire D1 into the PWM pin of your 12v fan
# ledc is the name of the pwm output system on an esp32
- platform: esp8266_pwm
id: fan_speed
pin: D1
# 25KHz is standard PC fan frequency, minimises buzzing for eso8266 1kHz is max
frequency: "1000 Hz"
# my fans stop working below 13% powerful.
# also they're powerful and loud, cap their max speed to 80%
min_power: 0
max_power: 1
zero_means_zero: True
# Fan power (MOSFET) via D3 with will switch GND for the fan through an N-Ch MOSFET
- platform: gpio
pin: D3
id: fan_power
fan:
- platform: speed
output: fan_speed
name: Fan
id: the_fan
on_turn_on:
- output.turn_on: fan_power
on_turn_off:
- output.turn_off: fan_power
# two number controlling the speed adjustment range
number:
- platform: template
name: "Fan Start Temp"
id: start_temp
internal: false
max_value: 40.0
min_value: 20.0
initial_value: 30
step: 1
optimistic: true
mode: slider
- platform: template
name: "Fan 100% Temp"
id: max_temp
internal: false
initial_value: 50
max_value: 60.0
min_value: 30.0
step: 1
optimistic: true
mode: slider
switch:
# template switch, whether control is fully manual or temperature controlled
- platform: template
name: Temperature Controlled
optimistic: true
id: automatic
restore_mode: RESTORE_DEFAULT_ON
on_turn_on:
# if auto is turned on restore temp based value
- lambda: !lambda |
auto pct = constrain(map(id(fan_temperature).state, id(start_temp).state, id(max_temp).state, 1, 100),0,100);
if (pct>1) {
auto call = id(the_fan).turn_on(); call.set_speed(pct); call.perform();
} else {
auto call = id(the_fan).turn_off(); call.set_speed(1); call.perform();
}
button:
# Expose an ESP32 restart button to HA
- platform: restart
name: "Restart"