Device Control
Update device parameters—turn on a light, adjust brightness, toggle a switch—from your app.
备注
userInstance — ESPRMUser from User sign in.
What This Module Does ?
Device control changes the state of physical hardware on a provisioned node. Each node has devices (e.g., lights, fans) with parameters (e.g., Power, Brightness) that you update via setValue().
Use this when you need to turn devices on/off, adjust settings, or use a device's primary control parameter.
Use Service Control for schedules, timezone, and other service parameters. Use Batch Operations to update multiple parameters or nodes at once.
Expected outcome: The SDK sends the update; if the node is online, the device state changes.
Common Workflows
Turn on a light
const { nodes } = await userInstance.getUserNodes();
const node = nodes[0];
const nodeConfig = node.nodeConfig ?? (await node.getNodeConfig());
const light = nodeConfig.devices.find((d) => d.type === "esp.device.light");
const powerParam = light.params.find((p) => p.name === "Power");
await powerParam.setValue(true);
Navigate the node hierarchy
- Get the node —
getUserNodes()orgetNodeDetails(nodeId) - Access
nodeConfig— on the node, orgetNodeConfig() - Find the device — by
nameortype(e.g.,"esp.device.light") - Find the parameter — by
nameortype(e.g.,"esp.param.power") - Call
setValue(newValue)
Use the primary parameter
const nodeConfig = node.nodeConfig ?? (await node.getNodeConfig());
const device = nodeConfig.devices[0];
const primaryParam = device.getPrimaryParam();
if (primaryParam) {
await primaryParam.setValue(true);
}
Find parameters by type
const powerParam = device.params.find((p) => p.type === "esp.param.power");
if (powerParam) {
await powerParam.setValue(true);
}

