batchSaveCostBudget(params: BatchSaveCostBudgetParams)

Requires:
@tuya-miniapp/cloud-api≥1.3.0
Additional notesRead the full notes
This API relies on cloud capabilities. You must grant authorization in Development Settings - Cloud Capabilities on the Mini App Developer Platform. Before using this API, ensure the device’s product has enabled the **Energy Statistics** advanced capability on the Tuya IoT Development Platform. Products without this capability cannot collect energy consumption/cost data; the API will return empty data or an error. To use this feature, create a product with energy consumption/cost statistics and enable the corresponding advanced capability in the product details.

Description

Batch save device electricity cost budgets. Supports updating cost budgets for multiple time dimensions (day/week/month) in one call; dimensions not provided will not be reset.

Parameters

ParameterTypeRequiredDescription
YesRequest parameters

Return Value

Type: Promise<boolean>
Whether the save succeeded

Referenced Types

enumBudgetDataType
ValueActual ValueDescription
BudgetDataType.DaydayDaily
BudgetDataType.WeekweekWeekly
BudgetDataType.MonthmonthMonthly

Valid Values

BudgetDataType
ValueDescriptionSince
dayDaily-
weekWeekly-
monthMonthly-

Examples

Request example

import { batchSaveCostBudget, BudgetDataType } from '@tuya-miniapp/cloud-api';

batchSaveCostBudget({
  devId: 'vdevo123',
  budgetConfig: [
    { dateType: BudgetDataType.Day, budget: '3' },
    { dateType: BudgetDataType.Week, budget: '15' },
    { dateType: BudgetDataType.Month, budget: '50' },
  ],
})
  .then(result => {
    console.log('Cost budget saved successfully:', result);
  })
  .catch(error => {
    console.error('Failed to save cost budget:', 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.