Smart Access Control

Last Updated on : 2022-02-17 06:49:49download

Smart access control is a smart unlocking method to open a door by using an app. Access control can be implemented with multiple methods, such as remote unlocking and QR code. The system dynamically calculates the access control records to facilitate access control for residents and improve the efficiency of property management. Smart access control simplifies door opening and enhances community security.

Feature overview

Smart access control supports unlocking a door by tapping on an app or by scanning a QR code. The class TuyaCommunitySmartDoorService is used to implement smart access control.

Query a list of access control devices

Returns a list of smart access control devices assigned to a house.

API description

- (void)getSmartDoorListWithCommunityId:(NSString *)communityId
                                 roomId:(NSString *)roomId
                                success:(void(^)(NSArray<TuyaCommunitySmartDoorInfoModel *>*models))success
                                failure:(void(^)(NSError *error))failure;

Request parameter

Parameter Description
communityId The community ID. You can call TuyaCommunityHouseModel to get the value.
roomId The room ID. You can call TuyaCommunityHouseModel to get the value.
success The success callback. Each data model of TuyaCommunitySmartDoorInfoModel in the response indicates an access control device.
failure The failure callback. An error message is returned.

Parameters of TuyaCommunitySmartDoorInfoModel

Parameter Description
deviceId The device ID. Each device is assigned a unique identifier.
deviceName The name of the device.

Example

TuyaCommunityHouseModel *houseModel = <#A house returned by the house list query API method#>;
[self.service getSmartDoorListWithCommunityId:houseModel.communityId
                                               roomId:houseModel.roomId
                                              success:^(NSArray<TuyaCommunitySmartDoorInfoModel *> * _Nonnull models) {
        //do something
    } failure:^(NSError * _Nonnull error) {
        NSLog(@"error = %@",error);
    }];

Unlock a door

Unlocks a door. This API method can be called after a list of access control devices is returned.

API description

- (void)openDoorWithCommunityId:(NSString *)communityId
                         roomId:(NSString *)roomId
                       deviceId:(NSString *)deviceId
                        success:(void(^)(NSString *accessLogId))success
                        failure:(void(^)(NSError *error))failure;

Request parameter

Parameter Description
communityId The community ID. You can call TuyaCommunityHouseModel to get the value.
roomId The room ID. You can call TuyaCommunityHouseModel to get the value.
deviceId The device ID. TuyaCommunitySmartDoorInfoModel can be returned to get the value of deviceId.
success The success callback. The ID of the pass record is returned.
failure The failure callback. An error message is returned.

Example

TuyaCommunityHouseModel *houseModel = <#A house returned by the house list query API method#>;
[self.service openDoorWithCommunityId:houseModel.communityId
                               roomId:houseModel.roomId
                             deviceId:model.deviceId
                              success:^(NSString * _Nonnull accessLogId) {
        // do something
    } failure:^(NSError * _Nonnull error) {
        NSLog(@"error = %@",error);
    }];

Query the unlocking result

Indicates the result of an unlocking operation. This API method can be polled at an interval, such as 0.3 seconds, after the unlocking API method is called.

API description

- (void)checkOpenDoorResultWithCommunityId:(NSString *)communityId
                               accessLogId:(NSString *)accessLogId
                                   success:(void(^)(TuyaCommunitySmartDoorOpenResult result))success
                                   failure:(void(^)(NSError *error))failure;

Request parameter

Parameter Description
communityId The community ID. You can call TuyaCommunityHouseModel to get the value.
accessLogId The ID of the pass record.
success The success callback. The callback of TuyaCommunitySmartDoorOpenResult. Valid values:
  • TuyaCommunitySmartDoorOpenResultOpening: unlocking, unknown state
  • TuyaCommunitySmartDoorOpenResultSuccess: unlocked successfully
  • TuyaCommunitySmartDoorOpenResultFailure: failed to unlock

Example

TuyaCommunityHouseModel *houseModel = <#A house returned by the house list query API method#>;
__weak __typeof(self) weakSelf = self;
[self.service checkOpenDoorResultWithCommunityId:houseModel.communityId
                                     accessLogId:logId
                                         success:^(TuyaCommunitySmartDoorOpenResult result) {
        switch (result) {
            case TuyaCommunitySmartDoorOpenResultOpening: {
                NSTimeInterval outTime = [[NSDate date] timeIntervalSince1970];
                if (outTime - self.currentTime > 3000.f) {
                    NSLog(@"Open Door Failure");
                } else {
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        [weakSelf getOpenReustWithLogId:logId];
                    });
                }
            }
                break;
            case TuyaCommunitySmartDoorOpenResultSuccess: {
                NSLog(@"Open Door Success");
                break;
            }
            case TuyaCommunitySmartDoorOpenResultFailure: {
                NSLog(@"Open Door Failure");
            }
            default:
                break;
        }
    } failure:^(NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];

Query unlocking records

Returns a list of unlocking records. Each time a user unlocks a door by tapping an app, an unlocking record is generated.

API description

- (void)getSmartDoorOpenRecordsWithCommunityId:(NSString *)communityId
                                        roomId:(NSString *)roomId
                                       success:(void(^)(NSArray<TuyaCommunitySmartDoorOpenRecordModel *> *models))success
                                       failure:(void(^)(NSError *error))failure;

Request parameter

Parameter Description
communityId The community ID. You can call TuyaCommunityHouseModel to get the value.
roomId The room ID. You can call TuyaCommunityHouseModel to get the value.
success The success callback. Each data model of TuyaCommunitySmartDoorOpenRecordModel in the response indicates an unlocking record.
failure The failure callback. An error message is returned.

Parameters of TuyaCommunitySmartDoorOpenRecordModel

Parameter Description
accessLogId The ID of a record.
accessControlName The name of the access control device.
accessControlAddress The address of the access control device.
accessTime The time when the record is generated.
accessDirection The device status indicated by a record. Valid values:
  • TuyaCommunitySmartDoorOpenDirectionOut: get out of the door
  • TuyaCommunitySmartDoorOpenDirectionIn: get into the door
  • TuyaCommunitySmartDoorOpenDirectionFailure: failed to open the door

Example

TuyaCommunityHouseModel *houseModel = <#A house returned by the house list query API method#>;
    [self.service getSmartDoorOpenRecordsWithCommunityId:houseModel.communityId
                                                  roomId:houseModel.roomId
                                                 success:^(NSArray<TuyaCommunitySmartDoorOpenRecordModel *> * _Nonnull models) {
        // do something
    } failure:^(NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];

Query access control QR code information

  • Returns an access control QR code. Users can scan the QR code on an access control device to open the door.
  • Returns a list of available access control devices and authorized elevator control devices.

API description

- (void)getCommunityQrCodeWithCommunityId:(NSString *)communityId
                                   roomId:(NSString *)roomId
                                  success:(void(^)(TuyaCommunityQRCodeModel *result))success
                                  failure:(void(^)(NSError *error))failure;

Request parameter

Parameter Description
communityId The community ID. You can call TuyaCommunityHouseModel to get the value.
roomId The room ID. You can call TuyaCommunityHouseModel to get the value.
success The success callback. The QR code information and available access control devices are returned.
failure The failure callback. An error message is returned.

Parameters of TuyaCommunityQRCodeModel

Parameter Description
qrCodeUrl The URL of a QR code.
expire The time when the QR code expires.
accessDoorList The list of available access control devices. Each element is a device name.
accessElevatorList The list of available elevator control devices. Each element is a device name.

Example

TuyaCommunityHouseModel *houseModel = <#A house returned by the house list query API method#>;
[self.service getCommunityQrCodeWithCommunityId:houseModel.communityId
                                         roomId:houseModel.roomId
                                        success:^(TuyaCommunityQRCodeModel * _Nonnull model) {
        UIImage *image = <#Converts `model.qrCodeUrl` into a QR code image#>;
        //do something
    } failure:^(NSError * _Nonnull error) {
        NSLog(@"error = %@",error);
    }];