A fail-safe fan for a fanless firewall
My fanless firewall now gets cooled only when it needs it: Home Assistant reads its CPU temperature and switches a fan on at 60 °C and off at 50 °C. If the reading is ever lost, the fan fails safe to on, and I get one alert, not a flood. This is how it works, the five things that broke, and how I tested the failure paths.
Why
My OPNsense firewall runs on a fanless mini PC. Under load (Suricata rule updates, big downloads) its hottest core climbed to around 65 °C. That's well below the point where the CPU throttles, but sustained heat shortens the life of the hardware and the SSD next to it.
The first fix was a fan on a smart plug with a timer: it ran for 30 minutes every 4 hours. It was blind. It cooled the box when it was already cool, and did nothing during a hot afternoon between runs.
The goal: cool on demand, from the firewall's own temperature; never leave the fan off if the temperature can't be read; and only alert me when something actually needs attention.
Design
Building it
Read-only access to the firewall
Home Assistant reads the temperatures through the community hass-opnsense integration and OPNsense's API. The API user has only the three privileges the integration needs for basic telemetry (Lobby: Dashboard, Status: Interfaces, System: Firmware), and Granular Sync is set to Basic Telemetry Data only. Several of the integration's categories are switches that could change firewall rules or services; none of them are enabled. If Home Assistant were ever compromised, it could read the firewall's temperature, not change the firewall.
The integration suggests a full admin account and logs a permission error for each feature it isn't allowed to use. Those errors are the least-privilege setup working, not a fault.
Helpers: one sensor and three settings
| Helper | Type | Purpose |
|---|---|---|
| Firewall CPU temp max | Combine the state of several sensors, Maximum | The hottest of the four cores: the fan reacts to the worst core, not an average that hides it |
| Firewall fan on temp | Number, 40 to 90 °C | 60 °C |
| Firewall fan off temp | Number, 35 to 85 °C | 50 °C |
| Firewall temp lost alerted | Toggle | Remembers that a "reading lost" alert went out |
Keeping the thresholds in helpers means they can be changed from the dashboard without touching the automations, and the 10 °C gap between on and off stops the fan flicking on and off around a single value.
Thresholds from a real test, not a guess
Before writing any logic I ran the fan by hand and watched the cores. Most dropped below 45 °C within three minutes; one core lagged and sat at 51 °C for a while before following. That lagging core is why the off threshold is 50 rather than lower: set it below where the slowest core settles and the fan would never switch off.
Three automations, one job each
- Temperature control. Fan on when the hottest core is above 60 °C for 2 minutes; off when it's below 50 °C for 5 minutes. If the reading is unavailable or unknown for 10 minutes, fan on. On recovery and on Home Assistant start, it re-checks the current temperature, because threshold triggers only fire when a value crosses the line.
- Alerts. One phone notification (ntfy) when the reading is lost for 10 minutes, or when it's still above 70 °C for 10 minutes with the fan running. After an alert it ignores new triggers for 6 hours, so a flapping integration can't flood my phone.
- All clear. "Reading back" only if a "reading lost" alert was actually sent, then it resets the toggle. Home Assistant restarts and short blips never notify.
Normal cooling cycles, several a day, never send anything.
What broke
Five things failed along the way. Each looked like a configuration mistake at first and turned out to be something more specific.
| What I saw | Cause | Fix |
|---|---|---|
Installing the integration through HACS failed with could_not_register | Home Assistant's log showed Got more than 8190 bytes when reading: GitHub had started sending a Content-Security-Policy header over 9 KB, larger than the web library's limit. A known upstream issue at the time. | Installed the integration manually from its tagged release instead of waiting for a fix |
| The fan automation didn't fire with the temperature at exactly 60 °C | "Above 60" means more than 60, and threshold triggers only fire when the value crosses the line, not while it's already past it | Tested by forcing a crossing: setting the sensor's state briefly in Developer tools |
| The alert automation ran but nothing arrived | The ntfy topic's notify entity was used as if it were an action | Called the generic notify.send_message action with the entity as its target |
| Disabling the integration never triggered the fail-safe | The combined max sensor goes unknown when its sources disappear, not unavailable, and the trigger only listened for unavailable | Triggers accept both states, in the fan automation and the alerts |
| The "reading back" alert never arrived after an outage | The alerts automation was still inside its 6-hour cooldown from the "reading lost" alert, and single mode silently drops new triggers | Moved the all-clear into its own automation, gated by a toggle that records whether a "lost" alert went out |
The fourth one matters most. A fail-safe that has never been tested is only a hope: the YAML looked correct, and only pulling the integration's plug showed the state it actually produces.
Proving it
The normal path is easy to test; the failure paths are the ones that matter. I tested every branch, using Home Assistant's traces to confirm which trigger fired and which branch ran.
| Test | How | Expected | Result |
|---|---|---|---|
| Fan on when hot | On threshold set just below the current temperature | Fan on after 2 minutes | Passed |
| Fan off when cool | On threshold back to 60 | Fan off after 5 minutes below 50 °C | Passed |
| Real cooling | Fan run by hand, cores watched | Below 50 °C within minutes | Most cores below 45 °C in 3 minutes; the slowest followed shortly after |
| "Running hot" alert | Temporary low threshold and a forced crossing | One ntfy alert | Passed |
| Reading lost | OPNsense integration disabled | Fan on and one "reading lost" alert after the delay | Passed (after the unknown fix) |
| Reading back | Integration enabled again | One "reading back" alert; fan off if already cool | Passed (after moving the all-clear into its own automation) |
| No flood | Normal cooling cycles through the day | No notifications | None received |
After each test the thresholds and delays went back to their real values, and the alerts automation was toggled off and on to clear the cooldown the test had started.
Lessons and what's next
- Fail safe, and decide what "safe" means. When the system can't see the temperature, it assumes the worst. A fan running for a day costs nothing; an overheating firewall costs the box.
- Test the failure paths, not just the happy path. Two of the five bugs were only in the outage branches, and only appeared when I actually broke the integration.
- Alerts are a design problem. Every alert needs a reason to exist, a grace period and a cooldown, and the all-clear must not be blocked by the cooldown of the alert it clears.
- Least privilege applies to home automation too. Read-only, telemetry-only API access means a compromised Home Assistant can't touch the firewall.
- Read the logs, then read the upstream issues. The HACS failure looked like my network; the log pointed to an 8190-byte header limit and a bug report from the day before.
Next: watch a few weeks of temperature history and adjust the thresholds if the fan runs longer than it needs to.