Custom ESP32 Attic Temperature Monitor & Gable Vent Fan Trigger

· by Bruno Costa · 5 min read

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:

Core Hardware You’ll Need

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:

  1. Read temperature and humidity every 30-60 seconds.
  2. Trigger the fan relay when temperature goes above a threshold (say, 95°F) or humidity climbs past 70%, regardless of temperature.
  3. 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.
  4. 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:

Common Pitfalls to Avoid

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.

#ESP32#Home Automation#Attic Monitoring#DIY Electronics#Energy Efficiency