Last active
September 9, 2021 13:17
-
-
Save FFY00/a089580df5d8f4276eab5b1dd0169123 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import pathlib | |
import subprocess | |
import time | |
# paired with fan speed (0-255) and temp (degrees C) | |
f_low_speed = 40 | |
f_low_temp = 35 | |
f_high_speed = 255 | |
f_high_temp = 80 | |
old_f_speed = f_speed = 255 | |
sys_platform = pathlib.Path('/sys/devices/platform') | |
temperature_files = list(sys_platform.rglob('coretemp.*/hwmon/hwmon*/temp*_input')) | |
while True: | |
max_temp = max( | |
int(file.read_text()) // 1000 | |
for file in temperature_files | |
) | |
# find what speed the fan should be | |
if max_temp < f_low_temp: | |
f_speed = f_low_speed | |
elif max_temp > f_high_temp: | |
f_speed = f_high_speed | |
else: | |
f_speed_f = f_low_speed + ((max_temp - f_low_temp) / (f_high_temp - f_low_temp) * (f_high_speed - f_low_speed)) | |
f_speed = int(f_speed_f) | |
print(f'Temperature: {max_temp}°C, Fan speed: 0x{f_speed:02x}') | |
if old_f_speed != f_speed: | |
subprocess.check_output(['ipmitool', 'raw', '0x3a', '0x07', '0x1', hex(f_speed), '0x01']) | |
subprocess.check_output(['ipmitool', 'raw', '0x3a', '0x07', '0x2', hex(f_speed), '0x01']) | |
subprocess.check_output(['ipmitool', 'raw', '0x3a', '0x07', '0x3', hex(f_speed), '0x01']) | |
old_f_speed = f_speed | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment