Created
June 4, 2024 10:34
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
For the base UDM it's slightly different as it only has one fan and the sensor chip is not the same. Also it must run a little hotter as the fan ramps up and is rather noticeable.
INTERVAL=2
DEVPATH=hwmon0=devices/platform/soc/fd880000.i2c-pld/i2c-0/0-004c
DEVNAME=hwmon0=lm63
FCTEMPS=hwmon0/device/pwm1=hwmon0/device/temp1_input hwmon0/device/pwm1=hwmon0/device/temp2_input
FCFANS=hwmon0/device/pwm1=hwmon0/device/fan1_input
MINTEMP=hwmon0/device/pwm1=40
MAXTEMP=hwmon0/device/pwm1=64
MINSTART=hwmon0/device/pwm1=30
MINSTOP=hwmon0/device/pwm1=15
MINPWM=hwmon0/device/pwm1=10
MAXPWM=hwmon0/device/pwm1=255
Sensors output;
sensors
lm63-i2c-0-4c
Adapter: Synopsys DesignWare I2C adapter
fan1: 6490 RPM (min = 4205 RPM)
temp1: +63.0°C (high = +70.0°C)
temp2: +59.2°C (low = +0.0°C, high = +70.0°C)
(crit = +93.0°C, hyst = +83.0°C)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello friends,
Here is the solution to have this working even after reboots or updates. Initially was thinking to either SSH from other machine (as suggested by @pirate or to run Ansible every day (now knowing if the DM was reset or not). But finally, I found a more elegant solution:
Follow these instructions https://github.com/unifi-utilities/unifios-utilities/blob/main/on-boot-script-2.x/README.md . You can build the package yourself or just run the
curl | bashcommand (not recommended, but at least check the script first).This will create a
/data/folder which conveniently has anon_boot.ddirectory