Field report: Tuya CL20-BT cabinet lock controlled locally from Home Assistant [SUCCESS]
Hi. I'm a tech dummy hoping to share how i got my Tuya bluetooth lock to work with Home Assistant. The lock is used on a shoe cabinet sitting outside the house.
ChatGPT did the heavy lifting. I just sat at the laptop copying and pasting stuff back and forth. Eventually, i learned how to give Chat GPT access to the laptop and to HA
sharing the below just in case it makes somebody's life easier. All content below prepared by ChatGPT
Field report: local Home Assistant control of a Tuya CL20-BT cabinet lock
An AI agent helped analyze the BLE protocol and adapt the Home Assistant integration. I supplied device information and capture files, authenticated the Samba share, and authorized changes to the HA integration and lock/unlock testing. I’m sharing the details for other CL20-BT owners, developers, and AI coding agents.
This report describes one working local setup. It is not an upstream-verified protocol specification.
1. Hardware and software
Devices and services
Lock: Tuya CL20-BT cabinet lock.
HA host: Home Assistant at
192.168.0.200.Bluetooth proxy: M5Stack Atom Lite running ESPHome’s Bluetooth Proxy firmware.
Android device: Samsung Galaxy Tab SM-T500, used with the Tuya app and for Bluetooth capture work.
Tuya account: Used to pair/register the lock and access its device information and DP schema.
Software and files used
Home Assistant, HACS, and the Tuya Local BLE custom integration.
Samba Share add-on, which exposed HA’s
/configfolder to the laptop over the local network.ESPHome web installer/dashboard to install the Bluetooth Proxy firmware and bring the Atom Lite into HA.
The Tuya or Smart Life app and the Tuya Developer Portal/API Explorer.
Android SDK Platform Tools (
adb) to communicate with the T500 and copy APK/log artifacts.Android Studio to inspect extracted app-related files.
Wireshark to inspect the Android Bluetooth HCI snoop capture and ATT traffic.
PowerShell scripts and JSON artifacts used during protocol investigation, including
CL20-Derive-And-Vault.ps1,decrypt.ps1,btatt data.json, anddecrypt.json.
The APK and packet-analysis artifacts were investigative materials. They are not needed for ordinary HA operation after the integration is configured. One early decryption-script attempt failed inner-frame/CRC validation, so it should not be described as a successful way to recover keys. Tools such as apk-mitm, Objection, mitmproxy, and HTTP Toolkit were discussed in pasted advice, but were not part of the working setup described here. The tablet was not rooted.
2. What access the AI agent had
Laptop files and internet: I authorized the agent to inspect relevant local files and use internet research for this task.
Home Assistant files: I authenticated Samba Share and authorized read/write access to the HA configuration. The relevant live integration files were under
/config/custom_components/tuya_local_ble/.Home Assistant lock controls: I authorized lock/unlock commands and status checks for testing. Physical movement was confirmed by observing the lock.
Tuya account and portal: I used my Tuya/Smart Life account and the Developer Portal to retrieve information. The agent worked from the information, files, and screenshots I provided; it did not need my Tuya password in the public report.
T500: ADB access and Bluetooth capture work were authorized. I performed the pairing and capture steps and provided the resulting files/output for analysis. ADB was not root access.
Atom Lite: I connected it to USB and used the ESPHome setup flow to flash and onboard it. I performed the physical device and serial-port steps.
This distinction matters: the agent had permission to edit HA’s files and issue HA lock commands, while I performed the physical pairing, tablet, and Atom setup steps.
3. Pairing and a Bluetooth connection gotcha
I first signed in to the Tuya/Smart Life app on the T500 and paired/registered the lock there. During Tuya Local BLE setup, I completed the integration’s QR-code/User-Code account-linking flow through the app.
A second Tuya app phone later automatically connected to the lock and controlled it. HA could see the advertisement but could not take the BLE connection. Turning off Bluetooth on that phone immediately allowed HA to connect. If HA sees the lock but cannot operate it, check whether another phone or BLE central is already connected.
4. Device identity and required credential fields
The working local profile uses:
HA/device display name: CL20-BT
Tuya hardware/model string:
HDY_BK3633Product ID:
mp13jfzgCategory in the local integration profile:
jtmsproSeparate Tuya model field observed:
modelId: e1nj8pbc
Do not treat modelId as interchangeable with product_id. Confirm the category and product ID from the relevant device/product details before reusing this profile on another lock.
The integration needs these fields:
device_id— Tuya cloud device identifier.uuid— Tuya BLE UUID/node identifier; it is not the Bluetooth MAC address.local_key— obtained through the linked Tuya Developer Portal project’s device-details/API Explorer workflow.categoryandproduct_id— select the device profile.sec_key— additional per-device key required by the CL20 code path.
I reported locating the sec_key in a JSON artifact from analysis of the Tuya app on the T500. It was not a field in the public DP schema. The failed HCI decrypt script mentioned above did not prove that the key came from the Bluetooth capture. Keep all real values private.
5. BLE discovery and capture
The lock advertised a connectable device with the Tuya FD50 service:
0000fd50-0000-1000-8000-00805f9b34fb
An Android Bluetooth HCI snoop was captured while the Tuya app connected to and operated the lock. ADB was used to retrieve the capture; Wireshark was used to inspect the ATT exchange. The capture showed security flags 0x0e and 0x0f.
In one capture, ATT handles appeared as:
Write:
0x0012Notify:
0x0014CCCD:
0x0015
These are observed handles from that capture. A reusable integration should discover the service and characteristics at runtime instead of assuming those handles are fixed.
6. Why the existing profiles did not work
The profiles we found were for other Tuya locks. A shared FD50 service UUID did not guarantee the same authentication protocol or command encoding.
The existing profiles we examined used security flags such as 0x04 and 0x05 and a different key derivation path. The CL20 capture used 0x0e for login traffic and 0x0f for session traffic, and the CL20 path required sec_key. The product ID was also not covered by the profile we needed.
The datapoints differed between lock families as well. The CL20 schema listed DP 6 for BLE unlock and DP 46 for manual lock; other locks may require DP 71 or a separate unlock-check value. Applying another lock’s datapoint profile to the CL20 was not sufficient.
Finally, the status refresh had to follow the command. Running them as independent tasks could allow the status query to overtake the lock command.
7. Key derivation and encrypted packet handling
For product ID mp13jfzg, the working local implementation derives:
login_key = MD5(ASCII(local_key) || ASCII(sec_key))
session_key = MD5(ASCII(local_key) || ASCII(sec_key) || srand)The captured DEVICE_INFO response places srand in data[6:12]. These are six raw bytes; do not convert them to the printable ASCII characters of their hexadecimal representation before deriving the session key.
The CL20 uses security flag 0x0e for login and 0x0f for session traffic. The code encrypts the inner frame with AES-CBC and an IV, adds and validates the inner CRC, and pads the frame to the AES block size. It derives the session key from DEVICE_INFO before sending the encrypted pair request.
8. Datapoints and command behavior
The Tuya model/DP data and the working profile identify:
DP | Code | Type | Use -- | -- | -- | -- 6 | bluetooth_unlock | Raw | BLE unlock command 8 | residual_electricity | Value | Battery percentage, schema range 0–100 19 | unlock_ble | Value | BLE unlock record/event 21 | alarm_lock | Enum | Lock alarm 33 | automatic_lock | Boolean | Automatic relock setting 46 | manual_lock | Boolean | Manual lock command 47 | lock_motor_state | Boolean, read-only | Reported lock/motor stateThe local profile maps DP 6 to unlock, DP 46 to lock, and DP 47 to state. The DP 6 raw value observed in Tuya logs was Base64 AQE=, which decodes to bytes 01 01. The implementation builds a CL20-specific FUN_SENDER_DPS_V4 payload for DP 6 and another for DP 46; it does not simply reuse a different product’s generic command map.
The current HA profile interprets DP 47 false as locked and true as unlocked. Logs also showed the motor state “on” during an operation and “off” later. Validate that against the physical lock, especially around automatic relock, before relying on DP 47 as a steady bolt-position sensor. DP 46 is a command, not the state report.
DP 8 exists in the Tuya schema, but I did not find a CL20-specific battery sensor mapping in the live integration files inspected. Do not assume the battery sensor is exposed in HA until verified.
9. Python files containing the CL20-specific code
In the live HA integration:
devices.py— identifiesmp13jfzgas CL20-BT and registers its product information.lock.py— maps DP 6/46/47, configures on-demand connections, and serializes the command/status refresh.const.py— defines thesec_keyconfiguration field.config_flow.py— accepts the key and requires it formp13jfzg.keyman.pyandtuya_ble/manager.py— carry the device credentials and reject an incomplete CL20 credential set.tuya_ble/tuya_ble.py— implements the CL20 security flags, key derivation, encrypted framing, CRC handling, and DP-V4 writes.translations/en.json— labels the field “Sec Key (CL20 only).”
For a command, the CL20 lock entity sends the DP write, then requests a status update while connected. The update is best-effort, with a 15-second timeout; the connection briefly lingers before disconnecting. The CL20 state is based on DP 47 rather than being assumed from the command alone.
10. Test results and limits
Lock and unlock physically worked from HA through the Atom Lite proxy. The range test was done with the lock loose, before installation. Long-term reliability, installed orientation, and recovery after power loss still need testing.
@paulskl Instead of describing what you changed to allow it to connect, I'd much rather you submitting your changes as a PR to allow other users to use them as well. GitHub issues are for reporting issues / asking for help, not explaining how to add support for new devices. Adding support for new devices should only be done through a pull request with actual working code.
I've been getting so many AI written issue reports for new devices (with almost none of those being then converted into PRs) lately that its seriously making me consider disabling issues altogether, as I do not want to waste my spare time on AI written reports.
And as stated many times before, I will not be buying any more Bluetooth-based Tuya devices, so new device support will only come from community members willing to contribute their code, with no way for me to verify that its actually working, which is why making these reports is practically useless for me as I will not be writing & committing untested code.
The TLDR is, if you have working code for the device you want added, open a PR for it & it'll be merged, do not use issues to suggest/explain how to get said device working.