Skip to content

Instantly share code, notes, and snippets.

Last active January 23, 2023 15:00
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Basic programm to use hidapi and report temp/co2 from Holtek Semiconductor, Inc. USB-zyTemp (hidapi is python3-hidapi in debian buster)
from hidapi import Device
vid = 0x04d9
pid = 0xa052
print("Opening the device")
h = Device(vendor_id=vid, product_id=pid, blocking=False), pid) # TREZOR VendorID/ProductID
print("Manufacturer: %s" % h.get_manufacturer_string())
print("Product: %s" % h.get_product_string())
print("Serial No: %s" % h.get_serial_number_string())
#print("Get feature report:")
print("Send feature report:")
h.send_feature_report(bytearray([0xc4, 0xc6, 0xc0, 0x92, 0x40, 0x23, 0xdc, 0x96]), report_id=bytes(1))
while True:
r =
if r:
# print('read: "{}"'.format(r))
metric = r[0]
value = r[1]
value_thousands = r[2]
checksum = r[3]
r4 = r[4]
if r4 != 0x0d:
print("Unexpected data from device")
value_sum = metric + value + value_thousands
#if checksum != metric + value + value_thousands:
# continue
# print("Checksum error")
metric_name = ""
value_shifted = value << 8
metric_value = value_shifted + value_thousands
if metric == 0x42:
metric_name = "Temperature"
metric_value = metric_value / 16 - 273.15
elif metric == 0x50:
metric_name = "CO2"
elif metric == 0x44:
metric_name = "Humidity"
metric_name = "Unknown"
print(hex(metric), metric_name, "%.1f" % metric_value)
print("Closing the device")
except IOError as ex:
print("You probably don't have the hard-coded device.")
print("Update the line in this script with the one")
print("from the enumeration list output above and try again.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment