Skip to main content

Control Tuya devices with MQTT over LAN.

Project description

local-tuya

tests PyPi python DockerHub

Control Tuya devices with MQTT over LAN.

Features

  • fully asynchronous
  • persistent and robust communication to the device and to MQTT
  • MQTT discovery
  • automatic remote device state updates (remotes can still be used)
  • configurable buffering for subsequent updates
  • constraints between device commands

[!IMPORTANT] For now, only v3.3 is supported as I only own devices using this version.

Supported devices

Installation

The easiest way is to use the Docker image:

docker run -v {PATH_TO_CONFIG}:/app/conf.yaml:ro gpajot/local-tuya

Alternatively, you can use the python package and run directly: CONFIG=path/to/config python -m local-tuya.manager

Configuration

The minimal config is:

mqtt:
  discovery_prefix: {YOUR_PREFIX_HERE}
  hostname: 127.0.0.1
devices:
  - name: My AC
    model: Airton AC
    config:
      tuya:
        id_: {DEVICE_ID_HERE}
        address: {DEVICE_IP_HERE}
        key: {DEVICE_KEY_HERE}

To control a device you will need these 3 things:

  • the device ID
  • the device local IP address
  • the device local key (encryption key generated upon pairing)

[!IMPORTANT] This library does not provide support for getting these. See how to do that using any of those projects:

Generous thanks to the maintainers of those tools for details on interfacing with Tuya devices.

[!WARNING] Keep in mind that:

  • After pairing the devices, it's recommended to assign static IPs in your router.
  • If you reset or re-pair devices the local key will change.
  • You can delete your tuya IOT account but not the SmartLife one and devices should be kept there.
  • It looks like you can block the device access to internet from your router and still have it working.

Architecture

This library is composed of three main components:

  • the Tuya protocol
  • the device
  • the MQTT client

Tuya protocol

The Tuya protocol is responsible for handling communication details with the Tuya device. Its interface consists of an asynchronous method to update the device and exposes state changes via events.

See protocol module.

Device

The device handles higher level functional logic such as buffering, constraints and specific device commands.

See device module.

MQTT client

Communication with home hubs through MQTT, supporting auto discovery.

See mqtt module.

Project details


Download files

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

Source Distribution

local_tuya-4.1.0.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

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

local_tuya-4.1.0-py3-none-any.whl (36.8 kB view details)

Uploaded Python 3

File details

Details for the file local_tuya-4.1.0.tar.gz.

File metadata

  • Download URL: local_tuya-4.1.0.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for local_tuya-4.1.0.tar.gz
Algorithm Hash digest
SHA256 d9a33f6815cbbe4a17924031a5c6d032f2d1f15f520611ef72aa24d689944089
MD5 b39672c691d19bfac653c4bb6c898ac9
BLAKE2b-256 96f89eb8418174d5a782e6529233a33fb247580b5eeb8daa855cd42be45fa3fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for local_tuya-4.1.0.tar.gz:

Publisher: publish.yml on gpajot/local-tuya

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file local_tuya-4.1.0-py3-none-any.whl.

File metadata

  • Download URL: local_tuya-4.1.0-py3-none-any.whl
  • Upload date:
  • Size: 36.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for local_tuya-4.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 45c7fc67ff239caa56a4d6b2749425d278a5a10f62fcf93390b046da0a03d4d6
MD5 38ea12e6b47cf72632a11b42040299a5
BLAKE2b-256 463c6b1d15e5978e147e471763bb2a7c2c869275bfd095f63db5f6282361b3bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for local_tuya-4.1.0-py3-none-any.whl:

Publisher: publish.yml on gpajot/local-tuya

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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