diff --git a/README.md b/README.md index b675f6f..929ca44 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ # fancontrol -Scripts for controlling the fans on my unraid server + +My Unraid server uses an MSI Z97 Gaming 5 Motherboard which I got secondhand. Unfortunately it has a couple of issues: + +1. The onboard CPU temperature doesn't work. This means the CPU fan doesn't ramp up when the CPU gets hot. +2. The lowest the case fans can go down to is 50% using the smart control on the motherboard. This is still quite loud when using Noctua fans as it equates to 800rpm. + +I have these scripts to control the fans in my case. + +Fans: +hwmon3/fan2_input - hwmon3/pwm2 - CPU +hwmon3/fan3_input - hwmon3/pwm3 - Front Bottom +hwmon3/fan5_input - hwmon3/pwm5 - Front Top (Array fan) - This currently being controlled by the Fan Control Plugin in unraid. +hwmon3/fan4_input - hwmon3/pwm4 - Rear Exhaust \ No newline at end of file diff --git a/cpufan.sh b/cpufan.sh new file mode 100644 index 0000000..16ce396 --- /dev/null +++ b/cpufan.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Inspired by https://github.com/kmwoley/unRAID-Tools/blob/master/unraid_array_fan.sh + +# User Defined variables +FAN_LOW_PWM=30 +FAN_HIGH_PWM=255 +FAN_START_PWM=50 # technically 30 but setting higher to ensure fan is running +LOW_TEMP=28 +HIGH_TEMP=60 +CPU_FAN=/sys/class/hwmon/hwmon3/pwm2 +# End of user defined variables + +NUM_STEPS=$((HIGH_TEMP - LOW_TEMP)) +PWM_INCREMENT=$(( (FAN_HIGH_PWM - FAN_LOW_PWM) / NUM_STEPS)) +OUTPUT+="Linear PWM Range is "$FAN_LOW_PWM" to "$FAN_HIGH_PWM" in "$NUM_STEPS" increments of "$PWM_INCREMENT$'\n' + +# Enable speed change on this fan if not already +if [ "$CPU_FAN" != "1" ]; then + echo 1 > "${CPU_FAN}_enable" +fi + +PREVIOUS_SPEED=`cat $CPU_FAN` + +# TODO: Get from sensors +CPU_TEMP=30 + +if [ "$CPU_TEMP" -le "$LOW_TEMP" ]; then + echo $FAN_LOW_PWM > $CPU_FAN + OUTPUT+="Setting pwm to: "$FAN_LOW_PWM$'\n' +elif [ "$CPU_TEMP" -ge "$HIGH_TEMP" ]; then + echo $FAN_HIGH_PWM > $CPU_FAN + OUTPUT+="Setting pwm to: "$FAN_HIGH_PWM$'\n' +else + # set fan to starting speed first to make sure it spins up then change it to low setting. + if [ "$PREVIOUS_SPEED" -lt "$FAN_START_PWM" ]; then + echo $FAN_START_PWM > $CPU_FAN + sleep 4 + fi + + # Calculate target fan PWM speed as a linear value between FAN_HIGH_PWM and FAN_LOW_PWM + FAN_LINEAR_PWM=$(( ((CPU_TEMP - LOW_TEMP) * PWM_INCREMENT) + FAN_LOW_PWM)) + echo $FAN_LINEAR_PWM > $CPU_FAN + OUTPUT+="Setting pwm to: "$FAN_LINEAR_PWM$'\n' +fi + +# produce output if the fan speed was changed +CURRENT_SPEED=`cat $CPU_FAN` +if [ "$PREVIOUS_SPEED" -ne "$CURRENT_SPEED" ]; then + echo "Fan speed has changed." + echo "${OUTPUT}" +else + echo "Fan speed unchanged. Highest temp: "$HIGHEST_TEMP" Current pwm: "$CURRENT_SPEED +fi \ No newline at end of file