Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kelon AC IR command decoder
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
MODES = {
0: "heat",
1: "smart",
2: "cool",
3: "dehum",
4: "fan"
}
FAN_SPEEDS = {
0: "auto",
1: "max",
2: "medium",
3: "min"
}
if __name__ == "__main__":
numstr = sys.argv[1]
base = 10
if numstr.startswith("0x"):
base = 16
elif numstr.startswith("0o"):
base = 8
elif numstr.startswith("0b"):
base = 2
num = int(numstr, base)
num >>= 16 # Strip preamble
print(f"Fan speed: {FAN_SPEEDS[num & 0b11]}")
num >>= 2
print(f"Power: {'pressed' if num & 1 else 'not pressed'}")
num >>= 1
print(f"Sleep: {'on' if num & 1 else 'off'}")
num >>= 1
print(f"Dehum intensity: {'-' if num & 0b100 == 0b100 else '+'}{num & 0b11}")
num >>= 3
print(f"Swing: {'pressed' if num & 1 else 'not pressed'}")
num >>= 1
print(f"Mode: {MODES[num & 0b111]}")
num >>= 3
print(f"Timer: {'on' if num & 1 else 'off'}")
num >>= 1
print(f"Temperature: {(num & 0b1111) + 18}°C")
num >>= 4
timer_half = num & 1
num >>= 1
timer_hour = num & 0b111111
num >>= 6
timer_time = 0
if timer_hour >= 10:
timer_time = (timer_hour << 1 | timer_half) - 10
else:
timer_time = timer_hour + (0.5 if timer_half else 0)
print(f"Timer duration: {timer_time}h")
print(f"Smart mode: {'on' if num & 1 else 'off'}")
num >>= 5 # Also strip unknown always-zero bits
if num & 0b1001 == 0b1001:
print(f"Supercool mode: on")
elif num & 0b1000 == 0b1000 or num & 0b0001 == 0b0001:
print(f"Supercool mode might be on but wtf")
else:
print(f"Supercool mode: off")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment