Replies: 2 comments
-
I found my solution via a fork of the LocalTuya project. This also includes support for Zigbee Hubs as well. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi Devs,
I'm in the process of adding my range of Tuya devices into Home Assistant for the first time, which has been fairly painful.
I'd like to suggest a few improvements to the device discovery and workflow that I think would help new users and new devices get started quickly.
Tuya recently introduced a new free subscription tier and "Smart Home Basic" Service API. This appears to be intended to replace the developer subscription, and no longer needs to be renewed every 6 months.
Goal:
AND
Suggested Psuedo-Logic:
1: Pull a list of all Device IDs in the home from the APIs.
2: Match any Device ID's from the Broadcast pings, if available.
3: If the IP is matched, allow the user to add the device.
4: If the IP is not matched, allow the user to enter an IP address manually, then add the device.
5. Prompt the user to confirm the discovered parameters (or edit as needed), then add the device to Home Assistant with all the parameters pre-filled.
Assumptions:
Need:
Service: https://iot.tuya.com/cloud/products/detail/?abilityId=1667049392684671055
Docs: https://developer.tuya.com/en/docs/cloud/smart-home-basic-service?id=Kconis1yii4be
API DETAILS
Discover the HOME (location) Info
"Smart Home Basic" Service API > HOME MANAGEMENT > Query user family list
Query Home List. Based on the user ID, query the list of homes where the specified user belongs.
GET EU/v1.0/users/{uid}/homes
RESULTS
Will return an array of all the homes that the user is part of.
The result will usually only be a single array, but good logic would ask the user to confirm, or select their home from a list.
VALUES WANTED
Extract and store the home_id value from the selected home.
Note: home_id = owner_id returned from other APIs.
###Discover all devices in the home
"Smart Home Basic" Service API > HOME MANAGEMENT > Query devices in Home
Based on the home ID, query a list of devices in the specified home.
GET EU/v1.0/homes/{home_id}/devices
RESULTS
Will return an array of all the Devices in the selected home.
VALUES WANTED
"id" (Device ID)
"local_key"
"model"
"name" (Friendly Name)
"owner_id"
"product_id"
"product_name"
Discovery Info
The "IP" value will show the Public WAN IP address of the home router, not the private LAN address of the Tuya WiFi device, so this (alone) can't be used for auto discovery.
However, all devices will send a UDP 6667 broadcast ping, which carries the IP Address and Device ID as a payload.
Unfortunately, the UDP broadcast will only work if HASS is on the same VLAN as the device. Many users run IOT devices on a separate subnet.
By combining both the broadcast and the API results, we can have a high confidence that the devices information will be as full-featured as possible.
All feedback welcome.
Beta Was this translation helpful? Give feedback.
All reactions