Scheduled Tasks

Last Updated on : 2026-02-05 03:17:42download

SmartLife App SDK provides basic capabilities to manage scheduled tasks. For example, set scheduled tasks for devices and groups. Supported types of devices include Wi-Fi devices, Bluetooth mesh sub-devices, and Zigbee sub-devices. This SDK encapsulates the API methods to query, add, modify, or delete timers for data points (DPs). The app can be used to set timers based on specific scheduled task API calls. Then, network modules will automatically run predefined tasks.

Functional description

  • Encapsulation class

    Class name Description
    TSmartTimer Encapsulates API methods for scheduled tasks.
  • Multiple API methods require the taskName parameter. It can be regarded as a group of timers. Each timer belongs to at most one group. A group is only used for display. Example:

    • A switch might support multiple DPs. A group of timers can be created for each DP.

    • Multiple timers can be added to each group to control the switch status of the DP in different periods.

      A scheduled task can include multiple timers. It is shown as follows:
      Scheduled Tasks

Add a scheduled task

Adds a timer to a specified scheduled task specified by task for a device or group. The maximum number of timers allowed for each device or group is 30.

API description

export class TSmartTimer {
  public static async addTimer(params: TSmartTimerParams): Promise<number>
}

Parameters

Parameter Description Optional or not
params Parameters required when adding a scheduled task. Required

TSmartTimerParams

Parameter Description
task The name of the scheduled task.
loops The way the scheduled task is repeated. Format: 0000000. Valid values of each digit:
  • 0: disabled
  • 1: enabled
The digits represent Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday sequentially from left to right. For example, if the schedule repeats every Monday, the value is set to 0100000.
bizId The ID of the device or group.
bizType
  • 0: individual device
  • 1: group of devices
time The scheduled time. Example: 18:00.
dps The list of DPs to be sent.
status Specifies whether to enable the timer.
isAppPush Specifies whether to enable push notifications.
aliasName The remarks.

Sample code

TSmartTimer.addTimer({
  task: 'timer_task_name',
  loops: '1111111',
  bizId: this.device?.devId ?? "",
  bizType: 0,
  time: "14:29",
  dps: {"20": true},
  status: true,
  isAppPush: false,
  aliasName: 'timer_task_aliasName'
})

Update a schedule

API description

export class TSmartTimer {
	public static async updateTimer(params: TSmartTimerParams): Promise<void>
}

Parameters

Parameter Description Optional or not
params Parameters required when updating a scheduled task. Required

TSmartTimerParams

Parameter Type Description
task string The name of the scheduled task.
loops string The way the scheduled task is repeated.
bizId string The ID of the device or group.
bizType number The business type. Valid values:
  • 0: individual device
  • 1: group of devices
time string The scheduled time.
dps Record<string, Object> The DP triggered when the schedule runs.
status boolean The schedule status. Valid values:
  • true: enabled
  • false: disabled
isAppPush boolean Specifies whether to notify the user of the schedule execution result via the app. Valid values:
  • true: yes
  • false: no
aliasName string The alias name of the schedule.

Sample code

TSmartTimer.updateTimer({
  task: 'timer_task_name',
  loops: '0111111',
  bizId: this.device?.devId ?? "",
  bizType: 0,
  time: "14:29",
  dps: {"20": true},
  status: true,
  isAppPush: false,
  aliasName: 'timer_task_aliasName'
})

Update the status of a schedule

API description

export class TSmartTimer {
	public static async updateTimerTaskStatus(task: string, bizId: string, bizType: number, updateType: number): Promise<void>
}

Parameters

Parameter Description Optional or not
task The name of the scheduled task. Required
bizId The ID of the device or group. Required
bizType The business type. Valid values:
  • 0: individual device
  • 1: group of devices
Required
updateType The schedule status. Valid values:
  • 1: enabled
  • 0: disabled
Required

Sample code

await TSmartTimer.updateTimerTaskStatus("timer_task_name", this.device?.devId ?? "", 0, 1)

Delete a timer

API description

export class TSmartTimer {
  public static async removeTimer(timerId: string, bizId: string, bizType: number): Promise<void>;
}

Parameters

Parameter Description Optional or not
timerId The ID of a specified scheduled task. Required
bizId The ID of the device or group. Required
bizType The business type. Valid values:
  • 0: individual device
  • 1: group of devices
Required

Sample code

TSmartTimer.removeTimer("111", this.device?.devId ?? "", 0)

Query a scheduled task

API description

export class TSmartTimer {
  public static async getTimerList(task: string, bizId: string, bizType:number): Promise<TSmartTimerModel[]>
}

Parameters

Parameter Description Optional or not
task The name of the scheduled task. Required
bizId The ID of the device or group. Required
bizType The business type. Valid values:
  • 0: individual device
  • 1: group of devices
Required

Sample code

const res = await TSmartTimer.getTimerList("timer_task_name", this.device?.devId!, 0)
console.log("timer res - :" + res)

Query all scheduled tasks for a device

API description

export class TSmartTimer {
	public static async getTimerTaskList(bizId: string, bizType: number): Promise<TSmartCategoryTimersModel[]>
}

Parameters

Parameter Description Optional or not
task The name of the scheduled task. Required
bizId The ID of the device or group. Required
bizType The business type. Valid values:
  • 0: individual device
  • 1: group of devices
Required

Sample code

const res = await TSmartTimer.getTimerTaskList(this.device?.devId!, 0)
console.log("timer res - :" + res)