Skip to content

Instantly share code, notes, and snippets.

@pirate
Created June 4, 2024 10:34
Show Gist options
  • Save pirate/5f1c68a94d0622f4acdb15c9f86fec7a to your computer and use it in GitHub Desktop.
Save pirate/5f1c68a94d0622f4acdb15c9f86fec7a to your computer and use it in GitHub Desktop.
Setup Unifi Dream Machine (UDM, UDM-SE, etc.) automatic fan speeds control to lower temps and increase hard drive lifespan.
#!/bin/bash
# Installs and configures fancontrol to automatically run Unifi Dream Machine (UDM) fans harder & lower temperatures.
#
# Context: Unifi equipment typically runs *very* hot from the factory unless you customize it.
# I don't want my hard drives to run as hot as they let them get by default (55ºC+), because it shortens lifespan (ideal temp is ~35-45C).
#
# Further Reading:
# - https://linux.die.net/man/8/fancontrol
# - https://community.ui.com/questions/Unifi-Dream-Router-fan-speed/1cb9cf18-e8a0-44b4-8402-ee9bac367bc0
# - https://www.reddit.com/r/Ubiquiti/comments/13imgqj/udm_pro_fan_speed_is_this_normal/
# - https://www.reddit.com/r/Ubiquiti/comments/lw4mjl/fan_speed_trick_on_udmp_not_working_on_190/
# - https://github.com/heXeo/ubnt-fan-speed/issues/3
# - https://ewpratten.com/blog/udm-fan/
# - https://github.com/desbma/hddfancontrol
# - https://unix.stackexchange.com/questions/499409/adjust-fan-speed-via-fancontrol-according-to-hard-disk-temperature-hddtemp
echo "[i] Here are your sensor readings before this script runs (for before/after comparison):"
sensors
hddtemp /dev/sda
hddtemp /dev/sdb
echo
echo
echo "[+] Installing fancontrol package using apt..."
apt-get update -qq
apt-get install -y fancontrol
echo
echo "[+] Setting up /etc/fancontrol config file (edit as-desired after this script completes)..."
tee /etc/fancontrol <<EOF
INTERVAL=1
DEVPATH=hwmon0=devices/platform/soc/fd880000.i2c-pld/i2c-0/i2c-4/4-002e
DEVNAME=hwmon0=adt7475
FCTEMPS=hwmon0/device/pwm2=hwmon0/device/temp1_input hwmon0/device/pwm1=hwmon0/device/temp3_input
FCFANS=hwmon0/device/pwm2=hwmon0/device/fan2_input hwmon0/device/pwm1=hwmon0/device/fan1_input
MINTEMP=hwmon0/device/pwm2=38 hwmon0/device/pwm1=38
MAXTEMP=hwmon0/device/pwm2=49 hwmon0/device/pwm1=49
MINSTART=hwmon0/device/pwm2=30 hwmon0/device/pwm1=30
MINSTOP=hwmon0/device/pwm2=15 hwmon0/device/pwm1=15
MINPWM=hwmon0/device/pwm2=10 hwmon0/device/pwm1=10
MAXPWM=hwmon0/device/pwm2=255 hwmon0/device/pwm1=255
EOF
echo "[*] Restarting fancontrol service to apply changes..."
systemctl restart fancontrol
sleep 1
echo
echo "[√] Complete. Check the sensor readings to make sure fans are spinning faster:"
sensors
hddtemp /dev/sda
hddtemp /dev/sdb
# Typical Values on my machine after setting this up:
#
# root@UDM ~# sensors
#
# adt7475-i2c-4-2e
# Adapter: i2c-0-mux (chan_id 3)
# in1: 908.00 mV (min = +0.00 V, max = +2.99 V)
# +3.3V: 3.29 V (min = +2.96 V, max = +3.63 V)
# fan1: 5288 RPM (min = 0 RPM)
# fan2: 2349 RPM (min = 0 RPM)
# fan3: 0 RPM (min = 0 RPM)
# fan4: 0 RPM (min = 0 RPM)
# temp1: +42.5°C (low = -63.0°C, high = +191.0°C)
# (crit = +100.0°C, hyst = +96.0°C)
# Board Temp: +42.0°C (low = -63.0°C, high = +191.0°C)
# (crit = +100.0°C, hyst = +96.0°C)
# temp3: +43.8°C (low = -63.0°C, high = +191.0°C)
# (crit = +100.0°C, hyst = +96.0°C)
#
# root@UDM ~# hddtemp /dev/sda
# /dev/sda: KINGSTON OM4P0S3128B-A0: 49°C
#
# root@UDM ~# hddtemp /dev/sdb
# /dev/sdb: WDC WD101EMAZ-11G7DA0: 45°C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment