跳到主要内容

ESPCDFAutomation

ESPCDFAutomation represents a rule that runs actions when node, weather, or daylight conditions match. Use it to enable, edit, or delete automations after they are created via ESPCDFGroup.createAutomation.

Automations live in AutomationStore. The synchronizer listens on operationsEvents (not events) — the only entity that uses this bus name.

Do not construct automations in UI code; adaptors return them from group operations.


Properties​

PropertyTypeDescription
id / namestringIdentity
enabledbooleanActive flag (updated by synchronizer)
eventTypetypednode, weather, or daylight
events / actionsarraysTrigger and action definitions
locationoptionalGeo for weather/daylight automations
operationsEventsESPCDFOperationEventEmitterSubscribe here for operation events
operationsESPCDFAutomationOperationSDK delegates
_rawanyOriginal SDK automation

Common Workflows​

Get an automation from the store​

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

const espCDF = await initCDF({ sdkAdaptorRegistry });
const automation = espCDF.automationStore.getAutomationById("auto-id");

Enable or disable​

await automation!.enable(true);
await automation!.enable(false);

// Or read local flag
const on = automation!.isEnabled();

Update definition​

await automation!.update({
name: "Night mode",
enabled: true,
events: [...],
actions: [...],
});

Delete​

await automation!.delete();
// AutomationStoreSynchronizer removes it from the store

Subscribe to operation events​

const unsubscribe = automation!.subscribe((entity, op, success, data, err) => {
if (!success) console.error(op, err);
});

// Clean up on unmount
unsubscribe();

Error Handling​

try {
await automation!.update({ enabled: false });
} catch (e) {
showErrorBanner("Could not update automation");
}

Failures re-throw and emit on operationsEvents so synchronizers can log without partial store patches.


Event types​

eventTypeTypical use
nodeTrigger on device param thresholds
weatherTrigger on weather conditions (needs location)
daylightSunrise/sunset style triggers

Filter automationStore.automationsList by eventType in UI when you need separate lists — the store exposes one combined list.


On this page