On this page

getSceneAndAuto(devOrGroupId: string)

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

Description

Get all scenes and automations for a device

Parameters

ParameterTypeRequiredDescription
devOrGroupIdstringYesDevice ID or group ID, used to query all scenes and automations associated with the device or group

Return Value

Type: Promise<SceneAndAuto>
SceneAndAuto (autos is the automation list, scenes is the Tap-to-Run list; see the type definitions and minituya return parameters for field meanings)

Referenced Types

typeSceneAndAuto
PropertyTypeDescription
autosSceneOrAuto[]Automation list
scenesSceneOrAuto[]Tap-to-Run list

Examples

Request example

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

getSceneAndAuto('device_id_123456')
  .then(response => {
    console.log('Automation list:', response.autos);
    console.log('Tap-to-Run list:', response.scenes);
  })
  .catch(error => {
    console.error('Failed to get scene and auto:', error);
  });

Response example

{
  "autos": [
    {
      "background": "#FF5722",
      "displayColor": "#FF5722",
      "displayIcon": "https://example.com/icon.png",
      "enabled": true,
      "id": "auto_123",
      "name": "Turn on lights automatically",
      "sceneIcons": [
        {
          "defaultIconName": "condition_icon",
          "isRemoved": false,
          "removeIconName": "",
          "type": "condition",
          "url": "https://example.com/condition_icon.png"
        },
        {
          "defaultIconName": "arrow_icon",
          "isRemoved": false,
          "removeIconName": "",
          "type": "arrow",
          "url": "https://example.com/arrow_icon.png"
        },
        {
          "defaultIconName": "action_icon",
          "isRemoved": false,
          "removeIconName": "",
          "type": "action",
          "url": "https://example.com/action_icon.png"
        }
      ]
    }
  ],
  "scenes": [
    {
      "displayColor": "#4CAF50",
      "displayIcon": "https://example.com/scene_icon.png",
      "enabled": true,
      "id": "scene_456",
      "name": "Home Mode"
    }
  ]
}

Additional notes

  1. Concepts:

    • autos (automations): include trigger conditions and actions; they run automatically when conditions are met. Automations include the sceneIcons field.
    • scenes (one-tap scenes): run manually when tapped; they have no trigger conditions. One-tap scenes do not include the sceneIcons field.
  2. Parameters:

    • devOrGroupId accepts a device ID or group ID and returns all scenes and automations related to that device or group.
    • The API separates automations and one-tap scenes into the autos and scenes fields.
  3. Errors:

    • If devOrGroupId is empty or invalid, the API throws: "getSceneAndAuto failed: devId or groupId is null!".
    • Errors are normalized internally; use .catch() to handle failures.