Last Updated on : 2023-10-11 02:47:01download
This topic describes the device schedule service that allows the user to schedule a smart device to run a task automatically. For example, schedule the curtains to close at 7 p.m. and open at 9 a.m.
The class ThingTimerManager is responsible for scheduling tasks. The request parameter for each API is TimerManagerBuilder, but the payload varies by API. The following sections will describe the required parameters for each API.
API description
| API | Description |
|---|---|
| getTimerList | Get the list of device or group schedules. |
| addTimer | Add a device or group schedule. |
| editTimer | Update a device or group schedule. |
| deleteTimer | Delete a device or group schedule. |
| updateTimerStatus | Update the status of a schedule. |
Parameter description
Description of TimerManagerBuilder
| Property | Type | Description |
|---|---|---|
| deviceId | String | The device ID. |
| groupId | long | The group ID. |
| category | String | The category of the schedule. |
| timerId | String | The schedule ID. |
| isOpen | boolean | Specifies whether to enable the schedule. |
| loops | String | The recurrence pattern, in the binary format of 0000000. Each digit can be 0 (off) or 1 (on). 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. 0000000 indicates a one-time schedule. 1111111 indicates the schedule runs every day. |
| time | String | The specified execution time. For example, 18:00. |
| dps | Map<String,Object> | The data point (DP) triggered when the schedule runs. For example, {"1":true}. For the raw type of DP, convert it with new String(Base64.encodeBase64(HexUtil.hexStringToBytes(dps))). |
| isAppPush | boolean | Specifies whether to notify the user of the schedule execution result via the app. |
| aliasName | String | The name of the schedule. |
| timezone | String | The time zone of the schedule. |
| callback | IThingTimerCallBack | The callback. |
API description
fun addTimer(builder: TimerManagerBuilder)
Parameter description
| Property | Type | Description | Required |
|---|---|---|---|
| deviceId | String | The device ID. It is required when a device schedule is created. | No |
| groupId | long | The group ID. It is required when a group schedule is created. | No |
| category | String | The category of the schedule. | Yes |
| isOpen | boolean | Specifies whether to enable the schedule. | Yes |
| loops | String | The recurrence pattern, in the format of 0000000. Each digit can be 0 (off) or 1 (on). 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. 0000000 indicates a one-time schedule. 1111111 indicates the schedule runs every day. |
Yes |
| time | String | The specified execution time. For example, 18:00. |
Yes |
| dps | Map<String,Object> | The data point (DP) triggered when the schedule runs. For example, {"1":true}. For the raw type of DP, convert it with new String(Base64.encodeBase64(HexUtil.hexStringToBytes(dps))). |
Yes |
| isAppPush | boolean | Specifies whether to notify the user of the schedule execution result via the app. | Yes |
| aliasName | String | The name of the schedule. | Yes |
| callback | IThingTimerCallBack | The callback. | Yes |
Example
HashMap<String, Object> dps = new HashMap<>();
dps.put("1",true);
TimerManagerBuilder builder = new TimerManagerBuilder.Builder()
.setDeviceId("xxxx")
.setCategory("test")
.setTime("08:00")
.setDps(dps)
.setLoops("1100011")
.setAliasName("Test")
.isOpen(true)
.isAppPush(true)
.setCallback(new IThingTimerCallBack() {
@Override
public void successful(@Nullable List<? extends AlarmTimerBean> list) {
}
@Override
public void fail(int errorCode, @NonNull String errorMsg) {
}
})
.build();
ThingDeviceDetailKit.getInstance().getDeviceTimerManager().addTimer(builder);
API description
fun editTimer(builder: TimerManagerBuilder)
Parameter description
| Property | Type | Description | Required |
|---|---|---|---|
| deviceId | String | The device ID. It is required when a device schedule is updated. | No |
| groupId | long | The group ID. It is required when a group schedule is updated. | No |
| timerId | String | The schedule ID. | Yes |
| loops | String | The recurrence pattern, in the format of 0000000. Each digit can be 0 (off) or 1 (on). 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. 0000000 indicates a one-time schedule. 1111111 indicates the schedule runs every day. |
Yes |
| time | String | The specified execution time. For example, 18:00. |
Yes |
| dps | Map<String,Object> | The data point (DP) triggered when the schedule runs. For example, {"1":true}. For the raw type of DP, convert it with new String(Base64.encodeBase64(HexUtil.hexStringToBytes(dps))). |
Yes |
| isAppPush | boolean | Specifies whether to notify the user of the schedule execution result via the app. | Yes |
| aliasName | String | The name of the schedule. | Yes |
| callback | IThingTimerCallBack | The callback. | Yes |
Example
HashMap<String, Object> dps = new HashMap<>();
dps.put("1",true);
TimerManagerBuilder builder = new TimerManagerBuilder.Builder()
.setDeviceId("xxxx")
.setTimerId("xxxxx")
.setTime("08:00")
.setDps(dps)
.setLoops("1100011")
.setAliasName("Test")
.isAppPush(true)
.setCallback(new IThingTimerCallBack() {
@Override
public void successful(@Nullable List<? extends AlarmTimerBean> list) {
}
@Override
public void fail(int errorCode, @NonNull String errorMsg) {
}
})
.build();
ThingDeviceDetailKit.getInstance().getDeviceTimerManager().editTimer(builder);
API description
fun deleteTimer(builder: TimerManagerBuilder)
Parameter description
| Property | Type | Description | Required |
|---|---|---|---|
| deviceId | String | The device ID. It is required when a device schedule is deleted. | No |
| groupId | long | The group ID. It is required when a group schedule is deleted. | No |
| timerId | String | The schedule ID. | Yes |
| callback | IThingTimerCallBack | The callback. | Yes |
Example
TimerManagerBuilder builder = new TimerManagerBuilder.Builder()
.setDeviceId("xxxx")
.setTimerId("xxxxxx")
.setCallback(new IThingTimerCallBack() {
@Override
public void successful(@Nullable List<? extends AlarmTimerBean> list) {
}
@Override
public void fail(int errorCode, @NonNull String errorMsg) {
}
})
.build();
ThingDeviceDetailKit.getInstance().getDeviceTimerManager().deleteTimer(builder);
API description
fun getTimerList(builder: TimerManagerBuilder)
Parameter description
| Property | Type | Description | Required |
|---|---|---|---|
| deviceId | String | The device ID. It is required when the list of device schedules is requested. | No |
| groupId | long | The group ID. It is required when the list of group schedules is requested. | No |
| callback | IThingTimerCallBack | The callback. | Yes |
Example
TimerManagerBuilder builder = new TimerManagerBuilder.Builder()
.setDeviceId("xxxx")
.setCallback(new IThingTimerCallBack() {
@Override
public void successful(@Nullable List<? extends AlarmTimerBean> list) {
}
@Override
public void fail(int errorCode, @NonNull String errorMsg) {
}
})
.build();
ThingDeviceDetailKit.getInstance().getDeviceTimerManager().getTimerList(builder);
Description of return values
The class AlarmTimerBean
| Property | Type | Description |
|---|---|---|
| groupId | String | The schedule ID. It is the value of timerId passed in when updating a schedule. |
| timezoneId | String | The time zone of the device. |
| status | int | Specifies whether to enable the schedule. 1: Enable. 0: Disable. |
| loops | String | The recurrence pattern, in the format of 0000000. Each digit can be 0 (off) or 1 (on). 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. 0000000 indicates a one-time schedule. 1111111 indicates the schedule runs every day. |
| time | String | The specified execution time. For example, 18:00. |
| value | String | The data point (DP) triggered when the schedule runs. For example, {"xx":true,"xxx":false}. The dps field in the request parameter. |
| isAppPush | boolean | Specifies whether to notify the user of the schedule execution result via the app. |
| aliasName | String | The name of the schedule. |
API description
fun updateTimerStatus(builder: TimerManagerBuilder)
Parameter description
| Property | Type | Description | Required |
|---|---|---|---|
| deviceId | String | The device ID. It is required when a device schedule is updated. | No |
| groupId | long | The group ID. It is required when a group schedule is updated. | No |
| timerId | long | The schedule ID. | Yes |
| isOpen | boolean | Specifies whether to enable the schedule. | Yes |
| callback | IThingTimerCallBack | The callback. | Yes |
Example
TimerManagerBuilder builder = new TimerManagerBuilder.Builder()
.setDeviceId("xxxx")
.setTimerId("xxxxxx")
.isOpen(false)
.setCallback(new IThingTimerCallBack() {
@Override
public void successful(@Nullable List<? extends AlarmTimerBean> list) {
}
@Override
public void fail(int errorCode, @NonNull String errorMsg) {
}
})
.build();
ThingDeviceDetailKit.getInstance().getDeviceTimerManager().updateTimerStatus(builder);
| Error codes | Description |
|---|---|
| 1 | Device is offline. |
| 2 | Failed to execute the schedule. |
| 3 | Failed to get the device information. |
| 4 | Timeout. |
| 5 | Device exception. |
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback