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

## saveLightScene

> [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

Create, edit, and save a lighting scene. This API saves the rule configuration of a lighting scene, including scene name, icon, execution actions, and other information.

### Parameters

`Params`

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

### Return Value

Type: `Promise<SaveLightSceneResult>`

Scene info after saving (includes id, code, name, parentRegionId, ownerId, icon, enabled, status, sceneType, etc.; see the Return Parameters table in the documentation for details)

### Referenced Types

##### `interface` SaveLightSceneParams

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `ownerId` | `string` | Yes | Home ID |
| `sceneExpr` | `string` | Yes | Scene rule JSON data (string serialized from a SaveExprData object) |


### Examples

#### Request example

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

const params = {
  ownerId: '194137',
  sceneExpr: JSON.stringify({
    actions: [
      {
        actionExecutor: 'lightDevice',
        entityId: 'vdevo176127325226099',
        entityName: 'Debug - Step Dimming - vdevo',
        executorProperty: {
          switch_led: true,
          work_mode: 'scene',
          smb_scene: '0132010100000000000003e80000320101000000000000000a0000',
        },
        extraProperty: {
          parentRegionId: '57939115',
          sceneName: '500 ms fade (warm light)',
          sceneId: '22304912',
          sceneType: 1,
          selectCellBackground: 'https://images.tuyacn.com/light/library/icon/img_scene.png',
        },
      },
    ],
    parentRegionId: 57939115,
    name: '500 ms fade (warm light)',
    displayColor: 'BA7B69',
    sceneType: 3,
    matchType: 1,
    icon: 'https://images.tuyacn.com/smart/rule/light/dianji_default.png',
  }),
};

saveLightScene(params)
  .then(result => {
    console.log('Scene saved successfully:', result);
  })
  .catch(error => {
    console.error('Failed to save scene:', error);
  });
```

#### Response example

```json
{
  "id": 123456,
  "code": "light_scene_001",
  "name": "500 ms fade (warm light)",
  "parentRegionId": "57939115",
  "ownerId": "194137",
  "uid": "ay1234567890",
  "icon": "https://images.tuyacn.com/smart/rule/light/dianji_default.png",
  "enabled": 1,
  "status": 1,
  "sort": 1,
  "sceneType": 3,
  "displayColor": "BA7B69",
  "matchType": 1,
  "gmtCreate": 1766558627585,
  "gmtModified": 1766558627585
}
```


### Additional notes

1. The `sceneExpr` parameter is a complex JSON string. Build a JavaScript object first, then convert it with `JSON.stringify()`.
2. Some fields in the response are optional; the actual payload may vary depending on scene type and configuration.
