getPeakValleyPrice(params: GetPeakValleyPriceParams)

Requires:
@tuya-miniapp/cloud-api≥1.3.0

Description

Query the device’s peak–valley pricing configuration. Returns the device’s current pricing strategy, including priceType, currency, and the complete pricing configuration object. If pricing is not configured for the device, the priceType and currency fields may be absent.

Parameters

ParameterTypeRequiredDescription
YesRequest parameters

Return Value

Type: Promise<GetPeakValleyPriceResult>
Peak–valley pricing configuration, including priceType (pricing type: 0 normal / 1 tiered / 2 peak–valley), currency (currency code), and config (pricing config containing normalPrice and the peakValleyPrice list).

Referenced Types

interfaceGetPeakValleyPriceResult
PropertyTypeDescription
priceTypePriceTypeElectricity price type
currencystringCurrency code, e.g., `CNY`, `USD`
Peak-valley pricing configuration object
enumPriceType
ValueActual ValueDescription
PriceType.Constant0Standard electricity price
PriceType.Stage1Tiered electricity price
PriceType.Dynamic2Peak-valley electricity price
interfacePeakValleyPriceConfig
PropertyTypeDescription
normalPricestringFlat (standard) tariff, unit: currency/kWh
List of peak/valley period tariffs; an empty array indicates that only the flat tariff is used

Examples

Request example

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

getPeakValleyPrice({ devId: 'vdevo123' })
  .then(result => {
    console.log('Price type:', result.priceType);
    console.log('Normal price:', result.config.normalPrice);
    result.config.peakValleyPrice.forEach(item => {
      console.log(`${item.startTime}:00 - ${item.endTime}:00, Unit price: ${item.price}`);
    });
  })
  .catch(error => {
    console.error('Failed to query peak/valley pricing:', error);
  });

Response example

{
  "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" }
    ]
  }
}

FAQ

Why does the call to cloud capabilities fail?

Before using this API, please ensure that the product to which the device belongs has enabled the Electricity Statistics advanced capability on the Tuya IoT Development Platform. Products without this capability enabled cannot collect electricity consumption/cost data, and the API will return empty data or an error. If you need to use it, please create a product with electricity consumption/cost statistics functions and enable the corresponding advanced capabilities in the product details. At the same time, the API depends on cloud capabilities, and authorization configuration is required in Development Settings - Cloud Capabilities on the Mini Program Developer Platform.