Custom ESP32 Attic Temperature Monitor & Gable Vent Fan Trigger
Attic Temperature Monitoring with a Custom ESP32 Build
Attics turn into ovens in summer. We’re talking 140°F (60°C) or hotter on a bad July afternoon, which beats up your roofing materials, drives your cooling bill through the roof (pun intended), and sets the stage for moisture damage once winter rolls around. A custom ESP32 board that watches attic temperature and fires up gable vent fans on its own gives you a level of precise, data-driven control that no off-the-shelf thermostatic vent fan can touch. And it costs a fraction of what the commercial “smart attic fan” systems want.
Why Build a Custom System Instead of Buying One
Most pre-built attic fan controllers run on a single bimetallic thermostat with a fixed on/off point, usually somewhere between 100 and 120°F. It works, sure, but it’s deaf to humidity, can’t be checked remotely, and keeps zero history. An ESP32 build fixes all three at once:
- Dual-condition logic: trigger the fan on temperature AND humidity, so moisture doesn’t build up on cooler but muggy days.
- Remote visibility: pull up attic conditions on your phone over Wi-Fi, MQTT, or a dashboard like Home Assistant.
- Data logging: watch seasonal patterns so you catch insulation or ventilation issues before they become expensive.
- Low cost: parts for a full setup usually land in the $25-$50 range, compared to $150+ for a commercial smart vent kit.
Core Hardware You’ll Need
- ESP32 DevKit board (almost any variant with enough GPIO pins works; the ESP32-WROOM-32 is the cheap, common choice)
- DHT22 or SHT31 sensor for temperature and humidity (the SHT31 costs a bit more but reads faster and more accurately)
- 5V relay module rated for your fan’s amp draw, or a solid-state relay if you want quieter switching that lasts longer
- 12V or 120V gable vent fan (you can reuse an old thermostatic fan, just bypass its built-in thermostat)
- Weatherproof enclosure for the ESP32 and relay, because attics are full of dust and wild temperature swings
- 24AWG or thicker wiring rated for high heat, standard hookup wire can degrade after months of sitting in 140°F+ air
Wiring and Placement Tips
Mount the sensor away from the roof deck and away from the fan itself, ideally at mid-attic height where air is actually moving. Put it too close to the rafters and radiant heat will give you false high readings, sometimes 10-15°F off. A basic radiation shield, even a short length of PVC pipe drilled with a few holes, makes a real difference in accuracy.
Keep the relay control wire separate from the AC power lines so you don’t get induced noise messing with the ESP32’s digital reads. If you’re switching a 120V fan, use a relay rated for that load and keep the AC wiring to code. If mains voltage isn’t your comfort zone, call a licensed electrician. It’s not worth the risk.
Firmware Logic That Actually Works
Here’s a basic loop that does the job well:
- Read temperature and humidity every 30-60 seconds.
- Trigger the fan relay when temperature goes above a threshold (say, 95°F) or humidity climbs past 70%, regardless of temperature.
- Build in hysteresis, turning the fan off only once temperature drops 5-8°F below the trigger point, so the relay doesn’t chatter on and off.
- Push readings to MQTT so Home Assistant or Node-RED can log the history and flag unusual spikes, which often point to a roof leak or failed insulation.
if (temperature > 95 || humidity > 70) { digitalWrite(RELAY_PIN, HIGH); } else if (temperature < 87 && humidity < 60) { digitalWrite(RELAY_PIN, LOW); }
Only bother with the ESP32’s deep sleep mode between reads if you’re running off battery. For a hardwired install, just let it loop continuously with a lightweight cycle. It keeps response time snappy and there’s no battery to worry about.
Integrating with Home Assistant
Publish your sensor data and relay state to MQTT topics such as attic/temperature, attic/humidity, and attic/fan_state. Once that’s in Home Assistant, you can:
- Build automations that also check outdoor weather (no sense venting hot outside air into an already hot attic)
- Get a push notification if attic temp crosses a danger threshold, which is a good way to catch a dead fan before it becomes a bigger problem
- Chart long-term trends to figure out whether you actually need more insulation or extra vents
Common Pitfalls to Avoid
- Sensor drift from heat soak: cheap DHT22 units start reading inaccurately above roughly 125°F. Calibrate against a known good thermometer, or just skip the hassle and go with an SHT31.
- Relay failure in high heat: mechanical relays wear out faster in a hot attic. Solid-state relays hold up longer under that kind of stress.
- No fail-safe: wire in a manual override switch. If the ESP32 ever locks up, you want a way to run the fan by hand, especially on the hottest day of the year, when it matters most.
Conclusion
A custom ESP32 attic monitor paired with a gable vent fan trigger turns a dumb, one-size-fits-all cooling fix into something that actually responds to real conditions. With a sensor, a relay, and some fairly simple firmware logic, you end up with smarter cooling, an early warning system for moisture problems, and a setup that plugs right into whatever smart home system you’re already running. All for less than what a basic commercial unit costs on its own.