{"id":19858407,"url":"https://github.com/tuya/tuya-smart-securitymax-sample-kotlin","last_synced_at":"2025-06-24T10:34:45.298Z","repository":{"id":103228829,"uuid":"347815076","full_name":"tuya/tuya-smart-securitymax-sample-kotlin","owner":"tuya","description":"The Tuya Smart SecurityMax Sample provides a simple example for remote control and data monitoring of the Smart WiFi environment's alarm apparatus.","archived":false,"fork":false,"pushed_at":"2021-03-20T16:22:27.000Z","size":120,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-01-11T14:25:48.771Z","etag":null,"topics":["tuya"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tuya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-15T02:42:36.000Z","updated_at":"2021-08-05T06:33:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"d77c1331-bc5e-4424-ac77-6fcd1e088c29","html_url":"https://github.com/tuya/tuya-smart-securitymax-sample-kotlin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-smart-securitymax-sample-kotlin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-smart-securitymax-sample-kotlin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-smart-securitymax-sample-kotlin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-smart-securitymax-sample-kotlin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tuya","download_url":"https://codeload.github.com/tuya/tuya-smart-securitymax-sample-kotlin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241255123,"owners_count":19934815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["tuya"],"created_at":"2024-11-12T14:23:20.574Z","updated_at":"2025-02-28T22:21:08.393Z","avatar_url":"https://github.com/tuya.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tuya Smart SecurityMax Sample\n\n[English](README.md) | [中文版](README_zh.md) \n\nOverview\n------------------------\n\nThe Tuya Smart SecurityMax Sample provides a simple example for remote control and data monitoring of the Smart WiFi environment's alarm apparatus, which is built on the Tuya Iotos Embeded WiFi \u0026Ble SDK.\n\nThe Tuya Smart SecurityMax Sample has realized the following functions:\n\n- User management module (registration, login, password reset)\n- Default family creation\n- Equipment distribution network module (EZ distribution network mode)\n- Equipment control module (Smoke detection, gas detection, PM2.5 detection, formaldehyde detection, flame detection, etc.)\n\n|                      Smart SecurityMax                       |\n| :----------------------------------------------------------: |\n| \u003cimg src=\"https://images.tuyacn.com/app/aiwen/tuya-smart-security/device.png\" width=\"70%\" /\u003e |\n| [Smart SecurityMax Doc](https://developer.tuya.com/en/demo/environment-monitor) |\n\n\n### Related Hardware \u0026 Tuya IoTOS Embedded Github Demo\n\n- Device Demo documentation，please check Tuya Demo Center：https://developer.tuya.com/en/demo/environment-monitor\n\n- Evaluation Kits：[Sandwich Evaluation Kits](https://developer.tuya.com/en/docs/iot/device-development/tuya-development-board-kit/tuya-sandwich-evaluation-kits/-tuya-sandwich-evaluation-kits?id=K97o0ixytemvr)\n\n\n\nGet Started\n------------------------\n\n#### 1. Project configuration\n\n1、According to [Preparation for Integration](https://developer.tuya.com/en/docs/app-development/android-app-sdk/preparation?id=Ka7mqlxh7vgi9) document description, register Tuya developer account and complete the application To create, replace the package name of Sample with the package name set during creation.\n\n2、According to the [Integration SDK](https://developer.tuya.com/en/docs/app-development/android-app-sdk/integrated?id=Ka7mqm2xsvs4n) document description, integrate the security picture and reset the AppKey And AppSecret.\n\n#### 2. UI\n\nAfter completing the above project configuration, run the program, the App displays the various interfaces as follows:\n\n|                             Home                             |                           Register                           |                            Login                             |\n| :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |\n| \u003cimg src=\"https://images.tuyacn.com/app/aiwen/tuya-smart-security/home_en.jpg\" style=\"zoom:20%;\" /\u003e | \u003cimg src=\"https://images.tuyacn.com/app/aiwen/tuya-smart-planter/user_register_en.jpg\" style=\"zoom:20%;\" /\u003e | \u003cimg src=\"https://images.tuyacn.com/app/aiwen/tuya-smart-planter/user_login_en.jpg\" style=\"zoom:20%;\" /\u003e |\n|                        Reset Password                        |                          Home Page                           |                       User Information                       |\n| \u003cimg src=\"https://images.tuyacn.com/app/aiwen/tuya-smart-planter/user_reset_password_en.jpg\" style=\"zoom:20%;\" /\u003e | \u003cimg src=\"https://images.tuyacn.com/app/aiwen/tuya-smart-security/main_page_en.jpg\" style=\"zoom:20%;\" /\u003e | \u003cimg src=\"https://images.tuyacn.com/app/aiwen/tuya-smart-planter/user_info_en.jpg\" style=\"zoom:20%;\" /\u003e |\n|                           EZ Mode                            |                         Device List                          |                        Device Control                        |\n| \u003cimg src=\"https://images.tuyacn.com/app/aiwen/tuya-smart-planter/network_en.jpg\" style=\"zoom:20%;\" /\u003e | \u003cimg src=\"https://images.tuyacn.com/app/aiwen/tuya-smart-security/device_list_en.jpg\" style=\"zoom:20%;\" /\u003e | \u003cimg src=\"https://images.tuyacn.com/app/aiwen/tuya-smart-security/device_control_en.jpg\" style=\"zoom:20%;\" /\u003e |\n\n \n\n#### 3. User Management Module\n\nThe user management module involves user registration and login and password reset. For more information about user management and Api interface calls, please refer to [User Management](https://developer.tuya.com/en/docs/app-development/android-app-sdk/user-management/usermanage?id=Ka69qtzy9l8nc).\n\n##### 3.1 Get  verification code\n\n```java\n// phone\nTuyaHomeSdk.getUserInstance().getValidateCode(String countryCode, String phoneNumber, final IValidateCallback callback);\n\n// IValidateCallback\npublic interface IValidateCallback {\n    void onSuccess();\n\n    void onError(String code, String error);\n}\n\n// email\nvoid getRegisterEmailValidateCode(String countryCode, String email, IResultCallback callback);\n\n// IResultCallback\npublic interface IResultCallback {\n    void onError(String var1);\n    void onSuccess();\n}\n```\n##### 3.2 Registered\n\n```java\n// phone\nTuyaHomeSdk.getUserInstance().registerAccountWithPhone(final String countryCode, final String phoneNumber, final String passwd, final String code, final IRegisterCallback callback);\n\n// email \nTuyaHomeSdk.getUserInstance().registerAccountWithEmail(final String countryCode, final String email, final String passwd, final String code, final IRegisterCallback callback);\n\n// IRegisterCallback\npublic interface IRegisterCallback {\n    void onSuccess(User user);\n\n    void onError(String code, String error);\n}\n```\n\n##### 3.3 Login\n\n```java\n// phone\nTuyaHomeSdk.getUserInstance().loginWithPhonePassword(String countryCode, String phone, String passwd, final ILoginCallback callback);\n// email\nTuyaHomeSdk.getUserInstance().loginWithEmail(String countryCode, String email, String passwd, final ILoginCallback callback);\n\n// ILoginCallback\npublic interface ILoginCallback {\n    void onSuccess(User user);\n\n    void onError(String code, String error);\n}\n```\n\n##### 3.4 Logout\n\n```java\nTuyaHomeSdk.getUserInstance().logout(new ILogoutCallback() {\n  @Override\n  public void onSuccess() {\n    \n  }\n\n  @Override\n  public void onError(String errorCode, String errorMsg) {\n  }\n});\n```\n\n\u003e If it prompts insufficient permissions when registering or logging in, please check whether the project configuration steps are completed correctly.\n\n#### 四、Home Management Module\n\nBefore adding Tuya devices, you need to create a family. This Demo only creates a default family based on the user’s mobile phone information when the program is launched. For more information about family management and related API interfaces, please refer to [Home Management](https://developer.tuya.com/en/docs/app-development/android-app-sdk/home-management/homemanage?id=Ka6kjkgere4ae).\n\n##### 4.1 Get the family list\n\n```java\nvoid queryHomeList(ITuyaGetHomeListCallback callback)\n  \n // ITuyaGetHomeListCallback\npublic interface ITuyaGetHomeListCallback {\n    void onSuccess(List\u003cHomeBean\u003e homeBeans);\n\n    void onError(String errorCode, String error);\n}\n```\n\n##### 4.2 Create a family\n\n```java\nvoid createHome(String name, double lon, double lat, String geoName, List\u003cString\u003e rooms, ITuyaHomeResultCallback callback)\n  \n// ITuyaHomeResultCallback\npublic interface ITuyaHomeResultCallback {\n    void onSuccess(HomeBean bean);\n\n    void onError(String errorCode, String errorMsg);\n}\n```\n\n\n\n#### 5. Wi-Fi Network Configuration Mode\n\nThe Device supports EZ network distribution and AP network distribution in WiFi mode. This demo only provides EZ network distribution examples. For more equipment network configuration information and API interfaces, please refer to [Wi-Fi Network Configuration](https://developer.tuya.com/en/docs/app-development/android-app-sdk/wifinetwork?id=Ka6ki8lbwu82c).\n\nBefore the Wi-Fi network configuration, the SDK needs to obtain the network configuration Token from the Tuya Cloud.\nThe term of validity of Token is 10 minutes, and the Token becomes invalid once the network configuration succeeds.\nA new Token has to be obtained if you have to reconfigure the network.\n\n##### 5.1 **Get Network Configuration Token**\n\n```java\nTuyaHomeSdk.getActivatorInstance().getActivatorToken(homeId, \n        new ITuyaActivatorGetToken() {\n        \n            @Override\n            public void onSuccess(String token) {\n            \n            }\n            \n            @Override\n            public void onFailure(String s, String s1) {\n            \n            }\n        });\n```\n\n\n\n**Parameters**\n\n| Parameters | Description                                                  |\n| :--------- | :----------------------------------------------------------- |\n| homeId     | Family ID, please refer to the family management section for details |\n\n```java\nActivatorBuilder builder = new ActivatorBuilder()\n        .setSsid(ssid)\n        .setContext(context)\n        .setPassword(password)\n        .setActivatorModel(ActivatorModelEnum.TY_EZ)\n        .setTimeOut(timeout)\n        .setToken(token)\n        .setListener(new ITuyaSmartActivatorListener() {\n            \n                @Override\n                public void onError(String errorCode, String errorMsg) {\n                    \n                }\n                \n                @Override\n                public void onActiveSuccess(DeviceBean devResp) {\n                     //If multiple devices are activated at the same time, they will be called back multiple times\n                }\n                \n                @Override\n                public void onStep(String step, Object data) {\n                    \n                }\n            }\n        ));\n```\n\n**Parameters**\n\n| Parameters     | Description                                                  |\n| :------------- | :----------------------------------------------------------- |\n| token          | Activation key required for Configuration                    |\n| context        | context                                                      |\n| ssid           | WiFi ssid                                                    |\n| password       | WiFi password                                                |\n| activatorModel | Configuration Mode, EZ Mode: ActivatorModelEnum.TY_EZ        |\n| timeout        | Configuration timeout, default setting is 100s, unit is second |\n\n##### 5.2 Configuration method invocation\n\n```java\nITuyaActivator mTuyaActivator = TuyaHomeSdk.getActivatorInstance().newMultiActivator(builder);\n//Start configuration\nmTuyaActivator.start();\n//Stop configuration\nmTuyaActivator.stop(); \n//Exit the page to destroy some cache data and monitoring data.\nmTuyaActivator.onDestroy(); \n```\n\n\n\n#### 6. Device Management\n\nWhen the equipment is successfully configured, you can view the  device that has been configured in the equipment list. Select the equipment and enter the control panel. For more information about the equipment and API interface, please refer to [Device Management](https://developer.tuya.com/en/docs/app-development/android-app-sdk/device-management/devicemanage?id=Ka6ki8r2rfiuu).\n\n##### 6.1 Device List\n\nThe device control must first initialize the data, call the following method to obtain the device information under the family, and it is sufficient to initialize it once every time the APP is alive. In addition, the switching family also needs to be initialized:\n\n```java\nTuyaHomeSdk.newHomeInstance(homeId).getHomeDetail(new ITuyaHomeResultCallback() {\n    @Override\n    public void onSuccess(HomeBean homeBean) {\n    \t\n    }\n\n    @Override\n    public void onError(String errorCode, String errorMsg) {\n\n    }\n});\n```\n\nThe onSuccess method of this interface will return `HomeBean`, and then call `getDeviceList` of `HomeBean` to get the device list:\n\n```java\nList\u003cDeviceBean\u003e deviceList = homeBean.getDeviceList();\n```\n\n##### 6.2 Get all the function points of the device\n\n```java\nMap\u003cString, SchemaBean\u003e schemaBeanList = TuyaHomeSdk.getDataInstance().getSchema(int deviceId)\n```\n\n##### 6.3. Device control\n\nThe device control interface function is to send function points to the device to change the device state or function.\n\n```java\nITuyaDevice.publishDps(dps, callback);\n```\n\n**Parameters**\n\n| Parameters | Description                                               |\n| ---------- | --------------------------------------------------------- |\n| dps        | data points, device function point, format is json string                                                         |\n| callback   | Callback to send control instruction success              |\n\nThe dps attribute of the DeviceBean class defines the state of the device, and is called the data point (DP) or the function point. Each key in the dps dictionary refers to a dpId of a function point, and the dpValue is the value of the function point.\n\n**Command Format**\n\nThe control commands shall be sent in the format given below. {\"(dpId)\":\"(dpValue)\"}\n\n**Example**\n\nAssuming that the function point of the device that turns on the light is 101, the control code for turning on the light is as follows:\n\n```java\nmDevice.publishDps(\"{\\\"101\\\": true}\", new IResultCallback() {\n  @Override\n  public void onError(String code, String error) {\n      Toast.makeText(mContext, \"turn on the light failure\", Toast.LENGTH_SHORT).show();\n  }\n  @Override\n  public void onSuccess() {\n      Toast.makeText(mContext, \"turn on the light success\", Toast.LENGTH_SHORT).show();\n  }\n});\n```\n\nDP control points of alarm apparatus:\n\n1. Smoke detection status:\n2. The preheating:\n3. Gas detection status:\n4. PM2.5 readings\n5. Formaldehyde detection value\n6. Flame detection value\n\n##### 6.4. Remove device\n\nUsed to remove a device from the user device list\n\n```java\nvoid removeDevice(IResultCallback callback);\n```\n\n##### 6.5. Reset\n\nIt is used to reset the device and restore it to the factory state. After the device is restored to the factory settings, it will re-enter the network-ready state (quick connection mode), and the related data of the device will be cleared.\n\n```java\nvoid resetFactory(IResultCallback callback)；\n```\n\n\n\n## Issue Feedback\n\nYou can provide feedback on your issue via **Github Issue** or [Technical Support Council](https://service.console.tuya.com)\n\n## LICENSE\n\nTuya Android Home SDK Sample is available under the MIT license. Please see the [LICENSE]() file for more info.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuya%2Ftuya-smart-securitymax-sample-kotlin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftuya%2Ftuya-smart-securitymax-sample-kotlin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuya%2Ftuya-smart-securitymax-sample-kotlin/lists"}