Skip to content

Instantly share code, notes, and snippets.

@chand1012
Created February 20, 2018 18:19
Show Gist options
  • Save chand1012/1ae6f3703089526b3ac9148e8f79dccb to your computer and use it in GitHub Desktop.
Save chand1012/1ae6f3703089526b3ac9148e8f79dccb to your computer and use it in GitHub Desktop.
Get CPU and GPU temps from Windows with Python and OHM
import wmi
def avg(value_list):
num = 0
length = len(value_list)
for val in value_list:
num += val
return num/length
w = wmi.WMI(namespace="root\\OpenHardwareMonitor")
sensors = w.Sensor()
cpu_temps = []
gpu_temp = 0
for sensor in sensors:
if sensor.SensorType==u'Temperature' and not 'GPU' in sensor.Name:
cpu_temps += [float(sensor.Value)]
elif sensor.SensorType==u'Temperature' and 'GPU' in sensor.Name:
gpu_temp = sensor.Value
print "Avg CPU: {}".format(avg(cpu_temps))
print "GPU: {}".format(gpu_temp)
@wfxey
Copy link

wfxey commented May 12, 2024

wmi.x_wmi: <x_wmi: Unexpected COM Error (-2147217394, 'OLE error 0x8004100e', None, None)>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment