Skip to content

Automation SDK: QuecAutomateSdk

Feature Description

The SDK supports the user to configure certain rules to make the device perform the specified actions under the specified conditions.

kotlin
QuecAutomateService

SDK Integration Method

Note

The automation SDK depends on the core library quec-iot-sdk to run. Please integrate the core library according to the IoT SDK Integration Guide.

Add dependencies

groovy
implementation 'com.quectel.app.sdk:quec-automate-sdk:2.14.0'

Automation Management

Obtain Automation List

API

Obtain the automation list by paging request.

kotlin
fun getAutomationList(pageNumber: Int, pageSize: Int, callBack: QuecCallback<QuecAutoListModel>)

Parameter

ParameterRequiredDescription
pageNumberYPage number.
pageSizeYPage size.
callbackYCallback function of the request.

Example

kotlin
QuecAutomateService.getAutomationList(1, 10) {
    if (it.isSuccess) {
        val data = it.data //Obtain the automation list successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }
}

QuecAutoListModel Definition

FieldTypeDescription
hasNextPagebooleanWhether there is a next page.
hasPreviousPagebooleanWhether there is a previous page.
isFirstPagebooleanWhether it is the first page.
isLastPagebooleanWhether it is the last page.
totalintTotal recorded count.
pageintCurrent page number.
pageSizeintPage size.
listList<QuecAutoListItemModel>Record data.

QuecAutoListItemModel Definition

FieldTypeDescription
automationIdlongAutomation ID
conditionTypeintTrigger type.
1 - Meet any condition
2 - Meet all conditions
nameStringAutomation name.
nameTypeintAutomation name generation method.
1 - System generated
2 - User filled
statusbooleanEnablement status.
true: Enabled
false: Disabled
triggerListList<QuecAutoListItemConditionModel>Trigger conditions.
actionListList<QuecAutoListItemActionModel>Execution actions.

QuecAutoListItemConditionModel Definition

FieldTypeDescription
nameStringDevice name.
iconStringDevice icon.
typeintTrigger condition type.
0 - Device
1 - Timer
sortintCondition order, starting from 1 incrementally.

QuecAutoListItemActionModel Definition

FieldTypeDescription
nameStringDevice/Group/Scene name.
iconStringDevice/Group/Scene icon.
typeintAction type.
1 - Scheduled task
2 - Device
3 - Group
4 - Scene
sortintOrder, starting from 1 incrementally.

Create Automation

API

Creating an automation rule can be divided into four parts:

  1. Basic information
    1. Name
  2. Effective time
    1. Time period
      1. Specific time period (0:00 – 23:59:59)
      2. The whole day
      3. Daytime/Nighttime
    2. Date
      1. Every day
      2. The nth day of each week
      3. The nth day of each month
      4. Specified start date and end date
  3. Trigger condition
    1. Condition selection
      1. Meet any condition
      2. Meet all conditions
    2. Condition type (multiple are allowed)
      1. Linked conditions of specified devices
      2. Timer
        1. Specific time of a day
        2. Which days of each week
  4. Execution actions (multiple are allowed)
    1. Execute device linkage configuration
    2. Execute specified scene
    3. Add a scheduled task

After filling in all the information of the four parts, a usable rule can be created.

kotlin
fun addAutomation(automationModel: QuecAutomationModel, callBack: QuecCallback<Long>)

Parameter

ParameterRequiredDescription
automationModelYAutomation information
callbackYCallback function of the request.

Example

kotlin
QuecAutomateService.addAutomation(
    QuecAutomationModel(
        "",
        0L,
        1,
        null,
        "Automation Name",
        1,
        QuecAutomationPreconditionModel().apply {
            effectDate = ""
            effectDateType = 0
            effectTimeType = 2
            location = ""
            timeZone = "GMT+08:00"
        },
        listOf(
            QuecAutomationConditionModel(
                type = 1,
                timer = QuecAutomationTimeModel(
                    0, "14:10", "", "GMT+8:00"
                ),
            )
        ),
        listOf(
            QuecAutomationActionModel(
                type = 4,
                icon = "https://xxx/xxx.png",
                name = "sence name",
                sceneId = "Scene ID",
                sort = 1,
            )
        )
    )
) {
    if (it.isSuccess) {
        //Create an automation successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }
}

QuecAutomationModel Definition

FieldTypeDescription
fidStringHome ID. This parameter is only specified in home mode, otherwise "" is passed.
automationIdlongAutomation ID
conditionTypeintTrigger type.
1 - Meet any condition
2 - Meet all conditions
iconStringAutomation icon
nameStringAutomation name
nameTypeintAutomation name generation method.
1 - System generated
2 - User filled
preconditionQuecAutomationPreconditionModelEffective conditions.
conditionsList<QuecAutomationConditionModel>Trigger conditions.
actionsList<QuecAutomationActionModel>Execution actions.

QuecAutomationPreconditionModel Definition

FieldTypeDescription
effectTimeTypeintEffective time.
0 - Daytime
1 - Nighttime
2 - The whole day
3 - Specific time period
startTimeStringSpecific start time, e.g., 12:00:00
endTimeStringSpecific end time, e.g., 12:00:00
effectDateTypeintEffective date.
0 - Every day
1 - Weekly
2 - Monthly
3 - Specified dates
effectDateStringEffective date for transmission calculation, e.g., weekly 1/2/3/4/5/6/7, monthly 1...31, specified dates 12-19/12-21.
effectDateShowStringEffective date for display, e.g., Daily Monday...Sunday 1st...31st
regionNameStringRegion name.
locationStringLongitude and latitude coordinates, longitude first, latitude second. Coordinate system: GCJ-02.
timeZoneStringTime zone ID, e.g., GMT+08:00.

QuecAutomationConditionModel Definition

FieldTypeDescription
typeintTrigger type.
1 - Meet any condition
2 - Meet all conditions
iconStringIcon.
nameStringCondition name.
timerQuecAutomationTimeModelTrigger time.
productKeyStringDevice ProductKey.
deviceKeyStringDeviceKey.
propertyQuecAutoProductTSLModelDevice property.
sortintCondition order, starting from 1 incrementally.

QuecAutomationActionModel Definition

FieldTypeDescription
typeintAction type.
1 - Delay execution of subsequent action
2 - Modify device property
3 - Modify group property
4 - Execute scene
iconStringIcon.
nameStringName.
productKeyStringDevice ProductKey.
deviceKeyStringDeviceKey.
sceneIdStringScene ID.
delayTimeintDelay time in seconds.
sortintAction order, starting from 1 incrementally.
propertyQuecAutoProductTSLModelDevice property.

QuecAutomationTimeModel Definition

FieldTypeDescription
typeintTiming type.
0 - Once
1 - Daily
2 - Custom
timeStringScheduled time in 24-hour format, e.g., 23:00.
dayOfWeekStringCustom time range, formatted as "1,3,4", separated by ",".
timeZoneStringTime zone ID, e.g., GMT+08:00.

QuecAutoProductTSLModel Definition

FieldTypeDescription
idintTSL ID.
codeStringTSL code.
nameStringTSL name.
compareStringComparison operator when used as a condition: > >= < <= == != REPORT COUNT, where REPORT is reported data.
unitStringUnit.
dataTypeStringData type.
valueStringProperty value.
subNameStringData type.

Edit Automation

API

Edit an existing automation rule.

kotlin
fun editAutomation(automationModel: QuecAutomationModel, callBack: QuecSimpleCallBack)

Parameter

ParameterRequiredDescription
automationModelYAutomation information.
callbackYCallback function of the request.

Example

kotlin
val model = getModel() //automationModel obtained from the server.
model.name = "new name"
QuecAutomateService.editAutomation(model) {
    if (it.isSuccess) {
        //Edit an existing automation rule successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }
}

Delete Automation

Delete a specified automation rule.

API

kotlin
fun deleteAutomation(automationId: Long, callBack: QuecCallback<Any>)

Parameter

ParameterRequiredDescription
automationIdYAutomation ID.
callbackYCallback function of the request.

Example

kotlin
val model = getModel() //automationModel obtained from the server.
QuecAutomateService.deleteAutomation(model.automationId) {
    if (it.isSuccess) {
        //Delete a specified automation rule successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }
}

Query TSL Available for Automation Condition and Action

API

kotlin
fun <T> getAutomationTSLWithProductKey(
        productKey: String,
        type: Int,
        convertor: PropertyConvertor<T>,
        callBack: QuecCallback<QuecPublishedAutoProductTSLModel<T>>
)

Parameter

ParameterRequiredDescription
productKeyYDevice ProductKey.
typeYQuery type.
0 - All
1 - Condition
2 - Action
convertorYCustom TSL model parser.
callbackYCallback function of the request.

Example

kotlin
//ModelBasic is defined in the core library.
val modelConvertor = object : PropertyConvertor<ModelBasic<*>> {
    override fun convert(objectJson: JSONArray): List<ModelBasic<*>> {
        val modelBasics: MutableList<ModelBasic<*>> = ArrayList()
        try {
            //This method is defined in the core library.
            return ObjectModelParse.buildModelListContent(objectJson)
        } catch (e: JSONException) {
            QLog.e("TslModelUtils", "convert error $e")
        }
        return modelBasics
    }
}
QuecAutomateService.getAutomationTSLWithProductKey("pk", 0, modelConvertor) {
    if (it.isSuccess) {
        //Query the TSL model available for automation conditions and actions successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }
}

QuecPublishedAutoProductTSLModel Definition

FieldTypeDescription
actionsList<T>Properties available for conditions.
conditionsList<T>Properties available for actions.

Get Automation Details

API

Get automation details.

kotlin
fun getAutomationInfo(automationId: Long, callBack: QuecCallback<QuecAutomationModel>)

Parameter

ParameterRequiredDescription
automationIdYAutomation ID.
callbackYCallback function of the request.

Example

kotlin
QuecAutomateService.getAutomationInfo(1002) {
    if (it.isSuccess) {
        //Get automation details successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }
}

Enable/Disable Automation

API

Enable or disable an automation rule.

kotlin
fun updateAutomationSwitchStatus(automationId: Long, open: Boolean, callBack: QuecCallback<Any>)

Parameter

ParameterRequiredDescription
automationIdYAutomation ID.
openYEnablement status.
callbackYCallback function of the request.

Example

kotlin
QuecAutomateService.updateAutomationSwitchStatus(1002, true) {
    if (it.isSuccess) {
        //Enable an automation rule successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }

Automation Testing

Test Automation

API

Test whether configured automation actions can be executed.

kotlin
fun testAutomationInfo(actions: List<QuecAutomationActionModel>, timeout: Long, callBack: QuecCallback<Long>)

Parameter

ParameterRequiredDescription
actionsYAutomation actions.
timeoutYTimeout. Unit: second.
callbackYCallback function of the request. Result ID is returned upon successful execution.

Example

kotlin
QuecAutomateService.testAutomationInfo(
    listOf(
        QuecAutomationActionModel(
            type = 4,
            icon = "https://iot-oss.quectelcn.com/quec_scene_1.png",
            name = "sence name",
            sceneId = "Scene ID",
            sort = 1,
        )
    ), 30
) {
    if (it.isSuccess) {
        //Test whether configured automation actions can be executed successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }
}

Get Automation Test Results

API

After executing an automation test, you can query execution results using the result ID.

kotlin
fun getTestAutomationResult(testResultId: Long, callBack: QuecCallback<QuecTestAutomationResultModel>)

Parameter

ParameterRequiredDescription
testResultIdYResult ID.
callbackYCallback function of the request.

Example

kotlin
QuecAutomateService.getTestAutomationResult(100) {
    if (it.isSuccess) {
        val data = it.data //query the execution result successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }
}

QuecTestAutomationResultModel Definition

FieldTypeDescription
resultintExecution result.
0 - All successful
1 - Partially successful
2 - All failed
successCountintThe number of successful executions.
failCountintThe number of failed executions.
overallFailMsgStringError message.
timeoutStatusbooleanTimeout status.
failActionListList<QuecTestActionModel>List of failed actions.

QuecTestActionModel Definition

FieldTypeDescription
nameStringAction name.
iconStringAction icon.
failMsgStringFailure reason.
propertyQuecAutoProductTSLModelFailed TSL model property.

Automation Logs

Get Automation Log List

API

After executing an automation, you can query its execution records.

kotlin
fun getAutomationLogList(
        lastLogId: Long,
        limit: Int,
        callBack: QuecCallback<List<QuecAutoLogDataModel>>
)

Parameter

ParameterRequiredDescription
lastLogIdYID of the last log.
limitYThe number of logs to get.
callbackYCallback function of the request.

Example

kotlin
QuecAutomateService.getAutomationLogList(0, 10) {
    if (it.isSuccess) {
        val data = it.data //Get automation logs successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }
}

QuecAutoLogDataModel Definition

FieldTypeDescription
automationIdlongAutomation ID.
logIdlongLog ID.
nameStringAutomation task name.
resultintExecution result.
0 - All successful
1 - All failed
2 - Partially successful
timelongExecution time (timestamp).
logDetailsList<QuecLogDetails>Log details.

QuecLogDetails Definition

FieldTypeDescription
actionNameStringAction name.
typeintType.
2 - Device
3 - Group
4 - Scene
resultbooleanExecution result.
true - Successful
false - Failed
executeTimelongExecution time.
actionQuecAutoProductTSLModelExecution action.

Get Log Details

API

Get automation log details.

kotlin
fun getAutomationLogDetail(logId: Long, callBack: QuecCallback<QuecAutoLogDataModel>)

Parameter

ParameterRequiredDescription
logIdYLog ID.
callbackYCallback function of the request.

Example

kotlin
QuecAutomateService.getAutomationLogDetail(200) {
    if (it.isSuccess) {
        val data = it.data //Get automation log details successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }
}

Clear Automation Logs

API

Clear all automation logs.

kotlin
fun clearAutomationLogs(callBack: QuecCallback<Any>)

Parameter

ParameterRequiredDescription
callbackYCallback function of the request.

Example

kotlin
QuecAutomateService.clearAutomationLogs {
    if (it.isSuccess) {
        //Clear all automation logs successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }
}