getDeviceCostBudget(params: GetDeviceCostBudgetParams)

版本要求:
@tuya-miniapp/cloud-api≥1.3.0

描述

查询设备电费预算列表。仅返回 energyAction 为 cost 的预算项,可用于在 UI 层展示预算进度或预算阈值告警。

参数

参数类型必填说明
是请求参数

返回值

类型:Promise<GetDeviceCostBudgetResult>
电费预算列表(energyAction 固定为 cost),每项含 dateType(预算维度:day/week/month)、budget(预算值,货币单位取决于设备配置,可通过 getDeviceCurrency 查询)、entityId(设备 ID)等字段

引用对象

typeGetDeviceCostBudgetResult`getDeviceCostBudget` 返回值,电费预算列表
export type GetDeviceCostBudgetResult = DeviceBudget[];
interfaceDeviceBudget
属性类型描述
bizIdstring业务 ID
budgetstring预算值,单位视 `energyAction` 而定(kWh 或货币)
dateTypeBudgetDataType预算时间维度
energyActionEnergyAction能源动作类型(`consume` 或 `cost`)
entityIdstring实体 ID(即设备 ID)
entityTypestring实体类型
projectIdstring项目 ID
projectTypestring项目类型
enumBudgetDataType
枚举值实际值描述
BudgetDataType.Dayday按天
BudgetDataType.Weekweek按周
BudgetDataType.Monthmonth按月
enumEnergyAction
枚举值实际值描述
EnergyAction.Costcost电费
EnergyAction.Consumeconsume用电量

示例代码

请求示例

import { getDeviceCostBudget } from '@tuya-miniapp/cloud-api';

getDeviceCostBudget({ devId: 'vdevo123' })
  .then(result => {
    result.forEach(item => {
      console.log(`${item.dateType} 电费预算: ${item.budget}`);
    });
  })
  .catch(error => {
    console.error('查询电费预算失败:', error);
  });

返回示例

[
  {
    "dateType": "day",
    "budget": "3",
    "energyAction": "cost",
    "bizId": "biz_003",
    "entityId": "vdevo123",
    "entityType": "device",
    "projectId": "proj_001",
    "projectType": "smartenergy"
  },
  {
    "dateType": "month",
    "budget": "50",
    "energyAction": "cost",
    "bizId": "biz_004",
    "entityId": "vdevo123",
    "entityType": "device",
    "projectId": "proj_001",
    "projectType": "smartenergy"
  }
]

常见问题

为什么调用云能力会出现失败的情况?

使用本接口前,请确保设备所属产品已在涂鸦 IoT 开发平台开启电量统计高级能力。未启用该能力的产品无法采集电量/电费数据,接口将返回空数据或报错。如需使用,请创建带有电量/电费统计功能的产品,并在产品详情中启用相应高级能力。同时,接口依赖云能力,需在小程序开发者平台开发设置 - 云能力进行授权配置。