savePeakValleyPrice(params: SavePeakValleyPriceParams)

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

Description

Save the device’s peak–valley pricing configuration. Used to add or modify the pricing strategy for the specified device. Changes apply only to subsequent data; historical electricity cost data will not be recalculated.

Parameters

ParameterTypeRequiredDescription
YesRequest parameters

Return Value

Type: Promise<boolean>
Whether the save was successful

Examples

Request example

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

savePeakValleyPrice({
  devId: 'vdevo123',
  priceConfig: {
    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' },
    ],
  },
})
  .then(result => {
    console.log('Peak/valley pricing saved successfully:', result);
  })
  .catch(error => {
    console.error('Failed to save peak/valley pricing:', error);
  });

Response example

true

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.