Device Data Statistics

Last Updated on : 2023-07-20 09:22:33download

This topic describes the APIs available for statistics of device data.

API list

Request method API name Description
GET /v1.0/devices/{device_id}/statistics/total Get all historical data
GET /v1.0/devices/{dev_id}/all-statistic-type Get available types of statistics
GET /v1.0/devices/{dev_id}/statistics/quarters Get data by minutes
GET /v1.0/devices/{dev_id}/statistics/hours Get data by hours
GET /v1.0/devices/{device_id}/statistics/days Get cumulative data by days
GET /v1.0/devices/{device_id}/statistics/weeks Get cumulative data by weeks
GET /v1.0/devices/{device_id}/statistics/months Get cumulative data by months

Get all historical data

API description

Get the cumulative value of historical data.

API endpoint

GET /v1.0/devices/{device_id}/statistics/total?code=xxx

Request parameters

Parameter name Type Parameter type Required Description
device_id String URI Yes The device ID.
code String Query Yes The identifier of the specified data point, depending on the product.

Response parameters

Parameter name Type Description
code Integer The response code. For more information, see Global Error Codes.
success Boolean Indicates whether the operation is successful. Valid values:
  • true: success.
  • false: failure.
msg String The error message that is returned if the API call fails. This parameter value is empty if the API call succeeds.
result Object The returned result.

Result

Parameter name Type Description
total String The statistics of cumulative data.

Sample request

GET /v1.0/devices/{device_id}/statistics/total?code=add_ele

Sample response

{
    "success": true,
    "t": 1545286977957,
    "result": {
        "total" : "92.68"
    }
}

Get available types of statistics

API description

Get the types of statistics available to the specified device.

API endpoint

GET /v1.0/devices/{dev_id}/all-statistic-type

Request parameters

Parameter name Type Required Description
dev_id URI Yes The device ID, equivalent to device_id.
code Query No The identifier of the specified data point. By default, get the information about all data points.

Response parameters

Parameter name Type Description
code Integer The response code. For more information, see Global Error Codes.
success Boolean Indicates whether the operation is successful. Valid values:
  • true: success.
  • false: failure.
msg String The error message that is returned if the API call fails. This parameter value is empty if the API call succeeds.
result Object The types of statistics supported by the specified data point identifier.

Sample request

GET /v1.0/devices/tuya1319563f96bc263b/all-statistic-type?code=sum_dp

Sample response

{
    "success": true,
    "t": 1562898798074,
    "result": [
        {
            "code": "sum_dp",
            "stat_type": "sum"
        },
        {
            "code": "avg_dp",
            "stat_type": "avg"
        }
    ]
}

Get data by minutes

API description

Show the statistics data of the specified device in the last 7 days at intervals of 15 minutes.

API endpoint

GET /v1.0/devices/{dev_id}/statistics/quarters

Request parameters

Parameter name Type Required Description
dev_id URI Yes The device ID, equivalent to device_id.
code Query Yes The identifier of the specified data point.
start_minute Query Yes The start time of the period to be queried, with precision down to minutes. Format: yyyyMMddHHmm.
end_minute Query Yes The end time of the period to be queried, with precision down to minutes. The value must be on the same date as start_minute and later than start_minute. Format: yyyyMMddHHmm.

Response parameters

Parameter name Type Description
code Integer The response code. For more information, see Global Error Codes.
success Boolean Indicates whether the operation is successful. Valid values:
  • true: success.
  • false: failure.
msg String The error message that is returned if the API call fails. This parameter value is empty if the API call succeeds.
result Object The success callback.

Sample request

GET /v1.0/devices/tuya73767600194b8b2b3/statistics/quarters?code=add_ele&start_minute=201908290815&end_minute=201908291045

Sample response

{
    "success": true,
    "t": 1567079117639,
    "result": {
        "quarters": {
            "201908290815": "0.01",
            "201908290830": "0.00",
            "201908290845": "0.01",
            "201908290900": "0.00",
            "201908290915": "0.01",
            "201908290930": "0.00",
            "201908290945": "0.01",
            "201908291000": "0.00",
            "201908291015": "0.02",
            "201908291030": "0.00"
        }
    }
}

Get data by hours

API description

Show the statistics hourly collected from the specified device in the last 7 days.

API endpoint

GET /v1.0/devices/{dev_id}/statistics/hours

Request parameters

Parameter name Type Required Description
dev_id URI Yes The device ID, equivalent to device_id.
code Query Yes The identifier of the specified data point.
start_hour Query Yes The start time of the period to be queried, with precision down to hours. Format: yyyyMMddHH.
end_hour Query Yes The end time of the period to be queried, with precision down to hours. The value must be on the same date as start_hour and later than start_hour. Format: yyyyMMddHH.
stat_type Query Yes The type of statistics. Valid values: sum, count, and avg. Default value: sum.

Response parameters

Parameter name Type Description
code Integer The response code. For more information, see Global Error Codes.
success Boolean Indicates whether the operation is successful. Valid values:
  • true: success.
  • false: failure.
msg String The error message that is returned if the API call fails. This parameter value is empty if the API call succeeds.
result Object The success callback.

Sample request

GET /v1.0/devices/tuya1319563f96bc263b/statistics/hours?code=sum_dp&one_day=20190705&start_hour=2019070501&end_hour=2019070502

Sample response

{
    "success": true,
    "t": 1562747403791,
    "result": {
        "hours": {
            "2019070501": "0.00",
            "2019070502": "1.00"
        }
    }
}

Get cumulative data by days

API description

Show the statistics data of the specified device by days.

API endpoint

GET /v1.0/devices/{device_id}/statistics/days?code=xxx&start_day=xxx&end_day

Request parameters

Parameter name Type Parameter type Required Description
device_id String URI Yes The device ID.
code String Query Yes The identifier of the specified data point.
start_day String Query Yes The start date. Example: 20190101.
end_day String Query Yes The end date. Example: 20190107.
stat_type String Query No The type of statistics. Valid values: sum, count, and avg. Default value: sum.

Response parameters

Parameter name Type Description
code Integer The response code. For more information, see Global Error Codes.
success Boolean Indicates whether the operation is successful. Valid values:
  • true: success.
  • false: failure.
msg String The error message that is returned if the API call fails. This parameter value is empty if the API call succeeds.
result Object The returned result.

Result

Parameter name Type Description
days Map The daily statistics.

Sample request

GET /v1.0/devices/vdevo156274241600622/statistics/days?code=switch_1&start_day=20190705&end_day=20190706&stat_type=sum

Sample response

{
    "success": true,
    "t": 1547650028453,
    "result": {
        "days": {
            "20190101": "0",
            "20190102": "0",
            "20190103": "0",
            "20190104": "0",
            "20190105": "0",
            "20190106": "0",
            "20190107": "0",
            "20190108": "0",
            "20190109": "0",
            "20190110": "0",
            "20190111": "0.01",
            "20190112": "0.01",
            "20190113": "0"
        }
    }
}

Get cumulative data by weeks

API description

Show the statistics data of the specified device by weeks.

API endpoint

GET /v1.0/devices/{device_id}/statistics/weeks?code=xxx&start_week=xxx&end_week

Request parameters

Parameter name Type Parameter type Required Description
device_id String URI Yes The device ID.
code String Query Yes The identifier of the specified data point.
start_week String Query Yes The week of the year in which the start time falls. Example: 201805 indicates week 5 of the year 2018.
end_week String Query Yes The week of the year in which the end time falls. Example: 201807 indicates week 7 of the year 2018.

Response parameters

Parameter name Type Description
code Integer The response code. For more information, see Global Error Codes.
success Boolean Indicates whether the operation is successful. Valid values:
  • true: success.
  • false: failure.
msg String The error message that is returned if the API call fails. This parameter value is empty if the API call succeeds.
result Object The returned result.

Result

Parameter name Type Description
weeks Map The weekly statistics.

Sample request

GET /v1.0/devices/{device_id}/weeks/statistics?code=add_ele&start_week=201901&end_week=201902

Sample response

{
    "success": true,
    "t": 1547650180271,
    "result": {
        "weeks": {
            "201901": "0",
            "201902": "0.02"
        }
    }
}

Get cumulative data by months

API description

Show the statistics data of the specified device by months.

API endpoint

GET /v1.0/devices/{device_id}/statistics/months?code=xxx&start_month=xxx&end_month=xxx

Request parameters

Parameter name Type Parameter type Required Description
device_id String URI Yes The device ID.
code String Query Yes The identifier of the specified data point.
start_month String Query Yes The start month. Example: 201901.
end_month String Query Yes The end month. Example: 201901.

The start month and end month must be in the same year.

Response parameters

Parameter name Type Description
code Integer The response code. For more information, see Global Error Codes.
success Boolean Indicates whether the operation is successful. Valid values:
  • true: success.
  • false: failure.
msg String The error message that is returned if the API call fails. This parameter value is empty if the API call succeeds.
result Object The returned result.

Result

Parameter name Type Description
months Map The monthly statistics.

Sample request

GET /v1.0/devices/{device_id}/statistics/months?code=cur_voltage&start_month=201801&end_month=201809

Sample response

{
    "success": true,
    "t": 1545286977957,
    "result": {
        "months" : {
            "201801":"11.36",
            "201802":"13.81",
            "201803":"12.39",
            "201804":"20.31",
            "201805":"14.47",
            "201806":"7.77",
            "201807":"1.29",
            "201808":"3.13",
            "201809":"8.15"
        }
    }
}