---
name: "getStatisticsRangHour"
mode: "api"
versionRequirements:
  - { name: "@tuya-miniapp/cloud-api", version: "1.0.5" }
---

## getStatisticsRangHour

> [VERSION] @tuya-miniapp/cloud-api >= 1.0.5

> 💡 This API is a cloud capability and requires authorization before use. For details on cloud capabilities, see the [documentation](/cn/miniapp/common/desc/tech-stack/api).
> Note: Currently, cloud capabilities are not available in the Developer Tools environment; you must package the app or debug on a real device.

### Description

With an hourly interval, retrieve the device's statistics for the date range.

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `data` | `IGetStatisticsRang` | Yes | Request body |

### Return Value

Type: `Promise<IStatisticsData>`

IStatisticsData (keys are hourly granularity, etc.; see the sample response in the docs)

### Referenced Types

##### `type` IGetStatisticsRang

15-min/hour granularity: single day + common statistics fields (e.g., `getStatisticsRang15min`, `getStatisticsRangHour`).

```typescript
export type IGetStatisticsRang = ICommonGetStatisticsRang & IDate;
```

##### `type` ICommonGetStatisticsRang

Common fields for range statistics/export requests (combined with `IDate`, `IStartEndDay`, `StartEndMonth` to form concrete input types).

| Property | Type | Description |
| --- | --- | --- |
| `devId` | `string` | Device ID |
| `dpId` | `number \| string` | Data point ID (DP) to be aggregated |
| `type` | `"sum" \| "avg" \| "minux" \| "max" \| "min" \| "count" \| "recent"` | Statistic type; if omitted, each API has a default in `index` (mostly `sum`). Aggregation algorithm, aligned with minituya 'Statistic Type Description'. - `sum`: Sum of values reported within the interval; suitable for cumulative metrics. - `minux`: Current interval maximum minus previous interval maximum, representing increment/consumption (historical spelling, not `minus`). - `avg`: Sum divided by the number of reports to obtain the average. - `min` / `max`: Minimum / maximum within the interval. - `count`: Number of reports within the interval. - `recent`: Most recent statistic value. |
| `auto` | `number` | Data filling strategy, consistent with the cloud-side agreement; default is `0` for all APIs. Refer to the IoT platform’s Smart Metering/Open API specs for the exact enum values. |
| `keepScalaPoint` | `boolean` | When `true`, decimal places align with the device DP `scale`; default is `false`. |

##### `type` IDate

Single-day query: calendar day, format `yyyyMMdd` (used with 15-min/hour range APIs).

| Property | Type | Description |
| --- | --- | --- |
| `date` | `string` | Date to query, `yyyyMMdd`, e.g., `20230511` |


### Examples

#### Request example

```typescript
import { getStatisticsRangHour } from '@tuya-miniapp/cloud-api';

getStatisticsRangHour({
  devId: 'vdevo161733425146241',
  dpId: '18',
  date: '20230511',
  type: 'avg',
})
  .then((response) => {
    console.log(response);
  })
  .catch();
```

#### Response example

```json
{
  "2023051117": "0.00",
  "2023051118": "24.00",
  "2023051119": "0.00",
  "...": "..."
}
```
