跳到主要内容

ESPCDFScene

ESPCDFScene is a named preset that applies device params across one or more nodes in a single call. Use it when you implement scene feature.

Scenes are created with group.createScene and stored in SceneStore. Read them with sceneStore.getScene or sceneStore.sceneList.

Constructor requires id and name. Mutations use runAndEmit; SceneStoreSynchronizer keeps the store in sync.


Properties​

PropertyTypeDescription
id / namestringRequired identity
nodesstring[]Participating node IDs
actionsnested mapPer-node device actions
devicesCountnumberUI helper count
adaptorIdentifieroptionalSource adaptor
operationsESPCDFSceneOperationSDK delegates
_rawanyOriginal SDK scene
eventsESPCDFOperationEventEmitterOperation bus

Common Workflows​

Get a scene from the store​

import { initCDF } from "@espressif/rainmaker-base-cdf";

const espCDF = await initCDF({ sdkAdaptorRegistry });
const scene = espCDF.sceneStore.getScene("scene-id");

Activate a scene​

Applies all actions on member nodes:

await scene!.activate();

You can also activate via the store:

await espCDF.sceneStore.activateScene("scene-id");

Rename a scene​

await scene!.edit({ name: "Chill Night" });

Delete a scene​

await scene!.remove();

Create via group (typical path)​

const group = espCDF.groupStore.getGroupById("group-id")!;
const capable = await group.getSceneCapableDevices();

const newScene = await group.createScene({
id: "scene-evening",
name: "Evening",
nodes: ["node-1"],
actions: { "node-1": { Light: { Power: true, Brightness: 50 } } },
});

Error Handling​

try {
await scene!.activate();
} catch (e) {
showErrorBanner("Scene activation failed");
}

Actions shape​

actions is a nested map: node id → device name → param payload:

actions: {
"node-1": { Light: { Power: true, Brightness: 80 } },
"node-2": { Fan: { Speed: 2 } },
}

On this page