---
name: "getSceneAndAuto"
mode: "api"
versionRequirements:
  - { name: "@tuya-miniapp/cloud-api", version: "1.1.0" }
---

## getSceneAndAuto

> [VERSION] @tuya-miniapp/cloud-api >= 1.1.0

> 💡 This API relies on cloud capabilities; configure authorization in the Mini App Developer Platform (https://platform.tuya.com/miniapp/) under Development Settings > Cloud Capabilities.

### Description

Get all scenes and automations for a device

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `devOrGroupId` | `string` | Yes | Device 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)

##### SceneAndAuto

| Property | Type | Description |
| --- | --- | --- |
| `autos` | `SceneOrAuto[]` | Automation list |
| `scenes` | `SceneOrAuto[]` | Tap-to-Run list |

### Referenced Types

##### `interface` SceneOrAuto

| Property | Type | Description |
| --- | --- | --- |
| `background` | `string` | Scene background |
| `displayColor` | `string` | Scene display color |
| `displayIcon` | `string` | Scene display icon |
| `enabled` | `boolean` | Whether the scene is enabled |
| `id` | `string` | Scene ID |
| `name` | `string` | Scene name |
| `sceneIcons` | `SceneIcon[]` | Scene icon list This field exists only for Auto automation; not available for Scene one-tap execution |

##### `type` SceneIcon

| Property | Type | Description |
| --- | --- | --- |
| `defaultIconName` | `string` | Default icon resource name |
| `isRemoved` | `boolean` | Whether it has been removed |
| `removeIconName` | `string` | Icon resource name for the remove state |
| `type` | `"action" \| "arrow" \| "condition"` | Icon semantics: action / arrow / condition |
| `url` | `string` | Icon URL |


### Examples

#### Request example

```typescript
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

```json
{
  "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.
