Linkage Features

Last Updated on : 2024-06-05 03:14:36download

This topic describes the API operations that you can call to manage the linkage features. These features are updated based on scenes. Multiple new features are supported. For example, a single trigger can be bound with multiple scene rules. All protocols are supported. Scenes can be enabled, disabled, or deleted.

Note: To use commonApi, you must install dependencies first.

Get a list of linkage devices

Name

getLinkageDeviceList

Description

Returns all devices that support linkages. These devices are bound with a specific home.

Request parameter

Parameter Data type Description Required
gid Number The home ID. Yes
sourceType String The type of request. Yes

Return parameter

Parameter Data type Description
data Array The list of returned devices.

Sample request

import { commonApi } from 'tuya-panel-api';

const { linkageApi } = commonApi;  

linkageApi.getLinkageDeviceList({
  gid: 11740421,
  sourceType: 'wirelessSwitch'
}).then((response) => {
    console.log(response)
}).catch()

Sample response

[{  
   'category': 'wxkg',
   'datapoints': [],
   'devId': 'vdevo161473760344855',
   'iconUrl': 'xxxx',
   'name': 'Wireless switch',
   'productId': 'xxxx'
}]

Get a list of scenes

Name

getSceneList

Description

Returns a list of tap-to-run scenes supported by a specific device.

Request parameter

Parameter Data type Description Required
devId String The device ID. Yes

Return parameter

Parameter Data type Description
data Array The list of scenes.

Sample request

import { commonApi } from 'tuya-panel-api';

const { linkageApi } = commonApi;  
  
linkageApi.getSceneList({
  devId: 'vdevo161469104176416',
}).then((response) => {
    console.log(response)
}).catch()

Sample response


[{  
    actions: [],
    attribute: 4,
    auditStatus: 0,
    background: '',
    boundForPanel: false,
    boundForWiFiPanel: false,
    code: '',
    commonField: '',
    coverIcon: 'xxx',   
    disableTime: 0,
    displayColor: '23AFA9',
    enabled: true,
    devId: 'vdevo161473760344855',
    name: '222',
    id: 'tgnVdPuWVoAZ1W89',
}]

Get a list of scenes associated with device details

Name

getBindRuleList

Description

Returns a list of scenes that are associated with device details.

Request parameter

Parameter Data type Description Required
bizDomain String The service domain. Yes
sourceEntityId String The device ID. Yes
entityType Number The type of entity. Yes

Return parameter

Parameter Data type Description
data Array The list of rules that apply to the associated scenes.

Sample request

import { commonApi } from 'tuya-panel-api';

const { linkageApi } = commonApi;  
  
linkageApi.getBindRuleList({
  devId: 'vdevo161469104176416',
  bizDomain: 'wirelessSwitchBindScene',
  entityType: 2 
}).then((response) => {
    console.log(response)
}).catch()

Sample response

[{  
    associativeEntityId: '1#single_click'
    associativeEntityValueList: [],
    bizDomain: 'wirelessSwitchBindScene',
    sourceEntityId: 'vdevo161473760344855'
}]

Bind a scene

Name

bindRule

Description

Associates button actions with scene rules.

Request parameter

Parameter Data type Description Required
associativeEntityId String The group of the associated data point (DP) and DP value. Yes
ruleId String The associated scene ID. Yes
entitySubIds String The associated DP. Yes
expr Array The group of the associated DP and action. Yes
bizDomain String The service domain. Yes

Return parameter

Parameter Data type Description
associativeEntityId String The group of the associated DP and DP value.
associativeEntityValue String The action ID.
bizDomain String The service domain.
id Number The data ID.
ownerId String The home ID.
sourceEntityId String The device ID.
triggerRuleId String The rule ID.
triggerRuleVO Object The information about the device that performs the specified action.

Sample request

import { commonApi } from 'tuya-panel-api';

const { linkageApi } = commonApi;  
  
linkageApi.bindRule({
  associativeEntityId: '1#single_click',
  ruleId: 'xxxxx',
  entitySubIds: "1",
  expr: [[ '$dp1', '==', 'Tap' ]],
  bizDomain: 'wirelessSwitchBindScene'
}).then((response) => {
    console.log(response)
}).catch()

Sample response

{
     associativeEntityId: '1#double_click',
     associativeEntityValue: 'huqzuD0Bb8wz1wxM',
     bizDomain: 'wirelessSwitchBindScene',
     id: 295022,
     ownerId: '11740421',
     sourceEntityId: 'vdevo161469104176416',
     triggerRuleId: '53BlwWMpfUJMFHYu',
     triggerRuleVO: {}
}

Unbind a scene

Name

removeRule

Description

Unbinds a scene from a specific button action.

Request parameter

Parameter Data type Description Required
bizDomain String The service domain. Yes
sourceEntityId String The device ID. Yes
associativeEntityId String The group of associated DPs. Yes
associativeEntityValue String The rule ID. Yes

Return parameter

Parameter Data type Description
result Boolean Indicates whether the operation is successful.

Sample request

import { commonApi } from 'tuya-panel-api';

const { linkageApi } = commonApi;  
  
linkageApi.removeRule({
   bizDomain: 'wirelessSwitchBindScene',
   sourceEntityId: 'vdevo161473760344855',
   associativeEntityId: '1#scene_1',
   associativeEntityValue: 'y2zAjojrpeZx9Dtu'
}).then((response) => {
    console.log(response)
}).catch()

Sample response

  true

Trigger a scene

Name

triggerRule

Description

Triggers a tap-to-run scene that is executed by the cloud.

Request parameter

Parameter Data type Description Required
ruleId String The rule ID. Yes

Return parameter

Parameter Data type Description
result Boolean Indicates whether the operation is successful.

Sample request

import { commonApi } from 'tuya-panel-api';

const { linkageApi } = commonApi;  
  
linkageApi.triggerRule({
  ruleId: 'y2zAjojrpeZx9Dtu',
}).then((response) => {
    console.log(response)
}).catch()

Sample response

   true

Enable a rule

Name

enableRule

Description

Enables a specified rule.

Request parameter

Parameter Data type Description Required
ruleId String The rule ID. Yes

Return parameter

Parameter Data type Description
result Boolean Indicates whether the operation is successful.

Sample request

import { commonApi } from 'tuya-panel-api';

const { linkageApi } = commonApi;  
  
linkageApi.enableRule({
   ruleId: 'y2zAjojrpeZx9Dtu',
}).then((response) => {
    console.log(response)
}).catch()

Sample response

   true

Disable a rule

Name

disableRule

Description

Disables a specified rule.

Request parameter

Parameter Data type Description Required
ruleId String The rule ID. Yes

Return parameter

Parameter Data type Description
result Boolean Indicates whether the operation is successful.

Sample request

import { commonApi } from 'tuya-panel-api';

const { linkageApi } = commonApi;  
  
linkageApi.disableRule({
   ruleId: 'y2zAjojrpeZx9Dtu',
}).then((response) => {
    console.log(response)
}).catch()

Sample response

   true