Skip to content

Instantly share code, notes, and snippets.

@garystafford
Last active April 14, 2021 13:04
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/6458b8ef2fce0857b4ce0fb5aaf0cd9d to your computer and use it in GitHub Desktop.
Save garystafford/6458b8ef2fce0857b4ce0fb5aaf0cd9d 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 0, bit 0
status = decoded[0] & 0b00000001 # (1 << 1) - 1
# Byte 1, bits 3:0
battery = decoded[1] & 0b00001111 # (1 << 4) - 1
battery = (25 + battery) / 10
# Byte 2, bits 6:0
board_temp = decoded[2] & 0b01111111 # (1 << 7) - 1
board_temp = board_temp - 32
# Byte 3, bits 6:0
rh = decoded[3] & 0b01111111 # (1 << 7) - 1
# Byte 5-4, bits 15:0
eco2 = decoded[5] << 8 | decoded[4]
# Byte 7-6, bits 15:0
voc = decoded[7] << 8 | decoded[6]
# Byte 9-8, bits 15:0
iaq = decoded[9] << 8 | decoded[8]
# Byte 10, bits 6:0
env_temp = decoded[10] & 0b1111111 # (1 << 7) - 1
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