Last active
May 25, 2025 01:28
-
-
Save radiaku/41bb687c4c1d07d00aa87ce13dc4672f to your computer and use it in GitHub Desktop.
custom fan control using i8kctl on alienware m15 with cachyos ( arch based linux )
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 | |
# LOG_FILE="~/fan_control.log" | |
# Initialize last fan state | |
LAST_LEFT=-1 | |
LAST_RIGHT=-1 | |
while true; do | |
# Get CPU temperature | |
CPU_TEMP=$(sensors | awk '/^CPU:/ { gsub(/\+|°C/, "", $2); print int($2) }') | |
# Get GPU temperature | |
GPU_TEMP=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits) | |
# Default fan levels | |
LEFT=0 # CPU fan | |
RIGHT=0 # GPU fan | |
# Determine CPU fan speed | |
if (( CPU_TEMP < 80 )); then | |
LEFT=1 # Medium | |
else | |
LEFT=2 # High | |
fi | |
# Determine GPU fan speed | |
if (( GPU_TEMP < 70 )); then | |
RIGHT=1 # Medium | |
else | |
RIGHT=2 # High | |
fi | |
# Apply fan settings only if changed | |
if [[ "$LEFT" -ne "$LAST_LEFT" ]]; then | |
sudo /usr/bin/i8kctl fan1 $LEFT | |
LAST_LEFT=$LEFT | |
fi | |
if [[ "$RIGHT" -ne "$LAST_RIGHT" ]]; then | |
sudo /usr/bin/i8kctl fan2 $RIGHT | |
LAST_RIGHT=$RIGHT | |
fi | |
echo "$(date): CPU Temp: $CPU_TEMP°C, GPU Temp: $GPU_TEMP°C, CPU Fan: $LEFT, GPU Fan: $RIGHT" >> $LOG_FILE | |
sleep 5 | |
done |
run this:
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl restart custom_fan_control.service
sudo systemctl status custom_fan_control.service
Dont forget to set i8kctl run without sudo
sudo visudo
add this line, last line:
radia ALL=(ALL) NOPASSWD: /usr/bin/i8kctl
where radia is your username
UPDATE , after install fancontrol_ui
I dont know what happen, but now fan1 not working.
you need
which i8kctl
if on
/usr/local/bin/i8kctl
just replace the old
sudo mv /usr/local/bin/i8kctl /usr/bin/i8kctl
#!/bin/bash
# LOG_FILE="~/fan_control.log"
# Initialize last fan state
LAST_LEFT=-1
LAST_RIGHT=-1
while true; do
# Get CPU temperature
CPU_TEMP=$(sensors | awk '/^CPU:/ { gsub(/\+|°C/, "", $2); print int($2) }')
# Get GPU temperature
GPU_TEMP=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits)
# Default fan levels
LEFT=0 # CPU fan
RIGHT=0 # GPU fan
# Determine CPU fan speed
if (( CPU_TEMP < 80 )); then
LEFT=1 # Medium
else
LEFT=2 # High
fi
# Determine GPU fan speed
if (( GPU_TEMP < 70 )); then
RIGHT=1 # Medium
else
RIGHT=2 # High
fi
# Apply fan settings only if changed
if [[ "$LEFT" -ne "$LAST_LEFT" ]]; then
sudo /usr/bin/i8kctl fan $LEFT 0
LAST_LEFT=$LEFT
fi
if [[ "$RIGHT" -ne "$LAST_RIGHT" ]]; then
sudo /usr/bin/i8kctl fan 0 $RIGHT
LAST_RIGHT=$RIGHT
fi
# echo "$(date): CPU Temp: $CPU_TEMP°C, GPU Temp: $GPU_TEMP°C, CPU Fan: $LEFT, GPU Fan: $RIGHT" >> $LOG_FILE
sleep 5
done
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add this
/etc/systemd/system/custom_fan_control.service
dont froget change radia, to your username