tuya-local
repository·main·Indexed 25 days ago
https://github.com/make-all/tuya-localA Home Assistant integration for local control of Tuya-firmware devices over WiFi, bypassing the Tuya cloud to improve speed and reliability. It uses YAML device configuration files to map Tuya Data Points (DPs) to Home Assistant entities, supporting various DP types (string, boolean, integer, bitfield, etc.) and complex mapping rules for data transformation.
What's inside tuya-local
- This project does not intend to support non-Tuya devices via Tuya hubs. The project focus is on making Tuya devices work with standard BLE and Zigbee support in Home Assistant. Users with non-Tuya devices should use standard Home Assistant integrations rather than attempting to route them through Tuya hubs via this project.
Use IR/RF Blasters for learning and sending commands
mainTuya IR/RF blasters are exposed as
remoteentities andinfraredemitters.Learning Commands
Use the
remote.learn_commandservice:command: The name to store the command under (e.g.,power).device: The appliance name (e.g.,TV).command_type: Set torffor RF remotes; omit for IR.
Sending Commands
- Learned Commands: Use
remote.send_commandwith the samecommandanddeviceused during learning. - Direct IR/RF Codes: Use the
infraredplatform with prefixes:b64:<base64_encoded_ir_code>rf:<base64_encoded_rf_code>
- Cross-Emitter Commands: Use the
send_learned_ir_commandservice to send a command learned by a Tuyaremoteentity to any otherinfraredemitter.
Contribute device configuration files
mainIf your device is not supported, you can help by providing a configuration file.
How to gather data for a new device:
- Check Home Assistant Logs: If a device is unrecognized, the logs will contain the current data points (dps) returned by the device.
- Use Tuya IoT Explorer: Sign up at iot.tuya.com. Under Cloud > Device Control, use the Query Things Data Model function to find DP IDs and range information for integer/enum types.
Requirements for Pull Requests:
When requesting support, include:
- Logs showing the LOCAL DPS received from the device.
- Device identification (model and brand).
- Gathered datapoint information.
- Links to manuals or webpages (even in other languages).
Configure Tuya Secure Locks
mainTuya BLE locks use a pairing mechanism involving two datapoints (DPs):
60:remote_no_pd_seykey61:remote_no_dp_key
To unlock a lock, you can capture the 8-digit ASCII numeric code sent by the app during the pairing phase. This code can be extracted by eavesdropping on the message in the Tuya developer portal and decoding the payload (which contains 4 bytes of binary, the 8-digit code, and 3-4 more bytes of binary). The 8-digit code from the first paired app should work for subsequent unlocking.
Configure tuya-local devices
mainAfter installation, you can configure devices via the Home Assistant Integrations UI (Settings > Devices & Services > Add Integration).
There are two configuration paths:
- Cloud-assisted (Recommended): Log in to the Tuya or SmartLife app via the integration. This automatically retrieves the device list and necessary local connection data (device ID and local key), avoiding the need for a Tuya IoT developer account.
- Manual: Provide all device details manually as per the
DEVICES_DETAILS.mdguide.
Configure Smart Plugs, Wall Sockets, and Switches
mainMost smart plugs follow a standard Tuya template, making many manufacturer-specific configurations compatible with other brands. However, features and datapoint locations can vary significantly between manufacturers.
Tip for adding devices: When adding a device, the default selected option for the device type typically has the most matching datapoints. If the device appears to be of that type, it is likely the best configuration option to start with.
Enable Meal Plan for Pet Feeders
mainMany pet feeders expose an encoded Meal plan setting via a text entity. This is disabled by default. To enable it, go to the Device settings in Home Assistant. Once enabled, the format is compatible with theFrederikM97/mealplan-cardcustom card.Find Device ID, Local Key, and Node ID using tinytuya wizard
mainYou can use the
tinytuyalibrary to scan your network and automatically gather theid,key, andnode_id(required for hub-dependent devices) needed for configuration.Prerequisites
Before running the wizard, gather these credentials from the Tuya Developer Portal (Cloud -> Development -> Open project):
- Access ID/Client ID
- Access Secret/Client Secret
- A sample Device ID
- Your Region (e.g., "Central Europe Data Center")
Execution
Run the following command in your terminal (e.g., on your Home Assistant machine):
python -m tinytuya wizardFollow the interactive prompts:
- Enter API Key from tuya.com: Use your
Access ID/Client ID. - Enter API Secret from tuya.com: Use your
Access Secret/Client Secret. - Enter any Device ID...: Enter a registered device ID or type
scanto scan the network. - Enter Your Region: Enter your datacenter's region.
- Download DP Name mappings?: Enter
Y. - Poll local devices?: Enter
Y.
Results
The wizard generates a
devices.jsonfile containing:id: The device ID.key: The local key.node_id: The sub-device ID (essential for hub-dependent devices).mapping: Data point descriptions (used if the device is not yet natively supported).
python -m tinytuya wizardFind Device ID and Local Key via Tuya IoT Developer Portal
mainIf you are manually configuring devices, you can retrieve the
Device IDandlocal_keyusing the Tuya Developer portal. This method is useful if you prefer not to use the cloud-assisted configuration flow.- Get Device ID: Log in to the Developer Portal. Under Cloud, you should see a list of your devices containing the
Device ID. Ensure your server is set correctly at the top of the page. - Get Local Key:
- Select Cloud from the sidebar, then go to API Explorer.
- Under Devices Management, select the Query Device Details in Bulk function.
- Enter your
Device IDs, separated by commas. - The results will include the
local_keyfor each device.
Note: You must use Tuya-branded "Tuya Smart" or "SmartLife" apps to access devices through the developer portal. Some manufacturer-branded apps may have limited functionality (e.g., missing vacuum cleaner maps) when used this way.
- Get Device ID: Log in to the Developer Portal. Under Cloud, you should see a list of your devices containing the
Configure Device IP Address
mainWhen configuring devices, you can set the IP address manually or use
Auto.- Manual IP (Recommended): It is highly recommended to fix the device's IP address in your router configuration and enter that specific IP into the integration. This ensures better reconnection performance and stability.
- Auto IP: You can enter
Autoto allow the integration to discover the address.
Drawbacks of
AutoIP:- It may fail if
localtuyais installed. - It may fail if the Tuya/Smartlife app is currently connected locally to the device.
- It may fail if your network is not a simple single subnet.
- Reconnection performance is significantly worse because the integration must search the network every time.
Structure of Device Configuration Files
mainDevice configuration files are written in YAML and map Tuya Data Points (DPs) to Home Assistant attributes. A single device configuration can define multiple Home Assistant entities.
At the top level, a configuration must include:
name: A descriptive, generic name for the device type.products(Optional): A list of specific products this config applies to. Each entry must have anid(matchingproduct_idfrom cloud info orproductKeyfrom local discovery). You can also includemanufacturer,model,model_id, and a specificnameoverride.entities: A list of Home Assistant entities provided by the device.
Configure Tuya devices connected via hubs
mainWhen adding a sub-device that connects through a hub (e.g., battery-powered water timers), you must provide the hub's credentials and the sub-device's specific ID:
- Device id (uuid): Use the hub's device ID.
- IP address or hostname: Use the hub's IP address or hostname.
- Local key: Use the hub's local key.
- Sub device id: Use the actual device's
node_id(this is different from the device ID; you can find it usingtinytuya).