Skip to main content

tuya-ble-sdk

Python SDK for Tuya Bluetooth Low Energy devices. It speaks the Tuya BLE GATT protocol directly — handshake, session key, encrypted frames and datapoints — and knows nothing about Home Assistant.

Consumed by the ha-tuya-ble integration, which pins it from manifest.json.

What it does

One read is one whole session: the client connects, performs the handshake, collects the datapoint report and disconnects. Tuya BLE sensors are battery powered and only listen for a moment after they advertise, so holding a connection open would drain them and occupy a proxy slot for nothing.

from tuya_ble_sdk import TuyaBleClient, TuyaBleCredentials, parse_advertisement

info = parse_advertisement(service_data, manufacturer_data)
client = TuyaBleClient(
    ble_device,
    TuyaBleCredentials(uuid=info.uuid, device_id=device_id, local_key=local_key),
)
data_points = await client.async_read_data_points()

Discovery belongs to the caller: the client takes an already-resolved BLEDevice, which is what lets Home Assistant hand over a device seen through a Bluetooth proxy.

parse_advertisement reads what the advertisement discloses — every field of the result is optional. The uuid is encrypted with the product-id record broadcast beside it, so no cloud call is needed to learn it; the readable product id, however, is only there on an unbound device. One bound to a Tuya account broadcasts an obfuscated value in its place: those bytes still decrypt the uuid, but they name no product, and the caller has to learn what the device is some other way.

Command line

The optional cli extra installs a tuya-ble command:

uv run --extra cli tuya-ble scan
uv run --extra cli tuya-ble read \
    --address AA:BB:CC:DD:EE:FF --device-id <id> --local-key <key>

scan lists every nearby Tuya BLE device with its product id and uuid; read runs one session and prints the datapoints it reported.

Not implemented

The device may report datapoints in a signed form (0x8004 / 0x8005) instead of the plain one this SDK reads. Those two commands are recognised and logged, not parsed: the reference implementation disagrees with itself about where the records start inside them, and no device was available to settle it. A device that uses them shows up as a read that reports no datapoint, with the command name in the debug log.

Development

uv sync                     # create .venv and install dependencies
uv run ruff format --check .
uv run ruff check .
uv run mypy src
uv run pytest               # 90 % coverage gate

Runtime dependencies carry a >= floor and nothing else: Home Assistant pins its own transitive dependencies exactly, so an == pin here eventually contradicts HA's pin and the integration stops installing.

Credits

The protocol implementation is derived from PlusPlus-ua/ha_tuya_ble (MIT), itself based on redphx/poc-tuya-ble-fingerbot.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tuya_ble_sdk-0.1.1.tar.gz (91.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tuya_ble_sdk-0.1.1-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file tuya_ble_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: tuya_ble_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 91.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tuya_ble_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d87d0d1a916fc0750280632715eaddaaaea4f8938468316f8c0790921ae91e59
MD5 7ab3ba92189b6b7e918c95f7740278f1
BLAKE2b-256 444fb441773862c000219c55d70a49734a13a469adf0048a41ee75391d463545

See more details on using hashes here.

File details

Details for the file tuya_ble_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tuya_ble_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tuya_ble_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bdebb171ddbb7492a285d5603df8e74d03a7c714ed8a3abd9fe966343bc0917b
MD5 1934b6996f03f56af3a53cb6d4524c80
BLAKE2b-256 e1d191452b5f4680407324573b85137a90501a1607adb63984ddd9f49b95855b

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.2

2 files

This release

0.1.1 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page