Auto nvidia fan speed depending on temperature

I did not want to write a how to, basically i just wanted to post the script. I am sure this could be made to work with SLI cards, I haven’t tried.

To be able to add fan control and overclocking.
Type this into the terminal. (changing 13 to 4 should make it fan only, and leave overclocking disabled)

nvidia-xconfig --cool-bits=*13*

Restart your system. After adding that and restarting, you should be able to adjust the clocks and fan.

To add a script that automatically changes the fan speeds. Create the file nvfc.sh with a text editor. Copy the code below to make the fan set automatically. Save, run and test.

If it works well for you, then you can make it start with Suse automatically.

Rename nvfc.sh to .desktop and paste to given dir. Or create file from scratch at dir.
To add a script that starts automatically and to change the fan speeds. Create the file nvfc.desktop with a text editor where “XXX” is your username, at “/home/XXX/.config/autostart-scripts/”. Copy the code below, to make the fan set automatically from start. I am not sure how .desktop files work exactly, I do know that you cannot run the nvfc.desktop file directly, but it does load on startup, and is what I wanted.

#!/bin/bash

#Sets Overclocking state to 1, enabling you to add +60 coreclock on the 3rd power level. Disable with "#" in front of it.
    #nvidia- settings -a [GPU:0]/GPUOverclockingState=1
    #nvidia-settings -a [gpu:0]/GPUGraphicsClockOffset[3]=60
    
        new_speed=0
        interval=5
    
    # continually loop
    while  "1" -eq "1" ]; do
    
    current_temp=`nvidia-settings -t -q [GPU:0]/GPUCoreTemp`
    current_speed=`nvidia-settings -t -q [fan:0]/GPUCurrentFanSpeed`

    #check current temperature and adjust fan speed 
    #If temp less than 43'c, then set to 40% speed
        if  "$current_temp" -lt "43" ]; then
            let "new_speed = 40"
            nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUCurrentFanSpeed=$new_speed
    fi
    #If temp more than 43'c, then set speed% to temp+10
    if  "$current_temp" -gt "43" ]; then
            let "new_speed = $current_temp + 10"
            nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUCurrentFanSpeed=$new_speed
    fi
    #If speed more than 72%, then set to 72% speed
    if  "$current_speed" -gt "72" ]; then
            let "new_speed = 72"
            nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUCurrentFanSpeed=$new_speed
    fi

    #wait until interval expires before rechecking
    sleep "$interval"
    done

You may restart and test if fan settings are good for you. Setting the fan speed is as straightforward as changing the values, comments should make it easy. If you would like to kill the current script and test out some values, search for nvfc in ksysgaurd, click on it and press delete.

You may overclock at your own risk, I take no responsibility for anything going wrong. I just wanted to post this script to allow people to cool their nvidia gpu’s on Suse easily.

Can’t edit it seems.

Where it says Rename nvfc.sh to .desktop and paste to given dir. should be rename nvfc.sh to nvfc.desktop.

I just noticed that I incorrectly limited the upper limit. It will still work with previous code, but not correctly.

#!/bin/bash
    #nvidia-settings -a [GPU:0]/GPUOverclockingState=1
    #nvidia-settings -a [gpu:0]/GPUGraphicsClockOffset[3]=60
    
        new_speed=0
        interval=5
    
    # continually loop
    while  "1" -eq "1" ]; do
    
    current_temp=`nvidia-settings -t -q [GPU:0]/GPUCoreTemp`
    current_speed=`nvidia-settings -t -q [fan:0]/GPUCurrentFanSpeed`

    #check current temperature and adjust fan speed
    

    if  "$current_temp" -lt "43" ]; then
            let "new_speed = 40"
            nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUCurrentFanSpeed=$new_speed
    fi
    
    if  "$current_temp" -gt "43" ]; then
    
            let "new_speed = $current_temp + 10"
**            #limits to 72
            if  "$new_speed" -gt "72" ]; then
            new_speed=72
            fi**
            nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUCurrentFanSpeed=$new_speed
    fi
    
    #wait until interval expires before rechecking
    sleep "$interval"
    done

Without testing,
I assume that your recommended location to place your script will only activate on User login, which might be OK if you are either auto login or login manually soon after boot. This might make a significant difference on headless machines and servers (where a User might not login locally).

Various ways to invoke a script on system startup have been described in the Install and Application forums, take your pick.

TSU