- Automatic fan control based on maximum temperature
- Configurable temperature thresholds and fan speeds
- Manual fan control via Home Assistant
- Web UI (ESPHome Web Server)
- OTA updates over WiFi
- Stop & fan test mode
| Component | Description |
|---|---|
| ESP32 DevKit | ESP32-WROOM-32D/32U, 30-pin, Type-C |
| DS18B20 Sensor | 2x with terminal adapter (4.7kΩ resistor) |
| PWM Fans | 2x Arctic P12 PWM 4-pin |
| 12V Power Supply | 1.5A |
| USB Power Supply | 5V 1A with USB Type-C cable |
| Dupont Cables |
- ESPHome installed
- Home Assistant (recommended but optional)
- USB cable for initial firmware upload
git clone https://github.com/YOUR_USERNAME/esp32-fan-controller.git
cd esp32-fan-controllerEdit fan-controller.yaml and update WiFi settings:
wifi:
ssid: "YOUR_WIFI_SSID"
password: "YOUR_WIFI_PASSWORD"Also update web server credentials:
web_server:
auth:
username: admin
password: YOUR_PASSWORDOption A: ESPHome Dashboard (recommended)
- Add device in ESPHome Dashboard
- Copy contents of
fan-controller.yaml - Click Install → Plug into this computer
- Select COM port
- Wait for installation
Option B: ESPHome CLI
esphome run fan-controller.yamlOption C: Web Flasher (first time only)
- Visit https://web.esphome.io/
- Connect ESP32 via USB
- Upload compiled
.binfile - After first flash, use OTA for updates
After successful installation:
- Go to Settings → Devices & Services
- ESPHome integration should auto-discover device
- Click Configure
- Enter encryption key (found in compilation logs)
- Done!
Configure via Home Assistant or web interface:
| Setting | Default | Description |
|---|---|---|
| Temp Threshold 1 | 30°C | Minimum temperature to start fans |
| Speed 1 (Low) | 30% | Fan speed when temp > Threshold 1 |
| Temp Threshold 2 | 40°C | Medium temperature |
| Speed 2 (Medium) | 60% | Fan speed when temp > Threshold 2 |
| Temp Threshold 3 | 50°C | High temperature |
| Speed 3 (High) | 100% | Fan speed when temp > Threshold 3 |
The system uses two temperature sensors (TOP and BOTTOM) and controls both fans based on the maximum temperature reading:
temp_max = max(temp_top, temp_bottom)
Temperature < 30°C → Fans OFF (0%)
Temperature 30-40°C → Fans at 30%
Temperature 40-50°C → Fans at 60%
Temperature > 50°C → Fans at 100%
Why max(temp_top, temp_bottom)?
- If either sensor detects high temperature, both fans respond
- Prevents hot spots in the rack
- More reliable than single sensor monitoring
All values are configurable via sliders in Home Assistant.
- Enable "Auto Control" switch
- System automatically adjusts fan speed based on temperature
- Configure thresholds and speeds via sliders
- Disable "Auto Control" switch
- Use individual fan controls or master ON/OFF switch
- Set desired fan speed (0-100%)
Switches:
Auto Control- Enable/disable automatic temperature-based controlFans ON/OFF- Master switch for all fans (50% default)
Buttons:
Test Fans- Run both fans at 100% for 5 secondsSTOP Fans- Emergency stop (disables auto mode)Restart Controller- Restart ESP32
Sensors:
Temperature TOP- Top sensor temperature readingTemperature BOTTOM- Bottom sensor temperature readingTemperature MAX- Maximum of both sensors (used for control)Speed TOP- Current speed of top fan (%)Speed BOTTOM- Current speed of bottom fan (%)WiFi Signal- WiFi signal strengthUptime- Device uptime
Example dashboard configuration in dashboard-example.yaml:
type: vertical-stack
cards:
- type: history-graph
title: Temperature History
hours_to_show: 24
entities:
- entity: sensor.temperatura_rack
- type: entities
title: Fan Controller
entities:
- sensor.temperatura_rack
- switch.auto_sterowanie
- switch.wentylatory_on_off
- fan.wentylator_top
- fan.wentylator_downSee full example in dashboard-example.yaml.
esphome run fan-controller.yaml --device fan-controller.local- Open
http://fan-controller.local - Login with credentials
- Look for update/upload button
- Select new
.binfile
- Settings → Devices & Services → ESPHome
- Find
fan-controller - Click Update (if available)
Check:
- 12V power supply connected and ON
- PWM wires connected to correct GPIO pins (25, 26)
- Common ground between 12V PSU and ESP32
- Fans support PWM control (4-pin connectors)
- Fan speed > 20% (minimum startup speed)
Check:
- Both DS18B20 sensors connected to GPIO4 (parallel)
- 4.7kΩ pull-up resistor present (usually on terminal board)
- Correct wiring: Red→3.3V, Yellow→GPIO4, Black→GND
- Check ESPHome logs for "Found DS18B20" message (should see 2 devices)
- Sensors have unique addresses
Finding sensor addresses: Check logs after first boot:
[one_wire] Found DS18B20 device 0x1c0000031edd2a28
[one_wire] Found DS18B20 device 0x233c01f096fff428
Solutions:
- Check SSID and password in configuration
- Ensure 2.4GHz WiFi (ESP32 doesn't support 5GHz)
- Device creates fallback hotspot "Fan-Controller-Fallback" (password: fancontrol123)
- Connect to fallback and reconfigure WiFi
Check:
- "Auto Control" switch is enabled
- Temperature thresholds configured correctly
- Check ESPHome logs for auto control messages
- Ensure temperature sensor is working
After first boot with both sensors connected, check logs:
[one_wire] Found DS18B20 device 0x1c0000031edd2a28
[one_wire] Found DS18B20 device 0x233c01f096fff428
The sensors are automatically assigned:
index: 0→ First sensor found (TOP)index: 1→ Second sensor found (BOTTOM)
If you need to swap them, physically swap the sensor probes or use explicit addresses in YAML:
sensor:
- platform: dallas_temp
address: 0x1c0000031edd2a28 # Specific address for TOP
name: "Temperature TOP"If you only have one sensor, the system still works:
- Comment out the second sensor in YAML
temp_maxwill use the single sensor value- Both fans controlled by one temperature reading
Change in YAML (default 25kHz):
output:
- platform: ledc
frequency: 25000 Hz # Adjust if neededModify lambda function in on_value section for custom temperature/speed curves.
