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

## getStatisticsRangMonth

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

> 💡 该接口为云能力，需开通授权后使用，关于云能力可[查看文档](/cn/miniapp/common/desc/tech-stack/api)。
> 注意：目前云能力在「开发者工具」环境无法使用，需要打包后或真机调试使用。

### 描述

月为时间间隔，获取设备日期区间的统计数据。

### 参数

`Params`

| 参数 | 类型 | 必填 | 默认值 | 描述 |
| --- | --- | --- | --- | --- |
| `data` | `IGetStatisticsRangMonth` | 是 | - | 请求体 |

### 引用对象

##### `type` IGetStatisticsRangMonth

按月查询区间统计：公共字段 + 起止月。

```typescript
export type IGetStatisticsRangMonth = ICommonGetStatisticsRang & StartEndMonth;
```

##### `type` ICommonGetStatisticsRang

区间统计/导出请求的公共字段（与 `IDate`、`IStartEndDay`、`StartEndMonth` 组合成具体入参类型）。

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `devId` | `string` | 设备 ID |
| `dpId` | `number \| string` | 要统计的数据点 ID（DP） |
| `type` | `"sum" \| "avg" \| "minux" \| "max" \| "min" \| "count" \| "recent"` | 统计类型；不传时各接口在 `index` 中有默认（多为 `sum`）。 统计聚合算法，与 minituya「统计类型说明」一致。 - `sum`：时段内上报值累加，适用于累计量。 - `minux`：本时段最大值减去上一时段最大值，表示增量/用量（历史拼写，非 `minus`）。 - `avg`：累加后除以上报次数，得平均值。 - `min` / `max`：时段内最小值 / 最大值。 - `count`：时段内上报次数。 - `recent`：最近一次统计值。 |
| `auto` | `number` | 数据填充策略，与云端约定一致；各接口默认 `0`。 具体枚举以 IoT 平台智能计量/开放接口说明为准。 |
| `keepScalaPoint` | `boolean` | 为 `true` 时小数位数与设备 DP 的 `scale` 对齐；默认 `false`。 |

##### `type` StartEndMonth

按「月」为粒度的一段月份区间（用于 `getStatisticsRangMonth` / `exportStatisticsMonth`）。

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `startMonth` | `string` | 开始月份，`yyyyMM`，例如 `202304` |
| `endMonth` | `string` | 结束月份，`yyyyMM` |


### 示例代码

#### 请求示例

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

getStatisticsRangMonth({
  devId: 'vdevo161733425146241',
  dpId: '18',
  startMonth: '202304',
  endMonth: '202305',
  type: 'avg',
})
  .then((response) => {
    console.log(response);
  })
  .catch();
```

#### 返回示例

```json
{
  "202304": "0",
  "202305": "24.00"
}
```
