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

## previewLightScene

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

> 💡 接口依赖云能力，需在 [小程序开发者平台](https://platform.tuya.com/miniapp/)开发设置 - 云能力 进行授权配置, 具体操作: 找到 小程序照明场景能力 卡片, 点击卡片右下角 授权 按钮, 完成该云能力授权。

### 描述

根据场景规则 JSON 数据，预览照明场景效果，返回执行成功和失败的动作列表。

### 参数

`Params`

| 参数 | 类型 | 必填 | 默认值 | 描述 |
| --- | --- | --- | --- | --- |
| `data` | `PreviewLightSceneParams` | 是 | - | 请求参数：ownerId（家庭 ID）、previewExpr（预览的场景 JSON 数据，包含场景的完整配置信息；PreviewExprData 字段说明见文档「previewExpr 字段说明」） |

### 引用对象

##### `interface` PreviewLightSceneParams

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `ownerId` | `string` | 家庭 ID |
| `previewExpr` | `string` | 预览的场景 JSON 数据（PreviewExprData 对象序列化后的字符串） |


### 示例代码

#### 请求示例

```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('场景预览结果:', result);
    console.log('成功的设备:', result.successActions);
    console.log('失败的设备:', result.failActions);
  })
  .catch(error => {
    console.error('场景预览失败:', error);
  });
```

#### 返回示例

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