Skip to content

Instantly share code, notes, and snippets.

@garystafford
Last active April 13, 2021 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garystafford/a2ea1d6e50880ce66cd03367c3397fbf to your computer and use it in GitHub Desktop.
Save garystafford/a2ea1d6e50880ce66cd03367c3397fbf to your computer and use it in GitHub Desktop.
def dict_from_payload(base64_input: str, fport: int = None):
""" Healthy Home Sensor IAQ (TBHV110) binary payload decoder """
decoded = base64.b64decode(base64_input)
# Byte 1
status = decoded[0] & 0b00000001
# Byte 2
battery = decoded[1] & 0b00001111
battery = (25 + battery) / 10
# Byte 3
board_temp = decoded[2] & 0b01111111
board_temp = board_temp - 32
# Byte 4
rh = decoded[3] & 0b01111111
# Byte 5-6
eco2 = decoded[5] << 8 | decoded[4]
# Byte 7-8
voc = decoded[7] << 8 | decoded[6]
# Byte 9-10
iaq = decoded[9] << 8 | decoded[8]
# Byte 11
env_temp = decoded[10] & 0b1111111
env_temp = env_temp - 32
result = {
'Status': status,
'Battery': battery,
'BoardTemp': board_temp,
'RH': rh,
'ECO2': eco2,
'VOC': voc,
'IAQ': iaq,
'EnvTemp': env_temp,
}
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment