Skip to content

Automation SDK: QuecAutomateKit

Feature Description

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

objc
#import <QuecAutomateKit/QuecAutomateKit.h>
/// Initialization.
[QuecAutomateService sharedInstance]

SDK Integration Method

Note

The automation SDK depends on the core library QuecIotSdk to run. Please integrate the core library according to the IoT SDK Integration Guide.

objc
pod 'QuecAutomateKit', '~> 0.3.0'

Automation Management

Obtain Automation List

API

Obtain the automation list by paging request.

objc
- (void)getAutomationListWithPageNumber:(NSInteger)pageNumber
                               pageSize:(NSInteger)pageSize
                                success:(QuecAutomationModelsSuccessBlock)success
                                failure:(QuecErrorBlock)failure;

Parameter

ParameterRequiredDescription
pageNumberYPage number.
pageSizeYPage size.
successNCallback function of successful request.
failureNCallback function of failed request.

Example

objc
[QuecAutomateService.sharedInstance getAutomationListWithPageNumber:1 pageSize:10 success:^(NSArray<QuecAutomateModel *> * _Nonnull models, NSUInteger total) {
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

QuecAutomateModel Definition

FieldTypeDescription
automationIdlong longAutomation ID.
fidStringHome ID. This parameter is only required when the home mode is enabled.
conditionTypeQuecAutomateConditionRuleTypeTrigger type.
QuecAutomateConditionRuleAny = 1 //1 - Meet any condition
QuecAutomateConditionRuleAll //2 - Meet all conditions
nameStringAutomation name.
nameTypeintAutomation name generation method.
1 - System generated
2 - User filled
statusbooleanEnablement status.
true: Enabled
false: Disabled
preconditionQuecAutomationPreconditionModelEffective time.
conditionsNSArray<QuecAutomationConditionModel *> *Trigger conditions.
actionsNSArray<QuecAutomationActionModel *> *Execution actions.

QuecAutomationPreconditionModel Definition

FieldTypeDescription
effectDateTypeQuecAutomateEffectDateTypeEffective date.
QuecAutomateEffectDateTypeEveryday = 0, /// Every day
QuecAutomateEffectDateTypeWeekly, /// Weekly
QuecAutomateEffectDateTypeMonthly, /// Monthly
QuecAutomateEffectDateTypeNamedDate /// Specified dates
effectTimeTypeQuecAutomateEffectTimeTypeEffective time.
QuecAutomateEffectTimeTypeDaytime = 0, /// Daytime
QuecAutomateEffectTimeTypeNight, /// Nighttime
QuecAutomateEffectTimeTypeWholeDay, /// The whole day
QuecAutomateEffectTimeTypeSpecificTimePeriod /// Specific time period
startTimeNSStringStart time, required when effectTimeType = QuecAutomateEffectTimeTypeWholeDay/QuecAutomateEffectTimeTypeSpecificTimePeriod. Format: HH:mm.
endTimeNSStringEnd time, required when effectTimeType = QuecAutomateEffectTimeTypeWholeDay/QuecAutomateEffectTimeTypeSpecificTimePeriod. Format: HH:mm.
effectDateNSStringEffective date, omitted when effectDateType = QuecAutomateEffectDateTypeEveryday. Every week: 1,2,3,...7 indicates Monday to Sunday. Weekly: 1st to 31st. Specified date format: MM-dd/MM-dd, e.g., 12-19/12-2.
regionNameNSStringRegion name.
locationNSStringLongitude and latitude.
timeZoneNSStringTime zone.

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.

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.

QuecAutomationPropertyModel Definition

FieldTypeDescription
identifierintTSL ID.
codeStringTSL identifier. Identifier is used because ID is the keyword for Objective-C.
nameStringTSL name.
compareStringComparison operator when used as a condition: > >= < <= == != REPORT COUNT, where REPORT is reported data.
unitStringUnit.
dataTypeStringData type.
valueStringProperty value.
subNameStringData type.

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.
delayTimeNSNumberDelay time in seconds.
sortintAction order, starting from 1 incrementally.
propertyQuecAutomationPropertyModelDevice property.

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.

objc
- (void)addAutomationWithModel:(QuecAutomateModel *)model
                       success:(QuecVoidBlock)success
                       failure:(QuecErrorBlock)failure;

Parameter

ParameterRequiredDescription
modelYAutomation information
successNCallback function of successful request.
failureNCallback function of failed request.

Example

objc
QuecAutomationPreconditionModel *precondition = [[QuecAutomationPreconditionModel alloc] init];
precondition.effectDate = @"";
precondition.effectDateType = QuecAutomateEffectDateTypeEveryday;
precondition.effectTimeType = QuecAutomateEffectTimeTypeWholeDay;
precondition.location = @"";
precondition.timeZone = @"GMT+08:00";

QuecAutomationTimeModel *time = QuecAutomationTimeModel.new;
time.type = 0;
time.time = @"14:10";
time.dayOfWeek = @"";
time.timeZone = @"GMT+8:00";
QuecAutomationConditionModel *condition = [[QuecAutomationConditionModel alloc] initWithType:1
                                                                                        icon:@""
                                                                                        name:@""
                                                                                        timer:time
                                                                                    productKey:@""
                                                                                    deviceKey:@""
                                                                                    property:nil
                                                                                        sort:1];
QuecAutomationActionModel *action = [[QuecAutomationActionModel alloc] initWithType:4
                                                                                icon:@"https://xxxxx.png"
                                                                                name:@"sence name"
                                                                            productKey:@""
                                                                            deviceKey:@""
                                                                            sceneId:@"Scene Id"
                                                                            delayTime:@(0)
                                                                            property:nil
                                                                                sort:1];

QuecAutomateModel *automateModel = [[QuecAutomateModel alloc] initWithFid:@"your fid"
                                                            conditionType:QuecAutomateConditionRuleAny
                                                                        name:@"Automation name"
                                                                    nameType:1
                                                            preconditions:precondition
                                                                conditions:@[condition]
                                                                    actions:@[action]];

[QuecAutomateService.sharedInstance addAutomationWithModel:automateModel
                                                    success:^{
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

Edit Automation

API

Edit an existing automation rule.

objc
- (void)editAutomationWithModel:(QuecAutomateModel *)model
                        success:(QuecVoidBlock)success
                        failure:(QuecErrorBlock)failure;

Parameter

ParameterRequiredDescription
modelYAutomation information.
successNCallback function of successful request.
failureNCallback function of failed request.

Example

objc
QuecAutomateModel *automate = QuecAutomateModel.new; ///automationModel obtained from the server.
automate.name = @"new name";
[QuecAutomateService.sharedInstance editAutomationWithModel:automate
                                                    success:^{
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

Delete Automation

Delete a specified automation rule.

API

objc
- (void)deleteAutomationWithAutomationId:(long long)automationId
                                 success:(QuecVoidBlock)success
                                 failure:(QuecErrorBlock)failure;

Parameter

ParameterRequiredDescription
automationIdYAutomation ID.
successNCallback function of successful request.
failureNCallback function of failed request.

Example

objc
[QuecAutomateService.sharedInstance deleteAutomationWithAutomationId:10010 success:^{
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

Query TSL Available for Automation Condition and Action

API

objc
- (void)getAutomationTSLWithProductKey:(NSString *)productKey
                                  type:(NSInteger)type
                               success:(QuecAutomationPropertySuccessBlock)success
                               failure:(QuecErrorBlock)failure;
)

Parameter

ParameterRequiredDescription
productKeyYDevice ProductKey.
typeYQuery type.
0 - All
1 - Condition
2 - Action
successNCallback function of successful request.
failureNCallback function of failed request.

Example

objc
[QuecAutomateService.sharedInstance getAutomationTSLWithProductKey:@"pk" type:0 success:^(NSArray<QuecProductTSLPropertyModel *> * _Nonnull conditions, NSArray<QuecProductTSLPropertyModel *> * _Nonnull actions) {
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

See QuecProductTSLPropertyModel Definition in the SDK description in the Device Management section.

Get Automation Details

API

Get automation details.

objc
- (void)getAutomationInfoWithAutomationId:(long long)automationId
                                  success:(void(^)(QuecAutomateModel *model))success
                                  failure:(QuecErrorBlock)failure;

Parameter

ParameterRequiredDescription
automationIdYAutomation ID.
successNCallback function of successful request.
failureNCallback function of failed request.

Example

objc
[QuecAutomateService.sharedInstance getAutomationInfoWithAutomationId:10009 success:^(QuecAutomateModel * _Nonnull model) {
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

Enable/Disable Automation

API

Enable or disable an automation rule.

objc
- (void)updateAutomationSwitchStatusWithAutomationId:(long long)automationId
                                              status:(BOOL)status
                                             success:(QuecVoidBlock)success
                                             failure:(QuecErrorBlock)failure;

Parameter

ParameterRequiredDescription
automationIdYAutomation ID.
statusYEnablement status.
true - Enable
false - Disable
successNCallback function of successful request.
failureNCallback function of failed request.

Example

objc
[QuecAutomateService.sharedInstance updateAutomationSwitchStatusWithAutomationId:10011 status:YES success:^{
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

Automation Testing

Test Automation

API

Test whether configured automation actions can be executed.

objc
- (void)testAutomationInfoWithActions:(NSArray<QuecAutomationActionModel *> *)actions
                                timeout:(long)timeout
                              success:(void(^)(long long testResultId))success
                              failure:(QuecErrorBlock)failure;

Parameter

ParameterRequiredDescription
actionsYAutomation actions.
timeoutYTimeout. Unit: second.
successNCallback function of successful request.
failureNCallback function of failed request.

Example

objc
QuecAutomationActionModel *action = [[QuecAutomationActionModel alloc] initWithType:4
                                                                                   icon:@"https://xxxxx.png"
                                                                                   name:@"sence name"
                                                                             productKey:@""
                                                                              deviceKey:@""
                                                                                sceneId:@"Scene Id"
                                                                              delayTime:@(0)
                                                                               property:nil
                                                                                   sort:1];
    [QuecAutomateService.sharedInstance testAutomationInfoWithActions:@[action]
                                                              timeout:30
                                                              success:^(long long testResultId) {
        /// Next Action
    } failure:^(NSError *error) {
        NSLog(@"check error: %@", error);
    }];

Get Automation Test Results

API

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

objc
- (void)getTestAutomationResultWithId:(long long)testResultId
                              success:(QuecAutomationResultSuccessBlock)success
                              failure:(QuecErrorBlock)failure;

Parameter

ParameterRequiredDescription
testResultIdYResult ID.
successNCallback function of successful request.
failureNCallback function of failed request.

Example

objc
[QuecAutomateService.sharedInstance getTestAutomationResultWithId:10002 success:^(QuecAutomationResultModel * _Nullable resultModel) {
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

QuecAutomationResultModel Definition

FieldTypeDescription
resultNSIntegerExecution result.
0 - All successful
1 - Partially successful
2 - All failed
successCountNSIntegerThe number of successful executions.
failCountNSIntegerThe number of failed executions.
overallFailMsgNSStringError message.
timeoutStatusBOOLTimeout status.
failActionListNSArray<QuecAutomationResultItemModel *> *List of failed actions.

QuecAutomationResultItemModel Definition

FieldTypeDescription
actionNameNSStringAction name.
iconNSStringAction icon.
failMsgNSStringFailure reason.

Automation Logs

Get Automation Log List

API

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

objc
- (void)getAutomationLogListWithLastLogId:(long long)lastLogId
                                    limit:(NSInteger)limit
                                  success:(void(^)(NSArray<QuecAutomationLogItemModel *> *list))success
                                  failure:(QuecErrorBlock)failure;

Parameter

ParameterRequiredDescription
lastLogIdYID of the last log.
limitYThe number of logs to get.
successNCallback function of successful request.
failureNCallback function of failed request.

Example

objc
[QuecAutomateService.sharedInstance getAutomationLogListWithLastLogId:99
                                                                limit:10
                                                                success:^(NSArray<QuecAutomationLogItemModel *> * _Nonnull list) {
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

QuecAutomationLogItemModel Definition

FieldTypeDescription
automationIdlongAutomation ID.
logIdlongLog ID.
nameStringAutomation task name.
iconStringAutomation icon.
resultintExecution result.
0 - All successful
1 - All failed
2 - Partially successful
timelongExecution time (timestamp).
logDetailsNSArray<QuecAutomationLogItemActionModel *> *Log details.

QuecAutomationLogItemActionModel Definition

FieldTypeDescription
actionNameStringAction name.
typeintType.
2 - Device
3 - Group
4 - Scene
resultbooleanExecution result.
true - Successful
false - Failed
executeTimelongExecution time.
actionQuecAutomationPropertyModelExecution action.
actionIconNSStringExecution action icon, device/group/scene.

Get Log Details

API

Get automation log details.

objc
- (void)getAutomationLogDetailWithLogId:(long long)logId
                                success:(void(^)(QuecAutomationLogItemModel *detailInfo))success
                                failure:(QuecErrorBlock)failure;

Parameter

ParameterRequiredDescription
logIdYLog ID.
successNCallback function of successful request.
failureNCallback function of failed request.

Example

objc
[QuecAutomateService.sharedInstance getAutomationLogDetailWithLogId:100
                                                                success:^(QuecAutomationLogItemModel * _Nonnull detailInfo) {
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];

Clear Automation Logs

API

Clear all automation logs.

objc
- (void)clearAutomationLogsWithSuccess:(QuecVoidBlock)success failure:(QuecErrorBlock)failure;

Parameter

ParameterRequiredDescription
successNCallback function of successful request.
failureNCallback function of failed request.

Example

objc
[QuecAutomateService.sharedInstance clearAutomationLogsWithSuccess:^{
    /// Next Action
} failure:^(NSError *error) {
    NSLog(@"check error: %@", error);
}];