Last Updated on : 2024-11-18 11:33:13
Smart Life 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.
Encapsulation class
Class name | Description |
---|---|
ITuyaCommonTimer | 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. The following figure shows the architecture of the device, scheduled tasks, and timers.
To fix certain known issues, the API methods for scheduled tasks mentioned in this topic are added to SDK v3.18.0 and later.
TuyaHomeSdk.getTimerInstance()
.TuyaHomeSdk.getTimerManagerInstance()
.Compared with the earlier API methods, the latest API methods support the following new features:
The earlier API methods for scheduled tasks will no longer be maintained. We recommend that you update to the latest API methods. During the update, all API methods for scheduled tasks are replaced. To improve compatibility, the list of timers created with earlier API methods can still be queried with the latest API methods.
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
void addTimer(TuyaTimerBuilder builder, final IResultCallback callback);
Parameters
Parameters of TuyaTimerBuilder
and IResultCallback
Parameter | Description |
---|---|
taskName | The name of the timer group. |
devId | The device ID or group ID. |
loops | The way the scheduled task is repeated. Format: 0000000 . Valid values of each digit:
0100000 . 0000000 represents that the scheduled task repeats only once. 1111111 represents that the scheduled task repeats every day. |
actions | The scheduled tasks in the JSON format assigned to DPs. Format: {"dps":{}, "time":""} . For DPs of Raw type, you must convert the format by using new String(Base64.encodeBase64(HexUtil.hexStringToBytes(dps))) . |
status | Initializes the status of the timer switch. Valid values:
|
appPush | Specifies whether to send a push notification of the scheduled task result. |
aliasName | The alias of the scheduled task. |
TimerDeviceTypeEnum | The target for which the scheduled task runs. Valid values:
|
callback | The success or failure callback. null cannot be returned. |
Example
TuyaTimerBuilder builder = new TuyaTimerBuilder.Builder()
.taskName(mTaskName)
.devId("efw9990wedsew")
.deviceType(TimerDeviceTypeEnum.DEVICE)
.actions(dps)
.loops("1100011")
.aliasName("Test")
.status(1)
.appPush(true)
.build();
TuyaHomeSdk.getTimerInstance().addTimer(builder, new IResultCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(String errorCode, String errorMsg) {
}
});
API description
void updateTimerStatus(String devId, TimerDeviceTypeEnum deviceTimerTypeEnum, List<String> ids, TimerUpdateEnum timerUpdateEnum, final IResultCallback callback);
Parameters
Parameter | Description |
---|---|
devId | The device ID or group ID. |
TimerDeviceTypeEnum | The target for which the scheduled task runs. Valid values:
|
ids | The list of timer IDs. |
TimerUpdateEnum | The type of operation. Valid values:
|
callback | The success or failure callback. null cannot be returned. |
Example
List<String> list = new ArrayList<>();
list.add("111");
TuyaHomeSdk.getTimerInstance().updateTimerStatus(mDevId, TimerDeviceTypeEnum.DEVICE, list, TimerUpdateEnum.DELETE, new IResultCallback() {
@Override
public void onError(String code, String error) {
}
@Override
public void onSuccess() {
}
});
API description
Updates the timer information of a scheduled task for a device or group.
void updateTimer(TuyaTimerBuilder builder, final IResultCallback callback);
Parameters
Parameters of TuyaTimerBuilder
and IResultCallback
Parameter | Description |
---|---|
taskName | The name of the timer group. |
devId | The device ID or group ID. |
loops | The way the scheduled task is repeated. Format: 0000000 . Valid values of each digit:
0100000 . 0000000 represents that the scheduled task repeats only once. 1111111 represents that the scheduled task repeats every day. |
actions | The scheduled tasks in the JSON format assigned to DPs. Format: {"dps":{}, "time":""} . For DPs of Raw type, you must convert the format by using new String(Base64.encodeBase64(HexUtil.hexStringToBytes(dps))) . |
status | Initializes the status of the timer switch. Valid values:
|
appPush | Specifies whether to send a push notification of the scheduled task result. |
aliasName | The alias of the scheduled task. |
TimerDeviceTypeEnum | The target for which the scheduled task runs. Valid values:
|
callback | The success or failure callback. null cannot be returned. |
Example
TuyaTimerBuilder builder = new TuyaTimerBuilder.Builder()
.timerId("1204923")
.devId(groupId+"")
.deviceType(TimerDeviceTypeEnum.GROUP)
.actions(dps)
.loops("0000000")
.aliasName("test")
.status(1)
.appPush(true)
.build();
TuyaHomeSdk.getTimerInstance().updateTimer(builder, new IResultCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(String errorCode, String errorMsg) {
}
});
API description
Returns all timers of a scheduled task for a device or group.
void getTimerList(String taskName, String devId, TimerDeviceTypeEnum deviceTimerTypeEnum, final ITuyaDataCallback<TimerTask> callback);
Parameters
Parameter | Description |
---|---|
taskname | The name of the timer group. If this parameter is empty, common timers are queried. |
devId | The device ID or group ID. |
TimerDeviceTypeEnum | The target for which the scheduled task runs. Valid values:
|
callback | The success or failure callback. null cannot be returned. |
Parameters of TimerTask
Parameter | Description |
---|---|
TimerTaskStatus | The switch status and name of a timer. |
ArrayList |
The list of timers. |
category | The category of the timer group. |
Example
TuyaHomeSdk.getTimerInstance().getTimerList(null, mGwId, TimerDeviceTypeEnum.DEVICE, new ITuyaDataCallback<TimerTask>() {
@Override
public void onSuccess(TimerTask timerTask){
}
@Override
public void onError(String errorCode, String errorMessage){
}
});
API description
Returns all timers for a device or group. Each timer is assigned to a scheduled task.
void getAllTimerList(String devId, TimerDeviceTypeEnum deviceTimerTypeEnum, final ITuyaDataCallback<List<TimerTask>> callback);
Parameters
Parameter | Description |
---|---|
devId | The device ID or group ID. |
TimerDeviceTypeEnum | The target for which the scheduled task runs. Valid values:
|
callback | The success or failure callback. null cannot be returned. |
Parameters of TimerTask
Parameter | Description |
---|---|
TimerTaskStatus | The switch status and name of a timer. |
ArrayList |
The list of timers. |
category | The category of the timer group. |
Example
TuyaHomeSdk.getTimerInstance().getAllTimerList(mGwId, TimerDeviceTypeEnum.DEVICE, new ITuyaDataCallback<List<TimerTask>>() {
@Override
public void onSuccess(List<TimerTask> timerTaskList){
}
@Override
public void onError(String errorCode, String errorMessage){
}
});
API description
void updateCategoryTimerStatus(String taskName, String devId, TimerDeviceTypeEnum deviceTimerTypeEnum, TimerUpdateEnum timerUpdateEnum, IResultCallback callback);
Parameters
Parameter | Description |
---|---|
taskname | The timer group. |
devId | The device ID or group ID. |
TimerDeviceTypeEnum | The target for which the scheduled task runs. Valid values:
|
TimerUpdateEnum | The type of operation. Valid values:
|
callback | The success or failure callback. null cannot be returned. |
Example
TuyaHomeSdk.getTimerInstance().updateCategoryTimerStatus("test" ,"90sdjoi3dedj33", TimerDeviceTypeEnum.DEVICE, TimerUpdateEnum.CLOSE,new IResultCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(String errorCode, String errorMsg) {
}
});
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback