Tuya BLE Lock Instructions - Tuya Smart - App Development
Tuya BLE Lock Instructions - Tuya Smart - App Development
Android App SDK > Extension SDK > Smart Lock SDK
Version: 20201231
Online Version
Contents
Contents
1 Term Explanation 1
2 Description 2
3 Member Management 3
3.1 Get Lock Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.2 Create Lock Member . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.3 Update Lock Member . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.4 Delete Lock Member . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
5 Dynamic Password 12
5.1 Get Dynamic Password . . . . . . . . . . . . . . . . . . . . . . . . . 12
7 Lock Records 16
7.1 Get Alarm Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
7.2 Get Unlocked Records . . . . . . . . . . . . . . . . . . . . . . . . . . 18
i
1 TERM EXPLANATION
1 Term Explanation
Term Explanation
1 / 35
2 DESCRIPTION
Term Explanation
2 Description
1 // init sdk
2 TuyaOptimusSdk .init( getApplicationContext ());
3 // get ITuyaLockManager
4 ITuyaLockManager tuyaLockManager = TuyaOptimusSdk . getManager ( ITuyaLo
5 ckManager .class );
6 // create ITuyaBleLock
7 ITuyaBleLock tuyaLockDevice = tuyaLockManager . getBleLock ( your_device
8 _id);
2 / 35
3 MEMBER MANAGEMENT
3 Member Management
The door lock can be divided into family members and non-family members. Family
members are concepts in the whole house intelligence, you can refer to the Family
Member Management for details.
Description
1 /**
2 * get lock users
3 */
4 public void getLockUsers ( final ITuyaResultCallback <List < BLELockUser >
5 > callback )
Parameters
3 / 35
3 MEMBER MANAGEMENT
Example
4 / 35
3 MEMBER MANAGEMENT
Note: For non-family members created here, family members needs to refer to
the document Family Member Management.
Description
1 /**
2 * add lock user
3 *
4 * @param userName userName
5 * @param allowedUnlock Whether allowed unlock with bluetooth
6 * @param permanent Whether the user is permanent
7 * @param effectiveTimestamp User effective time
8 * @param invalidTimestamp User invalid time
9 * @param avatarFile avatar
10 * @param callback callback
11 */
12 void addLockUser ( final String userName , boolean allowedUnlock , boole
13 an permanent , long effectiveTimestamp , long invalidTimestamp , File a
14 vatarFile , final ITuyaResultCallback <Boolean > callback );
Parameters
Parameter Description
5 / 35
3 MEMBER MANAGEMENT
Parameter Description
Example
SDK provides the function of modifying the members of the lock. The members
of the lock will interact with the hardware and require the device to maintain a
Bluetooth connection.
6 / 35
3 MEMBER MANAGEMENT
Description
1 /**
2 * update lock user
3 *
4 * @param userId userId
5 * @param userName userName
6 * @param allowedUnlock Whether allowed unlock with bluetooth
7 * @param permanent Whether the user is permanent
8 * @param effectiveTimestamp User effective time
9 * @param invalidTimestamp User invalid time
10 * @param avatarFile avatar
11 * @param callback callback
12 */
13 void updateLockUser ( final String userId , boolean allowedUnlock , fina
14 l String userName , final boolean permanent , long effectiveTimestamp ,
15 long invalidTimestamp , File avatarFile , final ITuyaResultCallback <B
16 oolean > callback );
Parameters
Parameter Description
userId user id
7 / 35
3 MEMBER MANAGEMENT
Parameter Description
Example
SDK provides the feature of deleting the member of the lock. The member of the
lock will interact with the hardware and delete all unlocking methods and passwords
of the user. The operation requires the device to maintain a bluetooth connection.
8 / 35
3 MEMBER MANAGEMENT
Description
1 /**
2 * delete lock user
3 * @param user user bean
4 * @param callback callback
5 */
6 public void deleteLockUser ( BLELockUser user , final ITuyaResultCallba
7 ck <Boolean > callback )
9 / 35
4 DEVICE BLUETOOTH CONNECTION STATUS
After the Bluetooth connection is established between the mobile phone and the
device, the door lock can be opened via Bluetooth.
Description
Determine whether the Bluetooth door lock is connected to the mobile phone.
The operations related to controlling the door lock basically need to call this interface
to judge, and the door lock must be online to operate.
1 /**
2 * @return if lock online , return true
3 */
4 public boolean isBLEConnected ()
Example
Description
If the door lock is not connected, call this interface to connect to the door lock
1 /**
2 * connect to lock
3 *
4 * @param connectListener callback BLE lock connect status
5 */
6 public void connect ( ConnectListener connectListener )
10 / 35
4 DEVICE BLUETOOTH CONNECTION STATUS
Parameters
Example
11 / 35
5 DYNAMIC PASSWORD
5 Dynamic Password
Use the SDK to get a dynamic password and enter it on the door lock to unlock. The
dynamic password is valid for 5 minutes.
Description
Example
12 / 35
5 DYNAMIC PASSWORD
13 / 35
6 BLUETOOTH UNLOCK & LOCK
Description
After the door lock is connected with the app, you can call this interface to unlock
it.
1 /**
2 * unlock the door
3 */
4 public void unlock ( String lockUserId )
Parameters
Parameter Description
All users will have a corresponding id in the door lock, the id starts from 1, and the
number will increase by one for each new user added.
Example
14 / 35
6 BLUETOOTH UNLOCK & LOCK
Description
1 /**
2 * lock the door
3 */
4 public void lock ()
Example
15 / 35
7 LOCK RECORDS
7 Lock Records
Description
1 /**
2 * get alarm records
3 * @param offset page number
4 * @param limit item count
5 * @param callback callback
6 */
7 void getAlarmRecords (int offset , int limit , final ITuyaResultCallbac
8 k<Record > callback );
Parameters
Parameter Description
Parameters in callback
Record Description
DataBean Description
16 / 35
7 LOCK RECORDS
Example
17 / 35
7 LOCK RECORDS
Description
1 /**
2 * get unlock records
3 * @param unlockTypes unlock type list
4 * @param offset page number
5 * @param limit item count
6 * @param callback callback
7 */
8 void getUnlockRecords (int offset , int limit , final ITuyaResultCallba
9 ck <Record > callback );
Parameters
Parameter Description
Example
18 / 35
8 UNLOCK MODE MANAGEMENT
This section provides interfaces for setting, modifying, and deleting unlocking meth-
ods.
The following figure shows the interactive process of adding an unlock method:
1 sequenceDiagram
2 SDK ->>Lock: Connect
3 Note left of Lock: Connect via Bluetooth
4 Lock -->>SDK: Connect success
5 SDK ->>Lock: Add unloack mode
6 Lock -->>SDK: Success
7 SDK ->> Server : Notify to server
8 loop save info
9 Server ->> Server :
10 end
11 Server -->>SDK: Success
Description
1 /**
2 * get unlock mode by unlockType
3 *
4 * @param unlockType unlock type { @link com.tuya. smart . optimus .lock.
5 api. TuyaUnlockType }
6 * @param callback callback
7 */
8 void getUnlockModeList ( String unlockType , final ITuyaResultCallback <
9 ArrayList <UnlockMode >> callback );
Parameters
19 / 35
8 UNLOCK MODE MANAGEMENT
Example
20 / 35
8 UNLOCK MODE MANAGEMENT
The interfaces for adding, modifying, and deleting unlocking methods are all asyn-
chronous calls and all return from this interface.
Description
21 / 35
8 UNLOCK MODE MANAGEMENT
22 / 35
8 UNLOCK MODE MANAGEMENT
Parameters
/** Delete */
23 / 35
8 UNLOCK MODE MANAGEMENT
int STAGE_BEFORE =
-1;// Before interacting
with the door lock, such
as sending commands
and interacting with the
server
int STAGE_START =
0x00; // start
int STAGE_CANCEL =
0xFE;// cancel
int STAGE_FAILED =
0xFD;// failed
int STAGE_ENTERING =
0xFC;// entering
int STAGE_SUCCESS =
0xFF;// success
24 / 35
8 UNLOCK MODE MANAGEMENT
Example
25 / 35
8 UNLOCK MODE MANAGEMENT
26 / 35
8 UNLOCK MODE MANAGEMENT
Description
1 /**
2 * Add unlock method .
3 *
4 * @param unlockType TuyaUnlockType { @link com.tuya.smart . optimus .lo
5 ck.api. TuyaUnlockType }
6 * @param user BLELockUser { @link com.tuya. smart .sdk. optimus .l
7 ock.bean.ble. BLELockUser }
8 * @param name Unlock mode name.
9 * @param password Unlock password . If it is not the password unlo
10 ck type , this field can be null
11 * @param times Number of times the unlock mode can be used. Th
12 e value range is 0 to 254 , 0 means unlimited times , and 1 ~ 254 is t
13 he actual number of times .
14 * @param isHijack Hijack flag. If it is true , a hijacking alarm w
15 ill be triggered when unlocking with this unlock mode.
16 */
17 void addUnlockMode ( final String unlockType , final BLELockUser user ,
18 String name , String password , int times , boolean isHijack );
Parameters
Parameter Description
27 / 35
8 UNLOCK MODE MANAGEMENT
Parameter Description
Example
Description
Update the name of the unlock mode and modify the hijacking mark.
This interface does not interact with the door lock, only communicates with the
server.
28 / 35
8 UNLOCK MODE MANAGEMENT
1 /**
2 * Update name and hijack flag of the unlocking method . Only update
3 server information , not communicate with door lock device
4 *
5 * @param unlockMode UnlockMode bean {@link com.tuya. smart .sdk. optim
6 us.lock.bean.ble. UnlockMode }
7 * @param name Unlock mode name
8 * @param isHijack Hijack flag. If it is true , a hijacking alarm w
9 ill be triggered when unlocking with this unlock mode.
10 */
11 void updateUnlockModeServerInfo ( UnlockMode unlockMode , String name ,
12 boolean isHijack );
Parameters
Parameter Description
Example
29 / 35
8 UNLOCK MODE MANAGEMENT
Description
1 /**
2 * Delete unlockMode .
3 *
4 * @param unlockMode unlockMode
5 */
6 void deleteUnlockMode ( UnlockMode unlockMode );
Example
Description
30 / 35
8 UNLOCK MODE MANAGEMENT
1 /**
2 * Cancel fingerprint entry .
3 * <p>
4 * The fingerprint entry process will be repeated multiple times and
5 can be cancelled during the entry process .
6 *
7 * @param user BLELockUser { @link com.tuya. smart .sdk. optimus .lock.be
8 an.ble. BLELockUser }
9 */
10 void cancelFingerprintUnlockMode (final BLELockUser user);
Description
The password can be updated after the unlock mode of the password type is set.
You can call this interface to modify the password name, password, unlock times,
and hijack mark.
Note: Only the password type supports calling this interface.
1 /**
2 * Update the name , password , validity period and other information
3 of the unlocking method
4 *
5 * @param unlockMode UnlockMode bean {@link com.tuya. smart .sdk. optim
6 us.lock.bean.ble. UnlockMode }
7 * @param name Unlock mode name
8 * @param password Unlock password . If it is not the password unlo
9 ck method , this field can be null
10 * @param times Number of times the unlock mode can be used. Th
11 e value range is 0 to 254 , 0 means unlimited times , and 1 ~ 254 is t
12 he actual number of times .
13 * @param isHijack Hijack flag. If it is true , a hijacking alarm w
14 ill be triggered when unlocking with this unlock mode.
15 */
16 void updatePasswordUnlockMode ( UnlockMode unlockMode , String name , St
17 ring password , int times , boolean isHijack );
31 / 35
8 UNLOCK MODE MANAGEMENT
Parameters
Parameter Description
Example
32 / 35
9 BLE DOOR LOCK FUNCTION POINTS
dp name dp code
33 / 35
9 BLE DOOR LOCK FUNCTION POINTS
dp name dp code
language language
34 / 35
9 BLE DOOR LOCK FUNCTION POINTS
dp name dp code
35 / 35