English
English
简体中文
Contact Us
Register
Log In
Language
English
English
简体中文
Contact Us
Log In
Register
Go to main website
App Develop

App Development

Tuya provides multiple mobile app development methods such as no-code or IoT App SDK development to maximize the monetization of IoT apps.
layoutIndex

Project Data Statistics

Last Updated on : 2022-01-14 03:01:24download

This topic describes the API operations that are used to manage project data. The implemented features are displayed on the commercial lighting dashboard.

API list

Request method API Description
GET /v1.0/iot-02/statics/project/device/info Query device overview
GET /v1.0/iot-02/statics/project/device/type/info Query details of devices by type
GET /v1.0/iot-02/statics/project/environment/state Get environmental status
GET /v1.0/iot-02/statics/project/energy Query the total energy consumption by day, week, and month
GET /v1.0/iot-02/statics/project/energy/type Query energy consumption by device type on a daily, weekly, or monthly basis.
GET /v1.0/iot-02/statics/project/alarm/list Get project alert list
GET /v1.0/iot-02/statics/project/exception/list Get project exception list

Query device overview

API description

Query the overview of devices in a specified project, including the total number of devices and the number of offline devices.

API endpoint

GET /v1.0/iot-02/statics/project/device/info

Request parameter

Parameter Type Parameter type Description Required
projectId String body The project ID. true

Response parameter

Parameter Type Description
code Integer The error code. For more information, see the error code section. It is null when the request succeeded.
success Boolean Determine whether the request succeeded.
  • true: success.
  • false: failure.
msg String The message that is returned if the request fails. The response is empty if the request succeeds.
t Long The returned 13-digit timestamp.
result Object The returned result.

Description of result

Parameter Type Description
total Long The total number of devices.
running Long The number of running devices.
stop Long The number of stopped devices.
offline Long The number of offline devices.
exception Long The number of failed devices.

Sample request

{
  "projectId": "sdjk232123****"
}

Sample response

{
  "total": 410,
  "running": 100,
  "stop": 100,
  "offline": 110,
  "exception": 100
}

Query details of devices by type

API description

Query the details of devices by device type. Map is returned, and key is the name of a specified device type.

API endpoint

GET /v1.0/iot-02/statics/project/device/type/info

Request parameter

Parameter Type Parameter type Description Required
projectId String body The project ID. true

Response parameter

Parameter Type Description
code Integer The error code. For more information, see the error code section. It is null when the request succeeded.
success Boolean Determine whether the request succeeded.
  • true: success.
  • false: failure.
msg String The message that is returned if the request fails. The response is empty if the request succeeds.
t Long The returned 13-digit timestamp.
result Object The returned result.

Description of result

Parameter Type Description
total Long The total number of devices.
running Long The number of running devices.
stop Long The number of stopped devices.
offline Long The number of offline devices.
exception Long The number of failed devices.

Sample request

{
  "projectId": "ssd23213****"
}

Sample response

{
 {
    "data": {
        "Security & Sensors": {
            "exception": 1,
            "offline": 1,
            "running": 1,
            "stop": 0,
            "total": 1
        },
        "Small home appliance": {
            "exception": 0,
            "offline": 0,
            "running": 1,
            "stop": 0,
            "total": 1
        },
        "lighting": {
            "exception": 1,
            "offline": 2,
            "running": 58,
            "stop": 0,
            "total": 58
        },
        "Electrical device": {
            "exception": 0,
            "offline": 0,
            "running": 2,
            "stop": 0,
            "total": 2
        },
        "Gateway control": {
            "exception": 0,
            "offline": 0,
            "running": 2,
            "stop": 0,
            "total": 2
        }
    }
}
}

Get environmental status

API description

Get the environmental status of a specified project, including space name, PM2.5, temperature, and humidity.

API endpoint

GET /v1.0/iot-02/statics/project/environment/state

Request parameter

Parameter Type Parameter type Description Required
projectId String body The project ID. true

Response parameter

Parameter Type Description
code Integer The error code. For more information, see the error code section. It is null when the request succeeded.
success Boolean Determine whether the request succeeded.
  • true: success.
  • false: failure.
msg String The message that is returned if the request fails. The response is empty if the request succeeds.
t Long The returned 13-digit timestamp.
result Object The returned result.

Description of result

Parameter Type Description
spaceName String The name of a specified space.
temperature Double The temperature.
humidity Double The humidity.
co2Point Double The carbon dioxide index.
pm25Point Double The PM2.5 index.
comfort Double The ambient comfort (percentage).

Sample request

{
  "projectId": "23213sadad23****"
}

Sample response

{
  "spaceName": "Test space",
  "temperature": 22.3,
  "humidity": 3.3,
  "co2Point": 80.2,
  "pm25Point": 3.3,
  "comfort": 80.8"
}

Query the total energy consumption by day, week, and month

API description

Get the total energy consumption of a specified project. Valid values of period include day, week, and month.

API endpoint

GET /v1.0/iot-02/statics/project/energy

Request parameter

Parameter Type Parameter type Description Required
projectId String body The project ID. true
period String body The query period. true

Response parameter

Parameter Type Description
code Integer The error code. For more information, see the error code section. It is null when the request succeeded.
success Boolean Determine whether the request succeeded.
  • true: success.
  • false: failure.
msg String The message that is returned if the request fails. The response is empty if the request succeeds.
t Long The returned 13-digit timestamp.
result Object The returned result.

Description of result

Parameter Type Description
ydl Double The electricity consumption data.
ydlFlag Boolean The flag of electricity consumption data.
tb Double The year-on-year data.
tbFlag Boolean The flag of the year-on-year data.
hb Double The comparison data with the last statistical period.
hbFlag Boolean The flag of the comparison data with the last statistical period.
energyDetailList List The list of energy consumption details.
time Long The time.
energy Double The value of energy consumption.
period String The period.

Sample request

{
  "period": "week",
  "projectId": "sdad2312ks****"
}

Sample response

{
  "ydl": 100,
  "ydlFlag": true,
  "tb": 20,
  "tbFlag": true,
  "hb": 30,
  "hbFlag": true,
  "energyDetailList": [
    {
      "time":10011223112222,
      "energy":30,
      "period":"Sunday"
    }
  ]
}

Query energy consumption by device type on a daily, weekly, or monthly basis

API description

Get the energy consumption of a specified device type. Valid values of period include day, week, and month.

API endpoint

GET /v1.0/iot-02/statics/project/energy/type

Request parameter

Parameter Type Parameter type Description Required
projectId String body The project ID. true
period String body The query period. true

Response parameter

Parameter Type Description
code Integer The error code. For more information, see the error code section. It is null when the request succeeded.
success Boolean Determine whether the request succeeded.
  • true: success.
  • false: failure.
msg String The message that is returned if the request fails. The response is empty if the request succeeds.
t Long The returned 13-digit timestamp.
result Object The returned result.

Description of result

Parameter Type Description
ydl Double The electricity consumption data.
ydlFlag Boolean The flag of electricity consumption data.
tb Double The year-on-year data.
tbFlag Boolean The flag of the year-on-year data.
hb Double The comparison data with the last statistical period.
hbFlag Boolean The flag of the comparison data with the last statistical period.
energyDetailList List The list of energy consumption details.
time Long The time.
energy Double The value of energy consumption.
period String The period.

Sample request

{
  "period": "week",
  "projectId": "213123sad****"
}

Sample response

{
    "data": {
        "Energy consumption of lighting sockets": {
            "energyDetailList": [],
            "hbFlag": true,
            "tbFlag": true,
            "ydl": 679.81,
            "ydlFlag": true
        }
    }
}

Get project alert list

API description

Get a list of device alerts on pages. The first page is shown by default.

API endpoint

GET /v1.0/iot-02/statics/project/alarm/list

Request parameter

Parameter Type Parameter type Description Required
projectId String body The project ID. true
page int body The current page number. true
pageSize int body The number of items to be returned per page. true

Response parameter

Parameter Type Description
code Integer The error code. For more information, see the error code section. It is null when the request succeeded.
success Boolean Determine whether the request succeeded.
  • true: success.
  • false: failure.
msg String The message that is returned if the request fails. The response is empty if the request succeeds.
t Long The returned 13-digit timestamp.
result Object The returned result.

Description of result

Parameter Type Description
alarmNum Long The total number of alerts.
solvedNum Long The number of solved alerts.
unsolvedNum Long The number of unsolved alerts.
data Object The returned list.
total Integer The total number of alerts.
list List The list of alerts.
alarmId String The ID of an alert.
roomId String The room ID.
roomName String The name of a room.
event String The name of an event.
disalarm Boolean Indicates whether to disarm.
category String The name of a specified device category.
categoryCode String The code of a specified device category.

Sample request

{
  "pageSize": 10,
  "page": 1,
  "projectId": "sdaddasd23****"
}

Sample response

{
    "alarmNum": 5921,
    "data": {
        "list": [
            {
                "alarmId": "147000657683107****",
                "category": "jjaf",
                "disalarm": true,
                "event": "Air detector offline",
                "roomId": "133260803333062****",
                "roomName": "B1.VIP Public"
            }
        ],
        "total": 5921
    },
    "solvedNum": 5915,
    "unsolvedNum": 6
}

Get project exception list

API description

Get a list of exceptions on pages.

API endpoint

GET /v1.0/iot-02/statics/project/exception/list

Request parameter

Parameter Type Parameter type Description Required
projectId String body The project ID. true
page int body The current page number. true
pageSize int body The number of items to be returned per page. true

Response parameter

Parameter Type Description
code Integer The error code. For more information, see the error code section. It is null when the request succeeded.
success Boolean Determine whether the request succeeded.
  • true: success.
  • false: failure.
msg String The message that is returned if the request fails. The response is empty if the request succeeds.
t Long The returned 13-digit timestamp.
result Object The returned result.

Description of result

Parameter Type Description
alarmNum Long The total number of alerts.
solvedNum Long The number of solved alerts.
unsolvedNum Long The number of unsolved alerts.
data Object The returned list.
total Integer The total number of alerts.
list List The list of alerts.
alarmId String The ID of an alert.
roomId String The room ID.
roomName String The name of a room.
event String The name of an event.
disalarm Boolean Indicates whether to disarm.
category String The name of a specified device category.
categoryCode String The code of a specified device category.

Sample request

{
  "pageSize": 20,
  "page": 2,
  "projectId": "sadadasd2s****"
}

Sample response

{
    "alarmNum": 5921,
    "data": {
        "list": [
            {
                "alarmId": "147000657683107****",
                "category": "jjaf",
                "disalarm": true,
                "event": "Air detector offline",
                "roomId": "133260803333062****",
                "roomName": "B1.VIP Public"
            }
        ],
        "total": 5921
    },
    "solvedNum": 5915,
    "unsolvedNum": 6
}

Error codes

The following table lists common error codes for the API calls. For more error codes, see Global Error Codes.

Error code Description
500 The error message is returned because a system error has occurred.