~/jackwent.co.uk
jack@jackwent:~$ cat rack-cooling.yaml

Keeping My Server Rack Cool with Home Assistant

published 7 October 20263 min read

My homelab lives in a small rack with a UPS at the bottom and a QNAP NAS full of spinning drives. Small racks get warm, UPS batteries hate heat, and water anywhere near the lot is a disaster. Home Assistant looks after all four for me with a handful of very simple automations.

None of these are clever. That’s the point. Each one does one job, and between them I don’t have to think about the rack at all.

Rack fans that switch themselves

There’s a temperature sensor inside the rack and the rack fans are plugged into an ESPHome smart plug. The fans come on above 21°C and go off below 19°C.

The gap between those two numbers matters. If the fans turned on at 20°C and off at 20°C, they’d flick on and off every few minutes as the temperature hovered around the line. With a two degree gap (called hysteresis), they run until the rack has properly cooled and then stay off until it has properly warmed up.

alias: Rack fan control
mode: single
triggers:
  - trigger: numeric_state
    entity_id: sensor.rack_temperature
    above: 21
    id: hot
  - trigger: numeric_state
    entity_id: sensor.rack_temperature
    below: 19
    id: cold
  - trigger: homeassistant
    event: start
    id: restart
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: hot
        sequence:
          - action: switch.turn_on
            target:
              entity_id: switch.rack_fans
      - conditions:
          - condition: trigger
            id: cold
        sequence:
          - action: switch.turn_off
            target:
              entity_id: switch.rack_fans
      - conditions:
          - condition: trigger
            id: restart
        sequence:
          - delay:
              seconds: 30
          - if:
              - condition: numeric_state
                entity_id: sensor.rack_temperature
                above: 21
            then:
              - action: switch.turn_on
                target:
                  entity_id: switch.rack_fans
          - if:
              - condition: numeric_state
                entity_id: sensor.rack_temperature
                below: 19
            then:
              - action: switch.turn_off
                target:
                  entity_id: switch.rack_fans

Why the restart trigger?

A numeric_state trigger only fires when the value crosses the threshold. If Home Assistant is restarting at the moment the rack goes past 21°C, it misses the crossing, and the fans won’t come on until the temperature drops below 21°C and climbs back up again. On a hot day that could be hours.

So on every restart the automation waits thirty seconds for the sensors to come back, looks at the current temperature, and puts the fans in the right state. I’d add this to any automation that uses above or below.

A fan for the UPS battery

UPS batteries age much faster when they run warm, and mine reports its battery temperature over SNMP. A little USB fan sits next to it, powered from a Zigbee USB switch. Same pattern as the rack: on above 31°C, off below 27°C.

alias: UPS fan control
mode: single
triggers:
  - trigger: numeric_state
    entity_id: sensor.ups_battery_temperature
    above: 31
    id: above
  - trigger: numeric_state
    entity_id: sensor.ups_battery_temperature
    below: 27
    id: below
actions:
  - action: "switch.turn_{{ 'on' if trigger.id == 'above' else 'off' }}"
    target:
      entity_id: switch.ups_usb_fan

The UPS also reports its battery health. When the status changes to Failed, Home Assistant raises a notification with a fixed id, and a second automation dismisses it when the status goes back to Good, which happens when the new battery goes in. The notification stays put until the job is done, which is exactly what you want for something easy to put off.

NAS drives

The QNAP integration gives Home Assistant a temperature sensor for every drive in the NAS. If any of them goes over 60°C, Home Assistant sends a notification to my phone and raises one in Home Assistant too. That has never fired, which is how I like it, but drives that hot don’t last long and I’d rather know.

Leak sensors

Two Aqara water leak sensors sit on the floor, one under the rack and one under the boiler. If either gets wet I get a push notification and a persistent notification in Home Assistant saying which one. Water and a rack full of electrics don’t mix, and a boiler leak is much cheaper to deal with when you find it early.

Leak sensors are one of the cheapest things you can add to a smart home, and one of the most useful. If you only buy one sensor after reading this, buy one of those.

What I’ve learned

  • Use two thresholds, not one. Anything that switches on and off based on a temperature needs a gap between the two numbers.
  • Plan for restarts. Anything triggered by a value crossing a line should recheck when Home Assistant starts.
  • Fixed notification ids. Give a notification an id and you can dismiss it automatically later, so alerts clear themselves when the problem goes away.

All of this sits alongside my server alerts, which tell me when a machine in the rack stops responding.

[jackwent]