跳到主要内容

Batch Operations

Update parameters across multiple nodes in a single API call.

备注

userInstance — ESPRMUser from User sign in.

提示

Use batch operations instead of individual setValue() calls when updating several parameters or nodes at once.

What This Module Does ?​

Send one request to update device and service parameters on multiple nodes—more efficient than per-parameter setValue() loops.

Use userInstance.setMultipleNodesParams() for multiple nodes (this page). Use node.setMultipleParams() for one node — Node Management. Use param.setValue() for a single parameter — Device Control.

Expected outcome: All listed nodes receive their updates in one API call.

Common Workflows​

Turn off lights in multiple rooms​

const payload = [
{ nodeId: "node_living_room", payload: { Light: { Power: false } } },
{ nodeId: "node_bedroom", payload: { Light: { Power: false } } },
];

await userInstance.setMultipleNodesParams(payload);

Update device and service params together​

await userInstance.setMultipleNodesParams([
{
nodeId: "node_id_1",
payload: {
Light: { Power: true, Brightness: 80 },
Time: { TZ: "America/Los_Angeles" },
},
},
]);

Build payload dynamically​

const payload = selectedNodeIds.map((nodeId) => ({
nodeId,
payload: { Light: { Power: true } },
}));

await userInstance.setMultipleNodesParams(payload);

Scene: all lights on​

const { nodes } = await userInstance.getUserNodes();
const payload = nodes.map((node) => ({
nodeId: node.id,
payload: { Light: { Power: true, Brightness: 100 } },
}));

await userInstance.setMultipleNodesParams(payload);

Error Handling​

try {
await userInstance.setMultipleNodesParams(payload);
} catch (error) {
console.error("Batch update failed:", error);
}

Validate nodeId and device/service names against node config before sending.

Advanced Concepts​

Payload shape​

Each entry is { nodeId, payload }. Keys in payload are device or service names; values are parameter maps. Device and service params can be mixed:

{
nodeId: "node_id",
payload: {
Light: { Power: true, Brightness: 80 },
Time: { TZ: "America/Los_Angeles" },
},
}

Mental model​

For each node, here's what to change — one array entry per node.

Best Practices​

  1. Prefer batch over loops
  2. Match payload names to node config exactly
  3. Use for scenes and bulk actions
  4. Build payloads from getUserNodes()

On this page