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

## previewLightScene

> [VERSION] @tuya-miniapp/cloud-api >= 1.2.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. Steps: find the Mini App Lighting Scene capability card, click the Authorize button at the bottom right of the card, and complete the authorization.

### Description

Preview the lighting scene effect based on the scene rule JSON data, and return the lists of actions that succeed and fail.

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `data` | `PreviewLightSceneParams` | Yes | Request parameters: ownerId (Home ID), previewExpr (preview scene JSON data that contains the complete scene configuration; see the documentation "previewExpr field description" for PreviewExprData field details) |

### Return Value

Type: `Promise<PreviewLightSceneResult>`

successActions (list of device IDs that executed successfully), failActions (list of device IDs that failed to execute)

##### PreviewLightSceneResult

| Property | Type | Description |
| --- | --- | --- |
| `successActions` | `string[]` | List of actions executed successfully |
| `failActions` | `string[]` | List of actions that failed to execute |

### Referenced Types

##### `interface` PreviewLightSceneParams

| Property | Type | Description |
| --- | --- | --- |
| `ownerId` | `string` | Home ID |
| `previewExpr` | `string` | Scene JSON data to preview (string serialized from a PreviewExprData object) |


### Examples

#### Request example

```typescript
import { previewLightScene } from '@tuya-miniapp/cloud-api';

const params = {
  ownerId: '214276111',
  previewExpr: JSON.stringify({
    actions: [
      {
        executorProperty: {
          switch_led: false,
        },
        actionExecutor: 'lightDevice',
      },
    ],
    parentRegionId: 65570551,
    originPercent: 0,
    targetPercent: 0,
    type: 2,
  }),
};

previewLightScene(params)
  .then(result => {
    console.log('Scene preview result:', result);
    console.log('Successful devices:', result.successActions);
    console.log('Failed devices:', result.failActions);
  })
  .catch(error => {
    console.error('Failed to preview scene:', error);
  });
```

#### Response example

```json
{
  "successActions": ["6c4003f3231bb36d40q123", "6c135cd26c3fcab5862456"],
  "failActions": ["6c9fb53eqkzdw123", "6c7d2bgchtp9x345"]
}
```


### Additional notes

1. The `previewExpr` parameter is a JSON string. Build a JavaScript object first, then convert it with `JSON.stringify()`.
2. The preview API does not actually run the scene; it only validates configuration correctness and device availability.
3. The returned `successActions` and `failActions` arrays contain device IDs, indicating which devices are configured correctly and which may need adjustment.
4. If all devices are configured correctly, `failActions` will be an empty array.
