跳到主要内容

ESPCDFSchedule

ESPCDFSchedule runs device actions on a time-based trigger. Use it for recurring routines such as morning lights or weekday shutdowns.

Schedules are created with group.createSchedule and stored in ScheduleStore. Access via scheduleStore.getScheduleById or scheduleStore.schedulesList.

The constructor requires id, name, at least one trigger, and a non-empty action map.


Properties

PropertyTypeDescription
id / namestringRequired identity
triggersESPCDFScheduleTrigger[]When the schedule runs
actionESPCDFScheduleActionPer-node device payloads
enabledoptionalActive flag
outOfSyncMetaoptionalClient sync hints per node
operationsESPCDFScheduleOperationSDK delegates
_rawanyOriginal SDK schedule
eventsESPCDFOperationEventEmitterOperation bus

Common Workflows

Get a schedule from the store

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

const espCDF = await initCDF({ sdkAdaptorRegistry });
const schedule = espCDF.scheduleStore.getScheduleById("schedule-id");

Enable and disable

await schedule!.enable();
await schedule!.disable();

const active = schedule!.isEnabled();

Edit a schedule

await schedule!.edit({
name: "Updated routine",
triggers: [{ m: 480, d: 127 }], // 08:00 daily
action: { "node-1": { Light: { Power: true, Brightness: 70 } } },
});

Delete a schedule

await schedule!.remove();

Create via group

const group = espCDF.groupStore.getGroupById("group-id")!;
await group.getScheduleCapableDevices();

const schedule = await group.createSchedule({
id: "sch-morning",
name: "Morning",
nodes: ["node-1"],
triggers: [{ m: 420, d: 127 }], // 07:00 every day
action: { "node-1": { Light: { Power: true } } },
enabled: true,
});

Error Handling

try {
await schedule!.edit({ name: "Weekend only", triggers: [{ m: 600, d: 65 }] });
} catch (e) {
showErrorBanner("Schedule update failed");
}


On this page