On this page

previewLightScene(data: PreviewLightSceneParams)

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

Description

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

Parameters

ParameterTypeRequiredDescription
YesRequest 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)

Referenced Types

interfacePreviewLightSceneResult
PropertyTypeDescription
successActionsstring[]List of successfully executed actions
failActionsstring[]List of failed actions

Examples

Request example

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

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