Skip to main content

Automation

Create triggers that automatically execute actions when device conditions are met.

note

The userInstance refers to ESPRMUser from User Sign in.

What This Module Does ?

Automations link events (conditions) to actions (parameter changes on nodes). When a trigger fires—motion, brightness, sunrise, weather—the SDK runs the configured actions.

TypeAPI
Node-level (device params)node.addAutomation()
Daylight (sunrise/sunset)userInstance.addDaylightBasedAutomation()
WeatheruserInstance.addWeatherBasedAutomation()

Manage existing automations in Automation Management.

Expected outcome: A new automation is created and runs when its conditions match.

Common Workflows

Motion triggers light

const automation = await node.addAutomation({
name: "Motion → Light",
events: [{ params: { Motion: { Motion: true } }, check: "==" }],
eventOperator: "and",
actions: [
{
node_id: "target_node_id",
params: { Light: { Power: true, Brightness: 80 } },
},
],
retrigger: false,
});

Multiple events (AND)

await node.addAutomation({
name: "Low light + motion",
events: [
{ params: { Light: { Brightness: 30 } }, check: "<=" },
{ params: { Motion: { Motion: true } }, check: "==" },
],
eventOperator: "and",
actions: [{ node_id: "node_id", params: { Light: { Power: true } } }],
retrigger: false,
});

List automations on a node

const automations = await node.getAutomations();

Daylight automation (sunrise)

await userInstance.setGeoCoordinates({
latitude: 37.7749,
longitude: -122.4194,
});

await userInstance.addDaylightBasedAutomation({
name: "Sunrise lights",
eventType: "sunrise",
offsetMinutes: 0,
actions: [
{ nodeId: "node_id", deviceName: "Light", params: { Power: true } },
],
});

Weather automation (rain)

await userInstance.addWeatherBasedAutomation({
name: "Close blinds when raining",
eventType: "rain",
actions: [
{ nodeId: "node_id", deviceName: "Blinds", params: { Power: false } },
],
});

Error Handling

try {
await node.addAutomation(automationDetails);
} catch (error) {
console.error("Failed to create automation:", error);
}

Match event parameter names to node config and ensure action node_id values exist.

Advanced Concepts

Mental model

When X happens → do Y on one or more nodes.

Event and action structure

  • Events watch parameter values on the source node; actions can target other nodes
  • eventOperator is "and" or "or" for multiple events
  • retrigger controls whether the automation can fire again while active
  • Daylight and weather automations need setGeoCoordinates() first

Best Practices

  1. Set geo coordinates before daylight/weather automations
  2. Use clear automation names in management UI
  3. Start with retrigger: false
  4. Test one event before combining many
  5. Use Automation Management for edits after creation

On this page