Panel SDK Method
This topic mainly describes how to control smart devices quickly through the panel SDK. For more information about cloud interfaces, see other documents under the directory of Common SDK Development.
Overview
Panel SDK provides quick and complete solutions to connect Tuya products. Panel SDK provides methods for App SDK-based capabilities, such as device control, timing tasks, and event monitoring, and methods for jumping to Smart Life app modules, such as a scenario module, a network configuration module, and a user center. Panel SDK can achieve complete functions through simple calls, so developers can connect Tuya products more quickly.
Requesting interface data
TYSdk.apiRequest()
Request parameter
Name |
Type |
Description |
Required |
a |
string |
Api name |
Yes |
postData |
object |
Parameters to be passed |
Yes |
version |
string |
Api version |
No |
TYSdk.apiRequest(a, postData, version)
.then(data =>
console.log('data',data);
)
.catch(error =>
console.log('error',error);
);
TYSdk.apiRequest({
a,
postData,
v,
})
.then(data => {
console.log('data :>> ', data);
})
.catch(error => {
console.log('error :>> ', error);
});
Event method
Monitoring method
Request parameter
Name |
Type |
Description |
Required |
yourEventName |
string |
Event name |
Yes |
yourHandler |
function |
Listen for callbacks triggered successfully |
No |
Request example
TYSdk.event.on(yourEventName, yourHandler);
TYSdk.event.off(yourEventName, yourHandler);
TYSdk.event.emit(yourEventName, yourHandler);
Frequently-used event name
on(
event: 'deviceDataChange',
callback: (data: {
type: 'dpData' | 'devInfo' | 'deviceOnline';
payload: Record<string, DpValue> | DevInfo | boolean;
}) => void,
): void;
on(event: 'networkStateChange', callback: (data: { appOnline: boolean }) => void): void;
on(event: 'linkageTimeUpdate', callback: (data: {}) => void): void;
on(event: 'deviceLocalStateChange', callback: (data: { state: boolean }) => void): void;
on(event: 'bluetoothChange', callback: (value: boolean) => void): void;
on(event: 'NAVIGATOR_ON_WILL_FOCUS', callback: (route: DeprecatedNavigatorRoute) => void): void;
on(event: 'NAVIGATOR_ON_DID_FOCUS', callback: (route: DeprecatedNavigatorRoute) => void): void;
Note: When executing componentWillUnmount
, cancel monitoring event.
Equipment information acquisition
TYSdk.devInfo
Note: 4.0 and above versions support this function.
Return parameter
Name |
Type |
Description |
DevInfo |
DevInfo |
Get device information |
The common fields will be explained below, for more comprehensive information, please refer to DEVINFO type definition
-
name: Device name.
-
productId: Product ID.
-
uiId: The panel ID corresponding to the current product.
-
bv: Hardware baseline version.
-
devId: Device ID.
-
gwId: Gateway ID. When it comes to a single device, the devId
is usually equal to gwId
.
-
ability: Only used by Bluetooth devices. The value should be 5 when it is used for Single Bluetooth Low Energy (Bluetooth LE) devices.
-
appOnline: Whether the app is online.
-
deviceOnline: Whether the device is online.
-
isLocalOnline: Whether the LAN is online.
-
isShare: Whether it is a shared device.
-
groupId: Group device ID, which is used to determine whether it is a group device.
-
networkType: The online type of the device.
-
schema: The data point of the product to which the device belongs. For more information about the data point, see DP explanation.
-
state: The status of DP.
-
capability: The capability type of the device, indicating what capabilities the device supports, such as Zigbee, infrared, and Bluetooth.
Type |
Wi-Fi |
Wired cable |
GPRS |
NB-IoT |
Bluetooth LE |
Bluetooth LE mesh |
Zigbee |
Infrared |
433 |
SIG Mesh |
Bit |
0 |
1 |
2 |
3 |
10 |
11 |
12 |
13 |
14 |
15 |
Capability value |
1 |
2 |
4 |
8 |
1024 |
2048 |
4096 |
8192 |
16384 |
32768 |
Request example
console.log('TYSdk.devInfo: ', TYSdk.devInfo);
Device method
TYSdk.device.checkDpExist()
Request parameter
Name |
Type |
Description |
Required |
idOrCode |
string |
dpId or dpCode |
Yes |
Return parameter
Name |
Type |
Description |
isExit |
boolean |
Check if the DP exists |
Request example
TYSdk.device.checkDpExist(idOrCode);
TYSdk.device.getDeviceInfo()
Return parameter
Name |
Type |
Description |
DevInfo |
DevInfo |
Get device information |
Request example
TYSdk.device.getDeviceInfo()
.then((data: DevInfo) => {
console.log('data :>> ', data);
})
.catch(error => {
console.log('error :>> ', error);
});
TYSdk.device.getDeviceState()
Note: 4.0 and above versions support this function.
Return parameter
Name |
Type |
Description |
DpState |
{ dpCode: number | string | boolean } |
Get device status information |
Request example
TYSdk.device.getDeviceState()
.then((data: DpState) => {
console.log('data :>> ', data);
})
.catch(error => {
console.log('error :>> ', error);
});
TYSdk.device.getDpCodeById()
Request parameter
Name |
Type |
Description |
Required |
dpId |
string | number |
dpId |
Yes |
Return parameter
Name |
Type |
Description |
dpCode |
string |
Obtain dpCode according to dpId |
Request example
TYSdk.device.getDpCodeById(dpId);
TYSdk.device.getDpCodes()
Note: 4.0 and above versions support this function.
Return parameter
Name |
Type |
Description |
dpCodes |
string[] |
Get all dpCodes of the device |
Request example
TYSdk.device.getDpCodes();
TYSdk.device.getDpDataFromDevice()
Note: 4.0 and above versions support this function.
Request parameter
Name |
Type |
Description |
Required |
idOrCode |
string | number |
dpId or dpCode |
Yes |
Return parameter
Name |
Type |
Description |
DpState |
{ dpCode: number | string | boolean } |
Get the data of the DP corresponding to the device |
Request example
TYSdk.device.getDpDataFromDevice(idOrCode)
.then((data: DpState) => {
console.log('data :>> ', data);
})
.catch(error => {
console.log('error :>> ', error);
});
TYSdk.device.getDpIdByCode()
Request parameter
Name |
Type |
Description |
Required |
dpCode |
string |
dpCode |
Yes |
Return parameter
Name |
Type |
Description |
dpId |
string |
Obtain dpId according to dpCode |
Request example
TYSdk.device.getDpIdByCode(dpCode);
TYSdk.device.getDpSchema()
Note: 4.0 and above versions support this function.
Request parameter
Name |
Type |
Description |
Required |
dpCode |
string |
dpCode |
No |
Return parameter
Name |
Type |
Description |
DpSchema |
DpSchema |
Get the schema information of the DP corresponding to the device |
Request example
TYSdk.device.getDpSchema(dpCode);
TYSdk.device.getState()
Note: 4.0 and above versions support this function.
Request parameter
Name |
Type |
Description |
Required |
idOrCode |
string | number |
dpId or dpCode |
No |
Return parameter
Name |
Type |
Description |
dpState |
{ dpCode: number | string | boolean } |
Get the value of DP. If no parameter is passed, all dpvalues will be obtained |
Request example
TYSdk.device.getState(idOrCode);
TYSdk.device.isBleDevice()
Note: 4.0 and above versions support this function.
Return parameter
Name |
Type |
Description |
isBleDevice |
boolean |
Is it a Bluetooth device |
Request example
TYSdk.device.isBleDevice();
TYSdk.device.isLocalLAN()
Note: 4.0 and above versions support this function.
Return parameter
Name |
Type |
Description |
isLocalLAN |
boolean |
LAN or not |
Request example
TYSdk.device.isLocalLAN();
TYSdk.device.isMeshDevice()
Return parameter
Name |
Type |
Description |
isMeshDevice |
boolean |
Whether it is a device that supports networking |
Request example
TYSdk.device.isMeshDevice();
TYSdk.device.isMeshWifiDevice()
Return parameter
Name |
Type |
Description |
isMeshWifiDevice |
boolean |
Whether it is a device that supports wireless networking |
Request example
TYSdk.device.isMeshWifiDevice();
TYSdk.device.isShareDevice()
Note: 4.0 and above versions support this function.
Return parameter
Name |
Type |
Description |
isShareDevice |
boolean |
Whether it is a device that can be shared |
Request example
TYSdk.device.isShareDevice();
TYSdk.device.isSigMeshDevice()
Note: 4.0 and above versions support this function.
Return parameter
Name |
Type |
Description |
isSigMeshDevice |
boolean |
Whether it is a Bluetooth mesh device |
Request example
TYSdk.device.isSigMeshDevice();
TYSdk.device.isWifiDevice()
Return parameter
Name |
Type |
Description |
isWifiDevice |
boolean |
Whether it is a Wi-Fi device |
Request example
TYSdk.device.isWifiDevice();
TYSdk.device.putDeviceData()
Request parameter
Name |
Type |
Description |
Required |
dpState |
{ dpCode: number | string | boolean } |
Get the required DP status |
Yes |
Request example
TYSdk.device.putDeviceData(dpState);
TYSdk.device.putDeviceData({ switch: true });
TYSdk.device.putLocalDpData()
Note: 4.0 and above versions support this function.
Request parameter
Name |
Type |
Description |
Required |
dpState |
{ dpCode: number | string | boolean } |
Distribution of DPs in LAN |
Yes |
Request example
TYSdk.device.putLocalDpData(dpState);
Mobile Methods
TYSdk.mobile.back()
Request example
TYSdk.mobile.back();
TYSdk.mobile.bottomListDialog()
Note: 4.0 and above versions support this function.
Request parameter
Name |
Type |
Description |
Required |
itemList |
string[] |
List |
Yes |
selected |
string |
An item selected in the list |
Yes |
onConfirmed |
() => void |
Confirmation function |
Yes |
Request example
TYSdk.mobile.bottomListDialog(itemList, selected, onConfirmed);
TYSdk.mobile.disablePopGesture()
Request example
TYSdk.mobile.disablePopGesture();
TYSdk.mobile.enablePopGesture()
Request example
TYSdk.mobile.enablePopGesture();
TYSdk.mobile.getMobileInfo()
Return parameter
Name |
Type |
Description |
MobileInfo |
MobileInfo |
Get client information |
Request example
TYSdk.mobile.getMobileInfo();
TYSdk.mobile.getNetworkState()
Return parameter
Name |
Type |
Description |
netWorkState |
'WIFI' | 'GPRS' | 'BLE' | 'NONE' |
Get network status |
Request example
TYSdk.mobile.getNetworkState();
TYSdk.mobile.hideLoading()
Request example
TYSdk.mobile.hideLoading();
TYSdk.mobile.is24Hour()
Return parameter
Name |
Type |
Description |
is24Hour |
Promise<boolean> |
Whether it is the 24-hour clock |
Request example
TYSdk.mobile.is24Hour()
.then(data => {
console.log('data :>> ', data);
})
.catch(error => {
console.log('error :>> ', error);
});
TYSdk.mobile.jumpSubPage()
Request parameter
Name |
Type |
Description |
Required |
uiIdParams |
{ uiId: string } |
Secondary page item uiId |
Yes |
pageParams |
object |
Passed attributes |
Yes |
Request example
TYSdk.mobile.jumpSubPage(uiIdParams: { uiId }, pageParams);
TYSdk.mobile.jumpTo()
Request parameter
Name |
Type |
Description |
Required |
url |
string |
Set the URL jump function to jump to the mall, official website. If the short URL is configured with a parameter, you need to add the parameter, such as ${url}? homeId=123456 |
Yes |
Request example
TYSdk.mobile.jumpTo(url);
Module |
URL |
Parameter |
Remark |
Scene module |
sceneAction |
{"action":"sceneUiUpdate"} |
Scenario common actions, such as refreshing UI |
createScene |
{"devid":"Device Id"} |
General creation scenario |
createScene_allDevices |
None |
ZigBee scene switch jumps in and creates all device types |
editScene |
{"sceneId":"Device Id"} |
General editing scenarios |
createAuto |
{"devId":"Device Id","dpId":"dpId","dpValue":"dpValue","actionDisplay":"Action display name","actionExcutor":"Action type"} |
Sound and light alarm panel jump in, create automation, bring action data |
createAutoWithCondition |
{"devId":"Device Id","dpId":"dpId","dpValue":"dpValue","operator":"Operator","exprDisplay":"Expression display name","entityType":"Condition type","extraInfo":"Conditional additional information"} |
Creating automation, carrying conditions |
Family module |
tysh_house_manage |
None |
Family management page |
tysh_room_manage |
{ "homeId": "Room id" } |
Room management page |
tysh_family_add |
None |
Add family page |
tysh_family_setting |
{ "homeId": "Room id" } |
Set family page |
tysh_room_setting |
{ "homeId": "Room id" } |
Set room page |
tysh_family_add_member |
{ "homeId": "Room id" } |
Add family member page |
tysh_family_associate_member_rn |
{"memberId": "Member ID", "isAdmin": "Whether it is the administrator "} |
Jump to the associated member page |
member_info |
{"memberId": "memberId", "role":"roleType", "homeId": "homeId"} |
Family member information |
User center |
about |
None |
About us |
user |
None |
User information page |
ty_user_center |
None |
User center page |
ty_user_setting |
None |
Setting page |
browser |
{ "url": "FAQ webpage URL" } |
Frequently asked questions |
settingMoreService |
None |
Jump to more services |
ty_mobile_bind |
None |
Bind the mobile phone number |
Login module |
registernew |
None |
Register |
tp_login |
None |
Login page |
ty_auth_code_login |
{"countryCode": "Country code", "account": "Account"} |
Verification code login page |
modifyPassword |
None |
Change password in login status |
ty_forget_password |
{"countryCode": "Country code", "account": "Account"} |
Forget password |
ty_signout |
None |
Logout |
ty_anonymous_mode |
None |
Jump to experience mode |
Distribution network module |
presentGatewayCategroy |
{"gwId": "Gateway Id"} |
The first version of ZigBee gateway panel with sub device routing |
device_only_search_config_gw_sub |
{"gwId": "Gateway Id"} |
The beginning of new gateway panel distribution network sub equipment scanning distribution network routing |
device_gw_sub_device_help_list |
{"gwId": "Gateway Id"} |
Sub device type list routing of sub equipment in new gateway panel |
Homepage module |
ty_family_speech |
None |
Short URL of the voice assistant desktop shortcut |
Feedback module |
ty_feedback |
{ "key" : "Feedback key" } |
Fill in the feedback page |
helpAndFeedBack |
None |
Feedback list page |
Message center |
messageCenter |
None |
Message center page |
TYSdk.mobile.mobileInfo
Note: 4.0 and above versions support this function.
Return parameter
Name |
Type |
Description |
MobileInfo |
MobileInfo |
Get client information |
Request example
console.log(TYSdk.mobile.mobileInfo);
TYSdk.mobile.showEditDialog()
Note: 4.0 and above versions support this function.
Request parameter
Name |
Type |
Description |
Required |
title |
string |
Title |
Yes |
editString |
string |
Edit message content |
Yes |
onConfirmed |
() => void |
Confirmation function |
Yes |
onCanceled |
() => void |
Cancelation function |
Yes |
Request example
TYSdk.mobile.showEditDialog(title, editString, onConfirmed, onCanceled);
TYSdk.mobile.showLoading()
Request example
TYSdk.mobile.showLoading();
TYSdk.mobile.showPromptDialog()
Request parameter
Name |
Type |
Description |
Required |
confirmText |
string |
Confirmation text |
Yes |
cancelText |
string |
Cancelation text |
Yes |
title |
string |
Dialog box title |
Yes |
message |
string |
Message |
Yes |
defaultValue |
string |
Default value |
Yes |
onConfirmed |
() => void |
Confirmation function |
Yes |
onCanceled |
() => void |
Cancelation function |
Yes |
Request example
TYSdk.mobile.showPromptDialog(
confirmText,
cancelText,
title,
message,
defaultValue,
onConfirmed,
onCanceled
);
TYSdk.mobile.simpleConfirmDialog()
Note: 4.0 and above versions support this function.
Request parameter
Name |
Type |
Description |
Required |
title |
string |
Title |
Yes |
msg |
string |
Dialog box message |
Yes |
onConfirmed |
() => void |
Confirmation function |
Yes |
onCanceled |
() => void |
Cancelation function |
Yes |
Request example
TYSdk.mobile.simpleConfirmDialog(title, msg, onConfirmed, onCanceled);
TYSdk.mobile.simpleTipDialog()
Note: 4.0 and above versions support this function.
Request parameter
Name |
Type |
Description |
Required |
msg |
string |
Dialog box message |
Yes |
onConfirmed |
() => void |
Confirmation function |
Yes |
Request example
TYSdk.mobile.simpleTipDialog(msg, onConfirmed);
TYSdk.mobile.verSupported()
Return parameter
Name |
Type |
Description |
verSupported |
boolean |
Is the app version supported |
Request example
TYSdk.mobile.verSupported();
Native method
TYSdk.native.gotoDpAlarm()
Note: TYSdk.native.gotoDpAlarm does not support raw
device function points (dpId).
Request parameter
Name |
Type |
Description |
Required |
category |
string |
Timing type |
Yes |
repeat |
number |
0 indicates that selecting repeat is necessary, and 1 indicates that selecting repeat is unnecessary |
Yes |
data |
data |
Need timing related DP information |
Yes |
Request example
const dpId = TYSdk.device.getDpIdByCode(dpCode);
const dpName = Strings.getDpLang(dpCode);
const category = "schedule";
TYSdk.native.gotoDpAlarm({
category,
repeat: 0,
data: [
{
dpId,
dpName,
selected: 0,
rangeKeys: [true, false],
rangeValues: [dpValue1, dpValue2],
},
],
});
TYSdk.native.showDeviceMenu()
Request example
TYNative.showDeviceMenu();