getPeakValleyPrice(params: GetPeakValleyPriceParams)

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

描述

查询设备峰谷电价配置。返回指定设备当前的电价策略,包括电价类型、货币编码及完整电价配置对象。若设备未完成电价配置,priceType、currency 字段可能不存在。

参数

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

返回值

类型:Promise<GetPeakValleyPriceResult>
峰谷电价配置,含 priceType(电价类型:0 常规/1 阶梯/2 峰谷)、currency(货币编码)、config(电价配置,含 normalPrice 和 peakValleyPrice 列表)

引用对象

interfaceGetPeakValleyPriceResult
属性类型描述
priceTypePriceType电价类型
currencystring货币编码,如 `CNY`、`USD`
峰谷电价配置对象
enumPriceType
枚举值实际值描述
PriceType.Constant0常规电价
PriceType.Stage1阶梯电价
PriceType.Dynamic2峰谷电价
interfacePeakValleyPriceConfig
属性类型描述
normalPricestring常规(平段)电价,单位为货币/kWh
峰谷时段电价列表,为空数组时表示仅使用常规电价

示例代码

请求示例

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

getPeakValleyPrice({ devId: 'vdevo123' })
  .then(result => {
    console.log('电价类型:', result.priceType);
    console.log('常规电价:', result.config.normalPrice);
    result.config.peakValleyPrice.forEach(item => {
      console.log(`${item.startTime}:00 - ${item.endTime}:00, 单价: ${item.price}`);
    });
  })
  .catch(error => {
    console.error('查询峰谷电价失败:', error);
  });

返回示例

{
  "priceType": 2,
  "currency": "CNY",
  "config": {
    "normalPrice": "0.56",
    "peakValleyPrice": [
      { "startTime": "08", "endTime": "12", "price": "0.80" },
      { "startTime": "18", "endTime": "22", "price": "0.80" },
      { "startTime": "22", "endTime": "24", "price": "0.30" }
    ]
  }
}

常见问题

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

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