Device Related

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

This topic describes APIs related to devices.

Note:
To use commonApi, you need to install dependencies first, click here to install dependencies.

Get information of all data points (DPs) of a device

Name

getDpsInfos

Description

Get information of all DPs of a device.

Request parameter

Parameter Data type Description Required
gwId String Device ID Yes
devId String Device ID Yes

Return parameter

Parameter Data type Description
Code String DP code
dpId Number DP ID
value String DP value
name String DP name
time Number The last time when the DP status is reported
type String DP type

Sample request

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

commonApi.deviceApi
  .getDpsInfos({
  gwId: TYSdk.devInfo.devId,
  devId: TYSdk.devInfo.devId,
})
  .then(response => {
  console.log(response);
})
  .catch();

Sample response

[
    {
        "code": "switch_led",
        "dpId": 20,
        "value": "true",
        "type": "bool",
        "time": 1621406710368
    },
    {
        "code": "work_mode",
        "dpId": 21,
        "value": "scene",
        "type": "enum",
        "time": 1621407290755
    },
    {
        "code": "bright_value",
        "dpId": 22,
        "value": "708",
        "type": "value",
        "time": 1621406712755
    },
    {
        "code": "temp_value",
        "dpId": 23,
        "value": "591",
        "type": "value",
        "time": 1621406181855
    },
    {
        "code": "colour_data",
        "dpId": 24,
        "value": "0168000003e8",
        "type": "string",
        "time": 1621406716923
    },
    {
        "code": "scene_data",
        "dpId": 25,
        "value": "020e0d0000000000000003e803e8",
        "type": "string",
        "time": 1621407290755
    },
    {
        "code": "countdown",
        "dpId": 26,
        "value": "0",
        "type": "value",
        "time": 1617334251531
    },
    {
        "code": "music_data",
        "dpId": 27,
        "value": "",
        "type": "string",
        "time": 1617334251531
    },
    {
        "code": "control_data",
        "dpId": 28,
        "value": "00127001c03e800000000",
        "type": "string",
        "time": 1621406741938
    }
]

Update the DP name for a device

Name

updateDpName

Description

Update the DP name for a device.

Request parameter

Parameter Data type Description Required
gwId String Device ID Yes
devId String Device ID Yes
dpId String DP ID Yes
name String Custom DP name Yes

Return parameter

Parameter Data type Description
response Boolean Whether the DP name is updated successfully.

Sample request

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

commonApi.deviceApi
  .updateDpName({
  gwId: TYSdk.devInfo.devId,
  devId: TYSdk.devInfo.devId,
  dpId: '21',
  name: 'work_mode',
})
  .then(response => {
  console.log(response);
})
  .catch();

Sample response

true

Get information of all DPs of group devices

Name

getGroupDpsInfos

Description

Get information of all DPs of group devices.

Request parameter

Parameter Data type Description Required
groupId String Group ID Yes

Return parameter

Parameter Data type Description
Code String DP code
dpId Number DP ID
value String DP value
name String DP name
time Number The last time when the DP status is reported
type String DP type

Sample request

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

commonApi.deviceApi
  .getGroupDpsInfos('1')
  .then(response => {
    console.log(response);
  })
  .catch();

Sample response

{
    {
      "code": "switch_spray",
      "dpId": 1,
      "value": "true",
      "name": "",
      "time": 1572338762533,
      "type": "bool"
    },
    {
      "code": "mode",
      "dpId": 2,
      "value": "large",
      "name": "",
      "time": 1572333409976,
      "type": "enum"
    },
}

Update the DP name for group devices

Name

updateGroupDpName

Description

Update the DP name for group devices.

Request parameter

Parameter Data type Description Required
groupId String Group ID Yes
dpId String DP ID Yes
name String Custom DP name Yes

Return parameter

Parameter Data type Description
response Boolean Whether the DP name is updated successfully.

Sample request

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

commonApi.deviceApi
  .updateGroupDpName({
    groupId: '1',
    dpId: '20',
    name: 'switch_led',
  })
  .then(response => {
    console.log(response);
  })
  .catch();

Sample response

true

Get weather forecast of the current day

Name

getWeatherQuality

Description

Get weather forecast of the current day by the device ID.

Request parameter

Parameter Data type Description Required
devId String Device ID Yes
isLocal Boolean Whether to use the user’s local time zone. The value defaults to false. No

Return parameter

Parameter Data type Description
c c[] See table c below.
w w[] See table w below.
  • c
Parameter Data type Description
name String City name
id Number City ID
  • w
Parameter Data type Description
windDir String Wind direction
tips String Overview
realFeel Number Apparent temperature
no2 Number Nitrogen dioxide
so2 Number Sulfur dioxide
zoneId String Time zone
humidity Number Air humidity
windSpeed String Wind speed in m/s
temp Number Temperature in Celsius (°C)
o3 Number Ozone
pm10 Number PM10
pressure Number Atmospheric pressure
co Number Carbon monoxide
qualityLevel Number Air quality level
quality String Air quality rating
condition String The text to describe weather conditions
pm25 Number PM2.5
condIconUrl String URL of weather icons
aqi Number Air quality
conditionNum String The serial number of descriptions of weather conditions
sunRise String Sunrise time text, the text format is yyyy-MM-dd HH:mm:ss
sunSet String Sunset time text, the text format is yyyy-MM-dd HH:mm:ss
sunRiseTimestamp Number Sunrise timestamp
sunSetTimestamp Number Sunset timestamp

Sample request

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

commonApi.deviceApi
  .getWeatherQuality({
  devId: TYSdk.devInfo.devId,
  isLocal: true,
})
  .then(response => {
  console.log(response);
})
  .catch();

Sample response

{
"result": 
   {
    c: 
       {
	name: String,   // City name
	id: Number,    // City ID
         },
     w:
       {
	windDir: String,   // Wind direction
	tips: String,   // Overview
	realFeel: Number   // Apparent temperature
	no2:  Number   // Nitrogen dioxide
	so2: Number // Sulfur dioxide
	zoneId: String,   // Time zone
	humidity: Number,   // Air humidity
	windSpeed: String,       // Wind speed in m/s
	temp: Number,   // Temperature in Celsius (°C)
	o3: Number,      // Ozone
	pm10: Number,     // PM10
	pressure: Number,      // Atmospheric pressure
	co: Number,    // Carbon monoxide
	qualityLevel: Number,   // Air quality level
	quality: String,      // Air quality rating
	condition: String,      // The text to describe weather conditions
	pm25: Number,     // PM2.5
	condIconUrl: String,  // URL of weather icons
	aqi: Number,    // Air quality
	conditionNum: String,    // The serial number of descriptions of weather conditions
	sunRise: String,    // Sunrise time text 
        sunSet: String,     // Sunset time text 
        sunRiseTimestamp: Number,    // SunRise timestamp
        sunSetTimestamp: number,    // Sunset timestamp
     }
},
"t": 1527770277652,
"success": true,
"status": "ok"
}

Note: The weather is obtained according to the latitude and longitude and IP address configured during device pairing. If this API returns true, but there is no specific weather data, the latitude, longitude, and IP address of the device might be set incorrectly. Check the device log.

Create custom location information

Name

saveCustomizePosition

Description

Create custom location information.

Note: If the weather API does not apply to the latitude and longitude configured during device pairing, you can get real-time weather by customizing latitude and longitude, such as for outdoor wearables.

Request parameter

Parameter Data type Description Required
devId String Device ID Yes
lon String Longitude Yes
lat String Latitude Yes
locationName String Location name No

Return parameter

Parameter Data type Description
response Boolean Whether the custom location information is successfully created.

Sample request

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

commonApi.deviceApi
  .saveCustomizePosition({
  devId: TYSdk.devInfo.devId,
  lon: '113.2333',
  lat: '23.1666',
})
  .then(response => {
  console.log(response);
})
  .catch();

Sample response

true

Get custom location information

Name

getCustomizePosition

Description

Get the custom location information of the device.

Request parameter

Parameter Data type Description Required
devId String Device ID Yes

Return parameter

Parameter Data type Description
lon String Longitude
lat String Latitude

Sample request

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

commonApi.deviceApi
  .getCustomizePosition({
  devId: TYSdk.devInfo.devId,
})
  .then(response => {
  console.log(response);
})
  .catch();

Sample response

{
  "lon": "113.2333",
  "lat": "23.1666"
}