Skip to content

Instantly share code, notes, and snippets.

@mildsunrise
Last active April 16, 2024 11:30
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mildsunrise/1d576669b63a260d2cff35fda63ec0b5 to your computer and use it in GitHub Desktop.
Save mildsunrise/1d576669b63a260d2cff35fda63ec0b5 to your computer and use it in GitHub Desktop.
Documentation of Tuya's weird compression scheme for IR codes

Tuya's IR blasters, like the ZS08, have the ability to both learn and blast generic IR codes. These IR codes are given to the user as an opaque string, like this:

A/IEiwFAAwbJAfIE8gSLIAUBiwFAC+ADAwuLAfIE8gSLAckBRx9AB0ADBskB8gTyBIsgBQGLAUALA4sB8gRAB8ADBfIEiwHJAeARLwHJAeAFAwHyBOC5LwGLAeA97wOLAfIE4RcfBYsB8gTyBEAFAYsB4AcrCYsB8gTyBIsByQHgPY8DyQHyBOAHAwHyBEAX4BVfBIsB8gTJoAMF8gSLAckB4BUvAckB4AEDBfIEiwHJAQ==

Not much is known about the format of these IR code strings, which makes it difficult to use codes obtained through other means (such as a manual implementation of the IR protocol for a particular device, or public Internet code tables) with these blasters, as well as to use codes learnt through these blasters with other brands of blasters and study their contents.

So far I've only been able to find one person who dug into this before me, who was able to understand it enough to create their own codes to blast, but not enough to understand codes learnt by the device.

This document attempts to fully document the format and also provides a (hopefully) working Python implementation.

Overview

There is no standard for IR codes, so appliances use different methods to encode the data into an IR signal, often called "IR protocols". A popular one, which could be considered an unofficial standard, is the NEC protocol. NEC specifies a way to encode 16 bits as a series of pulses of modulated IR light, but it's just one protocol.

Tuya's IR blasters are meant to be generic and work with just about any protocol. To do that, they work at a lower level and record the IR signal directly instead of detecting a particular protocol and decoding the bits. In particular, the blaster records a binary signal like this one:

  +------+     +----------+  +-+
  |      |     |          |  | |
--+      +-----+          +--+ +---

Such a signal can be represented by noting the times at which the signal flips from low to high and viceversa. It is better to record the differences of these times as they will be smaller numbers. For example, the above signal is represented as:

[7, 6, 11, 3, 2]

Meaning, the signal stays high for 7 units of time, then low for 6 units of time, then high for 11 units, and so on. The first time is always for a high state, which means even times (2nd, 4th, 6th...) are always low periods while odd times (1st, 3rd, 5th...) are always high periods.

The blaster takes these numbers (in units of microseconds) and encodes each of them as a little-endian 16-bit integer, resulting in the following 10 bytes:

07 00 06 00 0B 00 03 00 02 00

Because we're recording a signal rather than high-level protocol data, this results in very long messages in real life. So, the blaster compresses these bytes using a weird algorithm (see below), and then encodes the resulting bytes using base64 so the user can copy/paste the code easily.

Compression scheme

Update: Turns out this is FastLZ compression. No need to read this section, you can go to their website instead.

I was unable to find a public algorithm that matched this, so I'm assuming it's a custom lossless compression algorithm that a random Tuya employee hacked to make my life more complicated. Jokes aside it seems to be doing a very poor job, and if I were them I would've just used Huffman coding or something.

Anyway, the algorithm is LZ77-based, with a fixed 8kB window. The stream contains a series of blocks. Each block begins with a "header byte", and the 3 MSBs of this byte determine the type of block:

  • If the 3 bits are zero, then this is a literal block and the other 5 bits specify a length L minus one.

    Upon encountering this block, the decoder consumes the next L bytes from the stream and emits them as output.

    +---------+-----------------------------+
    |000LLLLLL| 1..32 bytes, depending on L |
    +---------+-----------------------------+
    
  • If the 3 bits have any other value, then this is a length-distance pair block; the 3 bits specify a length L minus 2, and the concatenation of the other 5 bits with the next byte specifies a distance D minus 1.

    Upon encountering this block, the decoder copies L bytes from the previous output. It begins copying D bytes before the output cursor, so if D = 1, the first copied byte is the most recently emitted byte; if D = 2, the byte before that one, and so on.

    As usual, it may happen that L > D, in which case the output repeats as necessary (for example if L = 5 and D = 2, and the 2 last emitted bytes are X and Y, the decoder would emit XYXYX).

    +--------+--------+
    |LLLDDDDD|DDDDDDDD|
    +--------+--------+
    

    As a special case, if the 3 bits are one, then there's an extra byte preceding the distance byte, which specifies a value to be added to L:

    +--------+--------+--------+
    |111DDDDD|LLLLLLLL|DDDDDDDD|
    +--------+--------+--------+
    
import io
import base64
from bisect import bisect
from struct import pack, unpack
# MAIN API
def decode_ir(code: str) -> list[int]:
'''
Decodes an IR code string from a Tuya blaster.
Returns the IR signal as a list of µs durations,
with the first duration belonging to a high state.
'''
payload = base64.decodebytes(code.encode('ascii'))
payload = decompress(io.BytesIO(payload))
signal = []
while payload:
assert len(payload) >= 2, \
f'garbage in decompressed payload: {payload.hex()}'
signal.append(unpack('<H', payload[:2])[0])
payload = payload[2:]
return signal
def encode_ir(signal: list[int], compression_level=2) -> str:
'''
Encodes an IR signal (see `decode_tuya_ir`)
into an IR code string for a Tuya blaster.
'''
payload = b''.join(pack('<H', t) for t in signal)
compress(out := io.BytesIO(), payload, compression_level)
payload = out.getvalue()
return base64.encodebytes(payload).decode('ascii').replace('\n', '')
# DECOMPRESSION
def decompress(inf: io.FileIO) -> bytes:
'''
Reads a "Tuya stream" from a binary file,
and returns the decompressed byte string.
'''
out = bytearray()
while (header := inf.read(1)):
L, D = header[0] >> 5, header[0] & 0b11111
if not L:
# literal block
L = D + 1
data = inf.read(L)
assert len(data) == L
else:
# length-distance pair block
if L == 7:
L += inf.read(1)[0]
L += 2
D = (D << 8 | inf.read(1)[0]) + 1
data = bytearray()
while len(data) < L:
data.extend(out[-D:][:L-len(data)])
out.extend(data)
return bytes(out)
# COMPRESSION
def emit_literal_blocks(out: io.FileIO, data: bytes):
for i in range(0, len(data), 32):
emit_literal_block(out, data[i:i+32])
def emit_literal_block(out: io.FileIO, data: bytes):
length = len(data) - 1
assert 0 <= length < (1 << 5)
out.write(bytes([length]))
out.write(data)
def emit_distance_block(out: io.FileIO, length: int, distance: int):
distance -= 1
assert 0 <= distance < (1 << 13)
length -= 2
assert length > 0
block = bytearray()
if length >= 7:
assert length < (1 << 8)
block.append(length - 7)
length = 7
block.insert(0, length << 5 | distance >> 8)
block.append(distance & 0xFF)
out.write(block)
def compress(out: io.FileIO, data: bytes, level=2):
'''
Takes a byte string and outputs a compressed "Tuya stream".
Implemented compression levels:
0 - copy over (no compression, 3.1% overhead)
1 - eagerly use first length-distance pair found (linear)
2 - eagerly use best length-distance pair found
3 - optimal compression (n^3)
'''
if level == 0:
return emit_literal_blocks(out, data)
W = 2**13 # window size
L = 256+9 # maximum length
distance_candidates = lambda: range(1, min(pos, W) + 1)
def find_length_for_distance(start: int) -> int:
length = 0
limit = min(L, len(data) - pos)
while length < limit and data[pos + length] == data[start + length]:
length += 1
return length
find_length_candidates = lambda: \
( (find_length_for_distance(pos - d), d) for d in distance_candidates() )
find_length_cheap = lambda: \
next((c for c in find_length_candidates() if c[0] >= 3), None)
find_length_max = lambda: \
max(find_length_candidates(), key=lambda c: (c[0], -c[1]), default=None)
if level >= 2:
suffixes = []; next_pos = 0
key = lambda n: data[n:]
find_idx = lambda n: bisect(suffixes, key(n), key=key)
def distance_candidates():
nonlocal next_pos
while next_pos <= pos:
if len(suffixes) == W:
suffixes.pop(find_idx(next_pos - W))
suffixes.insert(idx := find_idx(next_pos), next_pos)
next_pos += 1
idxs = (idx+i for i in (+1,-1)) # try +1 first
return (pos - suffixes[i] for i in idxs if 0 <= i < len(suffixes))
if level <= 2:
find_length = { 1: find_length_cheap, 2: find_length_max }[level]
block_start = pos = 0
while pos < len(data):
if (c := find_length()) and c[0] >= 3:
emit_literal_blocks(out, data[block_start:pos])
emit_distance_block(out, c[0], c[1])
pos += c[0]
block_start = pos
else:
pos += 1
emit_literal_blocks(out, data[block_start:pos])
return
# use topological sort to find shortest path
predecessors = [(0, None, None)] + [None] * len(data)
def put_edge(cost, length, distance):
npos = pos + length
cost += predecessors[pos][0]
current = predecessors[npos]
if not current or cost < current[0]:
predecessors[npos] = cost, length, distance
for pos in range(len(data)):
if c := find_length_max():
for l in range(3, c[0] + 1):
put_edge(2 if l < 9 else 3, l, c[1])
for l in range(1, min(32, len(data) - pos) + 1):
put_edge(1 + l, l, 0)
# reconstruct path, emit blocks
blocks = []; pos = len(data)
while pos > 0:
_, length, distance = predecessors[pos]
pos -= length
blocks.append((pos, length, distance))
for pos, length, distance in reversed(blocks):
if not distance:
emit_literal_block(out, data[pos:pos + length])
else:
emit_distance_block(out, length, distance)
@ferehcarb
Copy link

Hi, tuya cloud offers an API to get IR codes: https://developer.tuya.com/en/docs/cloud/universal-infrared?id=K9jgsgd7buln4#title-38-Get%20pairing%20rules%20of%20remote%20control
Unfortunately the code doesn't seem to be in the same format as you described here.
I tried to unterstand how it is compressed/encrypted but with no luck.
Here's an exemple for an Air conditioner, the code is base64 encoded but the result in not in FastLZ format.

{
  "result": [
    {
      "code": "9wIGR9Y6tL8R+3GOyeGh/S5a6c8Zq61qOrY7b96Yiao=",
      "key": "M0_T16_S0",
      "key_id": 0
    },
    {
      "code": "dsHOt9ZiRp0h6cLsQK/cdjGeaViVLOt7NMfuhKLJAXE=",
      "key": "M0_T16_S1",
      "key_id": 0
    },
    {
      "code": "XU91P/M4k3QZmapyi5hzGiCVE21b1fxilNpSe3HcawA=",
      "key": "M0_T16_S2",
      "key_id": 0
    },
    {
      "code": "Wl2rceJbm0oz673iLLL/IaaxSDqCZeU7dVYdD0gAOGI=",
      "key": "M0_T16_S3",
      "key_id": 0
    },
    {
      "code": "yc6wzg1fEll4+4CT4xNOCrRQCjtm57eTm43ucfeT8dQ=",
      "key": "M0_T17_S0",
      "key_id": 0
    },
    {
      "code": "wWRuImgjKufIFM6+DPsZov4hDKE3UXOcVUtPImeCJ4E=",
      "key": "M0_T17_S1",
      "key_id": 0
    },
    {
      "code": "vR/j9atl1tmMU9RiSO5wbBnuYWmKYrTYzV5bh9l8kts=",
      "key": "M0_T17_S2",
      "key_id": 0
    },
    {
      "code": "yssD16+ekpA1abSL7lvOhI2b2DABEKoK6FH/dUQNr7A=",
      "key": "M0_T17_S3",
      "key_id": 0
    },
    {
      "code": "vGTcLKdwGgLtr6qAIbTPdtvNBqVGtA0xuDcBQZ+N6Ko=",
      "key": "M0_T18_S0",
      "key_id": 0
    },
    {
      "code": "yUr5pHJvXJ/3NrNlzyztJM1yB+3HAq1opuZp7t8vClU=",
      "key": "M0_T18_S1",
      "key_id": 0
    },
    {
      "code": "ONXNuuti2sptjbQp1ruLJT0rM3atD5pCCN4snKiu7Vk=",
      "key": "M0_T18_S2",
      "key_id": 0
    },
    {
      "code": "ZwvWBWspnHyNLihvj83d7+qbXSEV7rTg6lbKpac6Wps=",
      "key": "M0_T18_S3",
      "key_id": 0
    },
    {
      "code": "5npwODplVah4jwqFnhal3RlC6mHUHwuD9cGTiwOw8hg=",
      "key": "M0_T19_S0",
      "key_id": 0
    },
    {
      "code": "55rwqa5WeKqRg44WcPI6GMkG7yLVnYXYHO9wG/5CJY8=",
      "key": "M0_T19_S1",
      "key_id": 0
    },
    {
      "code": "q4uBpRYw3xdr1v4hg5CmJh7bvo0i5HATWkCQ3G9hKIk=",
      "key": "M0_T19_S2",
      "key_id": 0
    },
    {
      "code": "iBDXW9Bo+JR38bhFD5IHrosU7EHlb2ne0vFG/MkF6mQ=",
      "key": "M0_T19_S3",
      "key_id": 0
    },
    {
      "code": "JmdWcykDdsjToPPqzUq4h7evvmORthxxmd860aEXl4A=",
      "key": "M0_T20_S0",
      "key_id": 0
    },
    {
      "code": "uYg+17UFbQ68wa1uhw6pGdJQRuHTRyDLTiNfGs3HfUA=",
      "key": "M0_T20_S1",
      "key_id": 0
    },
    {
      "code": "ArnHvoq8YTRedrzxV/i0QGSfEBPINVjVSTN0OHNvp/E=",
      "key": "M0_T20_S2",
      "key_id": 0
    },
    {
      "code": "dxJJ+RR9B8elRFTNhM7tILnbRk2CUySKSUc8AZvhCvE=",
      "key": "M0_T20_S3",
      "key_id": 0
    },
    {
      "code": "cRXmsLr9Sddtd9tCYTidUIKU4ph3VOGm3UdfKddvIQ0=",
      "key": "M0_T21_S0",
      "key_id": 0
    },
    {
      "code": "0yI1iwwt/KdzhVdVOgY9mYy6PoaQLS35sqGq+nHOxxY=",
      "key": "M0_T21_S1",
      "key_id": 0
    },
    {
      "code": "IvUJtF/rlHMecqDkeMvCp/FAtKxuQXFdud02IYw6MMA=",
      "key": "M0_T21_S2",
      "key_id": 0
    },
    {
      "code": "PdEr1YWLh0XS7E+PpjXlor3aiZKu0k5Lv2y0pytRQjw=",
      "key": "M0_T21_S3",
      "key_id": 0
    },
    {
      "code": "IFg0+GGmG/8tM5ExjXZvMrv8h19tURjIRYefrgTxdkc=",
      "key": "M0_T22_S0",
      "key_id": 0
    },
    {
      "code": "2Ayne0PWRnEl8zESQ/DZm3nTgSVNS+0CXKIVv8mvtdk=",
      "key": "M0_T22_S1",
      "key_id": 0
    },
    {
      "code": "xFvqIjsQ35uoeL70vV85LhbkGmtyiupH+GIJvh6poQQ=",
      "key": "M0_T22_S2",
      "key_id": 0
    },
    {
      "code": "t3hlRjkNldsMi0VoC4FIviGBy1EIEnL7U2MlmzeoodU=",
      "key": "M0_T22_S3",
      "key_id": 0
    },
    {
      "code": "X9mceI5QaYvOtiLD1f+SBBDUoPCEsiltacmQmZ7hymI=",
      "key": "M0_T23_S0",
      "key_id": 0
    },
    {
      "code": "5o1Uykra/M9cMnIiK5OdWNGih/akOInHZA1habJd7to=",
      "key": "M0_T23_S1",
      "key_id": 0
    },
    {
      "code": "X1enuIvyHi2rA53Wz3YEGOHZzYOllFkApvTrUWRvFek=",
      "key": "M0_T23_S2",
      "key_id": 0
    },
    {
      "code": "ljbb86MmJBrwJZ2ns+CtrDnr/AKqtGiqaWMcWsF9UV4=",
      "key": "M0_T23_S3",
      "key_id": 0
    },
    {
      "code": "XVMhS79+EhW92gjCeyqYCMFRk4o1GRykSOd9ucqoXXw=",
      "key": "M0_T24_S0",
      "key_id": 0
    },
    {
      "code": "poSjYn4iZifrwDNaaavgxtqld1LQWT0UanbvPld7QRU=",
      "key": "M0_T24_S1",
      "key_id": 0
    },
    {
      "code": "3LO0hG/DGJ9aygCWLiCO3aleUraXU6GBvdzVughpFh4=",
      "key": "M0_T24_S2",
      "key_id": 0
    },
    {
      "code": "++BJEcuvWSuzKWl8rQsYZWunXO9VUzcqAqfSqv01HBg=",
      "key": "M0_T24_S3",
      "key_id": 0
    },
    {
      "code": "xazL4hK7FP40D7sfPZotHd98+6Ag1vRfMpGDsm/c7Qg=",
      "key": "M0_T25_S0",
      "key_id": 0
    },
    {
      "code": "hf6MPoavggaCv5ozcCnTLUFGm0MWzpVYCmXb9fAloWg=",
      "key": "M0_T25_S1",
      "key_id": 0
    },
    {
      "code": "opL5p1klRtaB0qgSo+fj0OFnnfGTXG1g1q9LU+GFoFY=",
      "key": "M0_T25_S2",
      "key_id": 0
    },
    {
      "code": "C+lgfJ+KihW5zUnMgkVw9+lqaZstDpIEUOyniEVfTXQ=",
      "key": "M0_T25_S3",
      "key_id": 0
    },
    {
      "code": "CoKUOAvohVBVbRxbN6wp1llOAMswGdIt++NXZ+wBUic=",
      "key": "M0_T26_S0",
      "key_id": 0
    },
    {
      "code": "ZvUOMB2WEpdSZ9x+ijQyIy/GlE093h4FEeHvHi4GgaM=",
      "key": "M0_T26_S1",
      "key_id": 0
    },
    {
      "code": "v4Z8SQhfl3gAlduqe9erK4QkbJJN2nP3WnFyF5YUC5Q=",
      "key": "M0_T26_S2",
      "key_id": 0
    },
    {
      "code": "B4bG9WevMNClvPBeHiVqZ0GeDfGypXKXM7d6ZkYKYAk=",
      "key": "M0_T26_S3",
      "key_id": 0
    },
    {
      "code": "gw8S3yfXG6jsiu8pfy7MrsoaEGnKO9anfIorg4xz8v4=",
      "key": "M0_T27_S0",
      "key_id": 0
    },
    {
      "code": "7ISjjBs5sDcbObUrdJuBSzUeGKNuTyVIYi/m37nOgV0=",
      "key": "M0_T27_S1",
      "key_id": 0
    },
    {
      "code": "s8wtY+L/ZBZAs9EhuIndyC64eIwdHJXb0W5nC+km4io=",
      "key": "M0_T27_S2",
      "key_id": 0
    },
    {
      "code": "/pWWZ6Jo0wg1ZMBTAjFPnpc7A/KQVMsyXX0e1pOi8HU=",
      "key": "M0_T27_S3",
      "key_id": 0
    },
    {
      "code": "VL0xBQJQQ2wCicTW7Y79+apYt1Dx3iJCrvKZTTrLIEw=",
      "key": "M0_T28_S0",
      "key_id": 0
    },
    {
      "code": "kfQTcQOxCz9dU8+qe2PKaiGbu7draeMl2byVbykwyRI=",
      "key": "M0_T28_S1",
      "key_id": 0
    },
    {
      "code": "vVZt/9le5kqqqS9Mh2PnLxQy5HqOwcCRIhtm8w0YXt0=",
      "key": "M0_T28_S2",
      "key_id": 0
    },
    {
      "code": "mgo9R9WwRMHdjD+HNa/+M0okoXtN7GQq3U6ZTWCyQ8Q=",
      "key": "M0_T28_S3",
      "key_id": 0
    },
    {
      "code": "y0BfP20Rhk2pauazC9daLwy2T1k0MQTwWgVLKiZpMtg=",
      "key": "M0_T29_S0",
      "key_id": 0
    },
    {
      "code": "4BysqCIek+qxIFLk/Lq0xrNUyqCq/+UrS+XstBmIdgY=",
      "key": "M0_T29_S1",
      "key_id": 0
    },
    {
      "code": "VGJ/CuvsMpFT5fKA2kkp29fcyhBC0Kmny2Tb9SPs+jA=",
      "key": "M0_T29_S2",
      "key_id": 0
    },
    {
      "code": "WMpjIcH5MN05kwm2dKJySIKQCSYm8t07658ro1sSCFY=",
      "key": "M0_T29_S3",
      "key_id": 0
    },
    {
      "code": "pYSwiaC9cpcHPaGH6LPaS14yfJAZbfQIMb3ew6XADSo=",
      "key": "M0_T30_S0",
      "key_id": 0
    },
    {
      "code": "8R2I45uYP+MhBbOmFZGxNt+bMUVvQSDXDPAYQ1/P1Fw=",
      "key": "M0_T30_S1",
      "key_id": 0
    },
    {
      "code": "lPbPv3nTLN8UbKiJZaHmkGu7Zk2Mvl7pVymAyDhO4vo=",
      "key": "M0_T30_S2",
      "key_id": 0
    },
    {
      "code": "kePA1nf2XHnMWmm3+gPpxBqZjaQIQWQA9OGlC6oSITM=",
      "key": "M0_T30_S3",
      "key_id": 0
    },
    {
      "code": "ccAvG1GVGw5jGz1alINtuo4Z/UWEECJDcRsRGUWrfHA=",
      "key": "M1_T16_S0",
      "key_id": 0
    },
    {
      "code": "WWuDeG1S5dTzeQIidaFj8SypfEusJ4sPfiVHUfWWFLY=",
      "key": "M1_T16_S1",
      "key_id": 0
    },
    {
      "code": "6qq36yycYFOt+9jRgW55I+vbyEGPYl5TTYfwgWbXRqg=",
      "key": "M1_T16_S2",
      "key_id": 0
    },
    {
      "code": "GjYzfpCK2QMJsWNULuf5bdINQmqsMP193InCy5wXujA=",
      "key": "M1_T16_S3",
      "key_id": 0
    },
    {
      "code": "Z86zUrxOImH9Z8KFADjE2Irv67FxZYqFZmsCj4FZcZA=",
      "key": "M1_T17_S0",
      "key_id": 0
    },
    {
      "code": "u93VBlQl3+khF1X4shGVHlteSn2sUCL31K+DrKjnvdg=",
      "key": "M1_T17_S1",
      "key_id": 0
    },
    {
      "code": "yG7W5D5o5X1WJUrYUVk0kp1KWzMKFtL5ZLBU8VetdCk=",
      "key": "M1_T17_S2",
      "key_id": 0
    },
    {
      "code": "vRHEaIBDthrbg/Jz5njodW+uCKkXw/OcvmBWihtkdeg=",
      "key": "M1_T17_S3",
      "key_id": 0
    },
    {
      "code": "15iuloFoyRgDbY9XBP3Y2rUrHh4xr7ocOZe9E+01KBA=",
      "key": "M1_T18_S0",
      "key_id": 0
    },
    {
      "code": "sDBAACWb0kMe6HHjAyZhV56xWMFUKBAYSc2jMLJ0ZKs=",
      "key": "M1_T18_S1",
      "key_id": 0
    },
    {
      "code": "/8IvZYz6bhnJq2JGOANIy2q19UFCegQCXD23LpuNKL8=",
      "key": "M1_T18_S2",
      "key_id": 0
    },
    {
      "code": "50PsNV3Xs0oyM+nfQvGMbyno8veOjrk+NfeT7Iv4t5M=",
      "key": "M1_T18_S3",
      "key_id": 0
    },
    {
      "code": "ztzapTrb+36YxZu+vrAmagHGCZ3XqgGd+LqUSjr2gKc=",
      "key": "M1_T19_S0",
      "key_id": 0
    },
    {
      "code": "q9hhUjw5NjWfgNVOoIcPJErRl3ijbCI15VuuO0v0Kio=",
      "key": "M1_T19_S1",
      "key_id": 0
    },
    {
      "code": "oS3owx7KnuAxGyQ1gF80pbeMXF+Aonl1aCQDyfStX1U=",
      "key": "M1_T19_S2",
      "key_id": 0
    },
    {
      "code": "2slpeIuI0pHh/Z5Jz5tuU/wtXu4mW4AyVSy0tDeIAfI=",
      "key": "M1_T19_S3",
      "key_id": 0
    },
    {
      "code": "HQV/vxDJiwD5Z3Nd65b0D8s+QBa8mcRArkdY9LV+1i8=",
      "key": "M1_T20_S0",
      "key_id": 0
    },
    {
      "code": "KCK5vAvm7FjdQsfQHWvSGYeY9PJl2CXu016zGU9g2RY=",
      "key": "M1_T20_S1",
      "key_id": 0
    },
    {
      "code": "nX5X8JhM/zjp1vrc6cxssh2Um1ICfQ1WfSgzOfXvDgc=",
      "key": "M1_T20_S2",
      "key_id": 0
    },
    {
      "code": "Oe4RmqDqY1WuYWRWT+dBi6fClwsgIddg2uwaGC8Vts0=",
      "key": "M1_T20_S3",
      "key_id": 0
    },
    {
      "code": "7GySe+vhAWKFsXdgzlDT08qP2lKWeiHEUHkiDpZM6sk=",
      "key": "M1_T21_S0",
      "key_id": 0
    },
    {
      "code": "s/s0kiOS6o3ZUq5O4PkiGSLGvp/o848GrcUl0Nqrqjg=",
      "key": "M1_T21_S1",
      "key_id": 0
    },
    {
      "code": "CR55U7ANRLMQRQDeMtSVQAP6KEfOLNDeD0uuACkPOJQ=",
      "key": "M1_T21_S2",
      "key_id": 0
    },
    {
      "code": "dQvqBSgb4oOC2LAZV1URm9zKG/ohHJVZIv4ezGpRoWo=",
      "key": "M1_T21_S3",
      "key_id": 0
    },
    {
      "code": "+OJz+gd0ptfSYOE1/SYw+pDNV4jPjWQ92GX1en6QlFE=",
      "key": "M1_T22_S0",
      "key_id": 0
    },
    {
      "code": "CX4j2w7im9PG5M3ZhvFaITbuRLyCyB2ViNjoz3zZir4=",
      "key": "M1_T22_S1",
      "key_id": 0
    },
    {
      "code": "qEILba2ZhBBZYBQTLhb0QEdseOaPgH4hyDqR8/VusJk=",
      "key": "M1_T22_S2",
      "key_id": 0
    },
    {
      "code": "fBo/PcPCJByPNNHAk1na4DqUtZ9RxK1Z24iZO1m2a+M=",
      "key": "M1_T22_S3",
      "key_id": 0
    },
    {
      "code": "vU3ILqtaWxothVMNRfJ8Tj8k0xZBypnZDiAkQyRcvyY=",
      "key": "M1_T23_S0",
      "key_id": 0
    },
    {
      "code": "9Ct66umEIukQvbiRtFIz32EWdO52gkzWDU1cvotju7o=",
      "key": "M1_T23_S1",
      "key_id": 0
    },
    {
      "code": "wcyIZ5KsGYEgRpFo5IiVRiqHA+5D+YWIzGMVI8eS9q4=",
      "key": "M1_T23_S2",
      "key_id": 0
    },
    {
      "code": "ZhklobxMN0w/B0Jh5Fjo2ORKRsn/UyWDEJhKdTRaM5c=",
      "key": "M1_T23_S3",
      "key_id": 0
    },
    {
      "code": "exmQka4ysRm0sE/LTixDiZO+741iMkciCYovTKYKIZw=",
      "key": "M1_T24_S0",
      "key_id": 0
    },
    {
      "code": "ZrdLAFZy9xSinfJlnN3eIU85eGcjdXcLMLxp2YboIkw=",
      "key": "M1_T24_S1",
      "key_id": 0
    },
    {
      "code": "agJM4CLGov7kErBTCNmlYeUtuWpAxJlVVkUx1iLCBwU=",
      "key": "M1_T24_S2",
      "key_id": 0
    },
    {
      "code": "tGNZj7BhswbkCXqD8oGwSzK7dFynXQd2MG372j41DOQ=",
      "key": "M1_T24_S3",
      "key_id": 0
    },
    {
      "code": "8NkRNx1x0tDoVMiAmcuUqrh07sOr32o3v+sP2EhBnPs=",
      "key": "M1_T25_S0",
      "key_id": 0
    },
    {
      "code": "wg3Plq/zpyAJKuOVAQTEcvEIP5ywlhz05gcFSJw31L0=",
      "key": "M1_T25_S1",
      "key_id": 0
    },
    {
      "code": "zeVhgx7dVp3kyzzYRhwY07n0Q8BXy6u/zhzBhfG2K7o=",
      "key": "M1_T25_S2",
      "key_id": 0
    },
    {
      "code": "yIy7JCC6us+lyT1xGt/81gK97xYeqsWZZ6/1BQb2qH4=",
      "key": "M1_T25_S3",
      "key_id": 0
    },
    {
      "code": "a95kAMPMtiqd3u2YlKAskXNe7HFZZ8i7vNjNHrqXxNM=",
      "key": "M1_T26_S0",
      "key_id": 0
    },
    {
      "code": "/q31x2ifuV1cjcs75c761H4PzjvuJsnWmwiN807sJtc=",
      "key": "M1_T26_S1",
      "key_id": 0
    },
    {
      "code": "GXsWTaKEH7bgKHb2H2Cw52ixYGo5bLA3WiaYPWJ8SK0=",
      "key": "M1_T26_S2",
      "key_id": 0
    },
    {
      "code": "4JtoONMfjdfVu7qJgeZxWEgKphjq2ndLziu31v5Acz4=",
      "key": "M1_T26_S3",
      "key_id": 0
    },
    {
      "code": "aXP9s99ZgHwP3uaMw8fldh+qoPuA6wLBsfSl9FSdVrc=",
      "key": "M1_T27_S0",
      "key_id": 0
    },
    {
      "code": "kUFWuNDW8AjntxtRokIcPlRFdSiE6OfpD9cR79ffvKk=",
      "key": "M1_T27_S1",
      "key_id": 0
    },
    {
      "code": "9axu7vP501Bq+IU6AP+zT8H55hzLwXgVRoANDgxYVEA=",
      "key": "M1_T27_S2",
      "key_id": 0
    },
    {
      "code": "bJRF70qN5nOKE6ryDT1hqLHa2t4AYsuw2qFVTvTHrdE=",
      "key": "M1_T27_S3",
      "key_id": 0
    },
    {
      "code": "puSfPDXQSsEcLEX/Dx1WIdBiwXhv3ko1L4J6ozaS/mI=",
      "key": "M1_T28_S0",
      "key_id": 0
    },
    {
      "code": "YyyhLe7V8yKFQ200ehCPty7+76ZGmIvqRg26loDKJaA=",
      "key": "M1_T28_S1",
      "key_id": 0
    },
    {
      "code": "Fur2c98oULtifA/OwmNBqOL8Z9hqd0eiFuyfEOuxLBQ=",
      "key": "M1_T28_S2",
      "key_id": 0
    },
    {
      "code": "azLzf26BYfX+C5Dzk9Ufda8caUSogE85w3/wkCJoP9c=",
      "key": "M1_T28_S3",
      "key_id": 0
    },
    {
      "code": "yozt66NktSqCvZ5iJQWaKhk7/av+nvdB4sWHVaOh2m0=",
      "key": "M1_T29_S0",
      "key_id": 0
    },
    {
      "code": "GczfyttG6xlDcX0VzYXqnosrAQLZ4B1T4LVH8vHBx9w=",
      "key": "M1_T29_S1",
      "key_id": 0
    },
    {
      "code": "/VQpfrR/RhJd0Y08yKjYNs3x6CTERMQWre9Y9bN16co=",
      "key": "M1_T29_S2",
      "key_id": 0
    },
    {
      "code": "Ie7SzwFjg+3ACrRWP4QXcPCSrdmIVMt+oC/T1mQ1mCs=",
      "key": "M1_T29_S3",
      "key_id": 0
    },
    {
      "code": "oAc4yEjRJhSxNTY1oEG0QuBPIuaGSGwNiZ+55JqSAL8=",
      "key": "M1_T30_S0",
      "key_id": 0
    },
    {
      "code": "LYytdB1rnFHRpC+FHfLUgYPYQQaXkGLgxsG9sPMKH+E=",
      "key": "M1_T30_S1",
      "key_id": 0
    },
    {
      "code": "YVvKjXU/wNWZLGoZnMJVoMCsCgXZPvRjcjOV7qu8dFo=",
      "key": "M1_T30_S2",
      "key_id": 0
    },
    {
      "code": "Dd9f4oW84yMqZQIWaJA/67tA1NRkE6hiKt/wMejUpmg=",
      "key": "M1_T30_S3",
      "key_id": 0
    },
    {
      "code": "uInXSFdjiexpGGzIavY2UODF+Rs1O6qVVD9Yg3dfdog=",
      "key": "M2_S0",
      "key_id": 0
    },
    {
      "code": "EIDK1EUmgt/vVCHXtEwyCyvUcetjypkjAJ74KC4jwVU=",
      "key": "M2_S1",
      "key_id": 0
    },
    {
      "code": "bcaCZk9ZeZ5VdD0KXutmmfbGf90gGX426SiFkloZAkw=",
      "key": "M2_S2",
      "key_id": 0
    },
    {
      "code": "rQ1tNuR4e9rJngzQt+RbLiw159BmPbWZSR/ou1c52lc=",
      "key": "M2_S3",
      "key_id": 0
    },
    {
      "code": "Kx8HItNfd0y45NapqTwEmy7JNQ4pKqBqNqWreP3Fss4=",
      "key": "M3_T16_S1",
      "key_id": 0
    },
    {
      "code": "gT0nkFDhEc+7hNqCYZBQMMsdaR4WxIEAfX56uw9LCPE=",
      "key": "M3_T16_S2",
      "key_id": 0
    },
    {
      "code": "fOi/G2GceI/W1TMwTZ2iIS7tAO0PfnSxM3K2MDyGVNU=",
      "key": "M3_T16_S3",
      "key_id": 0
    },
    {
      "code": "UjbzJ+I4+P1H1J7Sw82cNr22DXakwRCQwDBOJ4QaM1c=",
      "key": "M3_T17_S1",
      "key_id": 0
    },
    {
      "code": "PFENUFnqnea7ROYVrd9fIqcYtROPCUFIIgnhQhV264Y=",
      "key": "M3_T17_S2",
      "key_id": 0
    },
    {
      "code": "dq7jo/VQ7JzFSXx8KzCz5FgSmVW682pvY2CK6V2wEzw=",
      "key": "M3_T17_S3",
      "key_id": 0
    },
    {
      "code": "YZCRdyrRTmORB0GP8DAerZNizx5VK/QTzZYu9KOT9bc=",
      "key": "M3_T18_S1",
      "key_id": 0
    },
    {
      "code": "zSgotaVL0w3BCp5bMU8W1EgFdID1UoP4LB+ZoNCvvOo=",
      "key": "M3_T18_S2",
      "key_id": 0
    },
    {
      "code": "s4T/sl2GdHsGn3PW1PkwbOlVyk6sgThsl6Pev5r7UaE=",
      "key": "M3_T18_S3",
      "key_id": 0
    },
    {
      "code": "5qLpmHHG+afsmyJ3AUYAKcPgovt7QFBj/xu/NZVFgtg=",
      "key": "M3_T19_S1",
      "key_id": 0
    },
    {
      "code": "1ZnVLlQ64CMz1TUX/3IbtCz+vcxnwDUj+HdPjG9KXiY=",
      "key": "M3_T19_S2",
      "key_id": 0
    },
    {
      "code": "dJR2L22xSxN98oCAkY8EQ782nDaPt4tuYJChI7gDhfs=",
      "key": "M3_T19_S3",
      "key_id": 0
    },
    {
      "code": "KYt0uYNb/Rx/2hiPW659Z3DO9clEAbdxr/1AVbmMBhI=",
      "key": "M3_T20_S1",
      "key_id": 0
    },
    {
      "code": "PgV56RVgIpQ4e7zVswRO5cjVfaW4ZEnhNUGm022xwwM=",
      "key": "M3_T20_S2",
      "key_id": 0
    },
    {
      "code": "waYkmMyLor2Z+AnQ9RUbOZhVrVQUo0teacnp7TK53GM=",
      "key": "M3_T20_S3",
      "key_id": 0
    },
    {
      "code": "iLdxIqPO5b5X9UQcsx1GzohZqq86kzNpCbpTGvn8UYA=",
      "key": "M3_T21_S1",
      "key_id": 0
    },
    {
      "code": "yKqurJ+ttkI4Cf+uDYLhzA/q4baZG9HaD8SZa224XJw=",
      "key": "M3_T21_S2",
      "key_id": 0
    },
    {
      "code": "y64hbLycJtAgHJl8SdLEaI47msPRz3cEEzzc3jDFTkg=",
      "key": "M3_T21_S3",
      "key_id": 0
    },
    {
      "code": "HAe2+F+71BISZO8VeVveyxnN1cyPDq9SLXksrnJBATg=",
      "key": "M3_T22_S1",
      "key_id": 0
    },
    {
      "code": "I7tF1U/93N0gxyjldTmq126Gy7WSf/dJbVyN/z4MxNE=",
      "key": "M3_T22_S2",
      "key_id": 0
    },
    {
      "code": "kuCDj21KEGS3r04RRV69dLlvb49dtwWnVcKaQrWxyXc=",
      "key": "M3_T22_S3",
      "key_id": 0
    },
    {
      "code": "IV5QfIA7diyMCckIVEsk+StddFxEgRNgBl2Bj/YnhaQ=",
      "key": "M3_T23_S1",
      "key_id": 0
    },
    {
      "code": "oshhn9jDxZnExU1Apz3neKujbKyZKDRmDK9EFtMg5f8=",
      "key": "M3_T23_S2",
      "key_id": 0
    },
    {
      "code": "zt8KP6cF+uE2w2tmjwGGzCNbqjXsrpRsluAvlxLt58k=",
      "key": "M3_T23_S3",
      "key_id": 0
    },
    {
      "code": "bJOAsVdvPOoukthdmfNK9P0f4SaCYMbwiiN+Uicbg2k=",
      "key": "M3_T24_S1",
      "key_id": 0
    },
    {
      "code": "4Ap8UP0ZPFeOQDkfX0XeFZffJLa8sA65jYwzBjP78P8=",
      "key": "M3_T24_S2",
      "key_id": 0
    },
    {
      "code": "nyLNrGFEdTANhWskAQyIl7BbvNE1u8YgMUVF3mQSBGE=",
      "key": "M3_T24_S3",
      "key_id": 0
    },
    {
      "code": "cdWw4OTq5hVbknetoBa0AzYvhOERpXT9IGURHxfEfw4=",
      "key": "M3_T25_S1",
      "key_id": 0
    },
    {
      "code": "Q/s0ctoiuStGVf8Yw8ha9qwj/dI5ay66CjMd+g+W9Ho=",
      "key": "M3_T25_S2",
      "key_id": 0
    },
    {
      "code": "UrgBsQBbQa1VsrnB/k/c03ZzOutcuE3LleUh2d2JzXI=",
      "key": "M3_T25_S3",
      "key_id": 0
    },
    {
      "code": "VqK8aeF9Xdgt8E5egrKWk/pBIWafpOAHs9Uj4gWGA9w=",
      "key": "M3_T26_S1",
      "key_id": 0
    },
    {
      "code": "0h8h4U1ur4K1Pp9qSkX0Frjf6DdfjGYfone/CZAGL/M=",
      "key": "M3_T26_S2",
      "key_id": 0
    },
    {
      "code": "dVICsO0S4FZz70cADq8hvoZAIpGzPs3FQ12DKWCaAfY=",
      "key": "M3_T26_S3",
      "key_id": 0
    },
    {
      "code": "5hNh5Cl4QWAtoHlrpDLewUMVogjAY4YIfkxvFfLJmwU=",
      "key": "M3_T27_S1",
      "key_id": 0
    },
    {
      "code": "7VgIlayRm6KvIS/wlWsmvgMO1dtPpw4zHTuyU57WBOM=",
      "key": "M3_T27_S2",
      "key_id": 0
    },
    {
      "code": "Npl3VZ5uYfE4C54R8zG1Su5R/7qWrMAuy8BHQ5JnYeg=",
      "key": "M3_T27_S3",
      "key_id": 0
    },
    {
      "code": "urdIlbhlVfLDbj4fU60QTpDSLVNM9/sQCubZaVPO8eo=",
      "key": "M3_T28_S1",
      "key_id": 0
    },
    {
      "code": "0jTOmMRM1xMbevsLqfQFs8uCtlQrDRvhjvQH/N6dY2M=",
      "key": "M3_T28_S2",
      "key_id": 0
    },
    {
      "code": "1imQC/icNXGqUvP5AcUfbG0/vaqBYkRI7+KqkNEYN98=",
      "key": "M3_T28_S3",
      "key_id": 0
    },
    {
      "code": "g91TsnwfN3tmhYbGWPkXpg6jdVkoL5yewro7+rHbnW0=",
      "key": "M3_T29_S1",
      "key_id": 0
    },
    {
      "code": "LPBFsXnhZzpD5q7aWr/Yq5E86a772pwCkXpWRyeSur8=",
      "key": "M3_T29_S2",
      "key_id": 0
    },
    {
      "code": "2NIHpe7Em+hLkfuoJKVwT8oyT2m8+EyHhefqCo8w69E=",
      "key": "M3_T29_S3",
      "key_id": 0
    },
    {
      "code": "vFQxkjm4TdUAvCinfJai+5iXlYkoHSRPp9HIVD5GZ0U=",
      "key": "M3_T30_S1",
      "key_id": 0
    },
    {
      "code": "q/VBB39FrjbzsMYchO+bmBv/P0B0sBMvAcyrhRFi8QM=",
      "key": "M3_T30_S2",
      "key_id": 0
    },
    {
      "code": "IU2I6bgzBDq69Vvo04e6DweSh4FhdRxfsCk8qavPw9k=",
      "key": "M3_T30_S3",
      "key_id": 0
    },
    {
      "code": "7oVrenwmQ4mMvJdwx/zBxz8rue/1GUJZvnR5ZMWsNfs=",
      "key": "M4_S1",
      "key_id": 0
    },
    {
      "code": "gAur5tlCjUfrenjB3C3ji62o5UFa1va/PS0a7DM6TJw=",
      "key": "power_off",
      "key_id": 0,
      "key_name": "power off"
    },
    {
      "code": "CoKUOAvohVBVbRxbN6wp1llOAMswGdIt++NXZ+wBUic=",
      "key": "power_on",
      "key_id": 0,
      "key_name": "power on"
    }
  ],
  "success": true,
}

@svyatogor
Copy link

Wow, this is really cool. I just received the UFO-R11, which is a battery operated version of the Tuya's IR blaster. With this script I was able to convert the codes from the SmartIR home assistant package from broadlink to Tuya's format. Not gonna pretend I understand the compression code :-D

Thank you!

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