#!/bin/env python3 import time import os import math os.chdir('/sys/class/drm/card0/device/hwmon/hwmon2/') temp = 'temp1' fan = 'fan1' def read(path): with open(path) as f: return int(f.read()) def write(path, n): with open(path, 'w') as f: f.write(str(n)) fan_min = read(fan+"_min") fan_max = read(fan+"_max") print(fan_min, fan_max) write(fan+"_enable", 1) while True: t = read(temp+"_input")/1000 temp_min = 40 temp_max = 80 if t < temp_min: f = fan_min elif t > temp_max: f = fan_max else: p = math.floor((t-temp_min)/(temp_max - temp_min)*(fan_max - fan_min) + fan_min) print(t, p) write(fan+'_target', p) time.sleep(1)