Tuya-BLE icon indicating copy to clipboard operation
Tuya-BLE copied to clipboard

Fixes for Raykube A1 Ultra (hc7n0urm) and DY-MJ-SLock (ikphogdj): battery, unlock key, handshake, state cache

Open robertbigk opened this issue 3 weeks ago • 1 comments

Hi, thank you for the integration.

I use two battery locks with it and had to patch a few things to make them work reliably. After the latest update my patches were overwritten, so I merged them onto your current code and would like to share them. Everything I changed is marked with an RBK comment in the code (some comments are in Polish, sorry).

Attached: tuya_local_ble_rbk_patches.zip – the 10 changed files plus rbk_changes.diff (unified diff against your version as installed on 2026-11-09, manifest version 0.1).

Devices

  • A1 Ultra, product id hc7n0urm (advertises as BleLock-Room-5111)
  • DY-MJ-SLock, product id ikphogdj

Confirmation of your code

  • The "candidate" remote lock command for hc7n0urm (DP46, 00000000012e00000101) works on my A1 Ultra – the lock physically locks.

Changes for both locks

  • tuya_ble.py, _build_raykube_unlock_v4_data: the last 4 bytes of the unlock payload are the current unix time, not the value from the cloud ble_unlock_check. Verified in a decrypted HCI capture of the official app. The cloud value goes stale after the lock is opened by another method and the unlock is then rejected.
  • tuya_ble.py: the sequence number is reset to 1 before the device info request (the official app always opens a new link with seq 1).
  • sensor.py: DP9 battery_state removed for both locks – it is never reported over BLE, so the entity was always unknown. DP8 is the working battery value.
  • sensor.py, devices.py: entities stay available with the last known value while the lock sleeps, instead of flipping to unavailable.
  • New rbk_dp_cache.py + __init__.py: the last datapoints are stored in Home Assistant storage and loaded before entities are created, so the locks have a state right after a restart. Entities carry restored_from_cache: true until the first real report.

Changes for hc7n0urm (A1 Ultra)

  • tuya_ble.py, FD50 frame parser: this lock sends the header 00 00 00 28, not 00 00 00 00, so every frame fell through to the heuristic parser and DP8 (battery) was never read. The parser now checks only the first 3 bytes.
  • sensor.py: battery mapped to DP8 (TuyaBLEBatteryMapping).
  • switch.py + tuya_ble.py: automatic_lock switch (DP33), same V4 bool framing as ikphogdj, with on-demand connect.
  • button.py: "unlock" button (DP6) that connects on demand.
  • binary_sensor.py: lock state sensor based on DP47 (bolt state); when DP47 is not reported it assumes the lock closes 5 s after opening if auto lock is on.

Changes for ikphogdj (DY-MJ-SLock)

  • tuya_ble.py: device info request payload is 00 14 instead of 00 f3 (HCI capture of the official app).
  • tuya_ble.py: lock command is 00000000012e01000101 (bool type 01, as sent by the app) instead of 00000000012e00000101.
  • select.py: beep_volume options are low / normal / high – this lock has no "mute", so the list was shifted by one.

Notes

  • Tested only on these two locks. Where a change could affect other models (seq reset, unix-time unlock key, lock command bytes) I limited it to hc7n0urm / ikphogdj.
  • Your additions from the last update (B5 lock nglqaett, Hoselink qycalacn, background initial update) are kept unchanged.

Feel free to take whatever is useful.

tuya_local_ble_rbk_patches.zip

robertbigk avatar Nov 10 '26 18:11 robertbigk

First of all, thanks for your patches.

Second, this isnt how you contribute code on GitHub. Please open a PR with your additions so I could review them properly and merge them into the main repo.

ShonP40 avatar Nov 10 '26 18:11 ShonP40