1. Scene BizBundle

1.1. Features Overview

Smart divides into scene or automation actions.

Scene is a condition that users add actions and it is triggered manually; Automation action is a action set by users, and the set action is automatically executed when the condition is triggered.

The Tuya Cloud allows users to set meteorological or device conditions based on actual scenes in life, and if conditions are met, one or multiple devices will carry out corresponding tasks.

1.2. Integrate

1.2.1. Create project

Create your project in Android Studio, connect to the public SDK and configure Biz Bundle Framework

1.2.2. module's build.gradle configuration

dependencies {
  implementation 'com.tuya.smart:tuyasmart-bizbundle-scene:3.22.0-6'
}

1.3. Service Protocol

1.3.1. Provide services

The scene biz bundle implements ITuyaSceneBusinessService to provide services.

Example

 //Get scene bizbundle service
ITuyaSceneBusinessService iTuyaSceneBusinessService = MicroContext.findServiceByInterface(ITuyaSceneBusinessService.class.getName());

1.3.2. Create Scene

Enter the scene adding page by getting the family ID

Declaration

Go to create scene page

ITuyaSceneBusinessService.addScene(Activity activity, long homeId, int requestCode);;

Parameters

Parameter Description
activity Activity Object
homeId The family ID is obtained through the home SDK interface
requestCode Request code, bring back in onActivityResult

Example

if(null != iTuyaSceneBusinessService && homeId != 0){
  iTuyaSceneBusinessService.addScene(activity, homeId, requestCode);
}

1.3.3. Edit Scene

Enter scene edit page by obtaining scene data and family ID

Declaration

Enter edit scene

ITuyaSceneBusinessService.editScene(Activity activity, long homeId,SceneBean sceneBean, int requestCode);;

Parameters

Parameter Description
activity Activity Object
homeId The family ID is obtained through the home SDK interface
SceneBean Scene data object, obtained through SDK Get Scene List interface
requestCode Request code, bring back in onActivityResult

Example

TuyaHomeSdk.getSceneManagerInstance().getSceneList(homeId, new ITuyaResultCallback<List<SceneBean>>() {
            @Override
            public void onSuccess(List<SceneBean> result) {
                if(!result.isEmpty()){
                    SceneBean sceneBean = result.get(0);
                    if(null != iTuyaSceneBusinessService){
                        iTuyaSceneBusinessService.editScene(SceneActivity.this, homeId, sceneBean, requestCode);
                    }
                }
            }

            @Override
            public void onError(String errorCode, String errorMessage) {

            }
        });

1.3.4. Set geographic location

The conditions of the scene and the effective time period need to set the geographic location of the app. If it is not set, the city information will not be automatically obtained when the condition is selected, but it can still be selected on the city list.

Declaration

Set scene conditions‘s location

ITuyaSceneBusinessService.setAppLocation(double longitude, double latitude);

Parameters

Parameter Description
longitude Longitude,Long-distance business app provides access to related tripartite maps
latitude Latitude,Provide relevant three-party maps for self-service access

Example


if(null != iTuyaSceneBusinessService){           
    iTuyaSceneBusinessService.setAppLocation(lng, lat);
}

1.3.5. Set App Map Class

The geographical location in the scene conditions, if you do not need a foreign account, you do not need to call, you need to set the map category in the foreign account, do not set the default to get the domestic city interface

Declaration

Set App Map Class

ITuyaSceneBusinessService.setMapActivity(Class activity);

Parameters

Parameter Description
Class Map Activity class object

Example

if(null != iTuyaSceneBusinessService){

            iTuyaSceneBusinessService.setMapActivity(MapActivity.class);
        }

1.3.6. Save map selection data

After accessing the map class, you need to send the map selection data to the service package to update the conditional geographic location information

Declaration

Set up map data

ITuyaSceneBusinessService.saveMapData(double longitude, double latitude,String city, String address);

Parameters

Parameter Description
longitude longitude
latitude latitude
city city
address address

Example

if(null != iTuyaSceneBusinessService){    
   iTuyaSceneBusinessService.saveMapData(lng, lat, city, address);
 }

results matching ""

    No results matching ""