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);
}
Error Handling
try {
const { nodes } = await userInstance.getUserNodes();
const node = nodes.find((n) => n.id === targetNodeId);
if (!node) return;
const nodeConfig = node.nodeConfig ?? (await node.getNodeConfig());
const device = nodeConfig.devices.find((d) => d.type === "esp.device.light");
const param = device?.params.find((p) => p.name === "Power");
if (!param) return;
await param.setValue(true);
} catch (error) {
console.error("Failed to update device parameter:", error);
}
Guard each hierarchy step—nodes, devices, and parameters may not exist for every account or firmware.
Advanced Concepts
Mental model
Find the parameter → set its value → the device responds.
How updates reach the device
With local transport configured, the SDK may route updates directly when the node is on the same network.
Parameter value types
Values match the RainMaker parameter type—booleans for power, numbers for brightness, strings for modes. The SDK handles serialization.
Best Practices
- Cache node config when building control UI
- Use
getPrimaryParam()for the main toggle - Match by
typewhen parameter names differ across models - Subscribe to node updates — see Events and Subscriptions
- Batch related changes with
setMultipleParams()— see Node Management
Related Resource
- API Reference: