getDeviceCostBudget(params: GetDeviceCostBudgetParams)

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

Query the device electricity cost budget list. Only budget items with energyAction set to cost are returned. Can be used to display budget progress or threshold alerts in the UI.

Parameters

ParameterTypeRequiredDescription
YesRequest parameters

Return Value

Type: Promise<GetDeviceCostBudgetResult>
Electricity cost budget list (energyAction is fixed to cost). Each item includes dateType (budget dimension: day/week/month), budget (budget value; currency depends on the device configuration and can be queried via getDeviceCurrency), entityId (device ID), etc.

Referenced Types

typeGetDeviceCostBudgetResult`getDeviceCostBudget` return value, electricity cost budget list
export type GetDeviceCostBudgetResult = DeviceBudget[];
interfaceDeviceBudget
PropertyTypeDescription
bizIdstringBusiness ID
budgetstringBudget value; unit depends on `energyAction` (kWh or currency)
dateTypeBudgetDataTypeBudget time dimension
energyActionEnergyActionEnergy action type (`consume` or `cost`)
entityIdstringEntity ID (i.e., device ID)
entityTypestringEntity type
projectIdstringProject ID
projectTypestringProject type
enumBudgetDataType
ValueActual ValueDescription
BudgetDataType.DaydayDaily
BudgetDataType.WeekweekWeekly
BudgetDataType.MonthmonthMonthly
enumEnergyAction
ValueActual ValueDescription
EnergyAction.CostcostElectricity cost
EnergyAction.ConsumeconsumeElectricity consumption

Examples

Request example

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

getDeviceCostBudget({ devId: 'vdevo123' })
  .then(result => {
    result.forEach(item => {
      console.log(`${item.dateType} electricity cost budget: ${item.budget}`);
    });
  })
  .catch(error => {
    console.error('Failed to query cost budget:', error);
  });

Response example

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

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.