1. Smart

Smart are divided into "one-click execution scene" and "automated scene", hereinafter referred to as "scene" and "automation", respectively.

Scene is user-added actions that is triggered manually; automation is that the user sets conditions and automatically executes the set actions when the conditions trigger.

Tuya Cloud supports users to set weather or equipment conditions according to actual life scene, and when the conditions are met, let one or more devices perform the corresponding tasks.

Scene Management Description
TuyaHomeSdk.newSceneInstance(String sceneId) Provides editing, deletion, and execution of a single scene, which needs to be initialized with the scene id. The scene id refers to the id field of SceneBean, which can be obtained from the return result of the Get Scene List interface.
TuyaHomeSdk.getSceneManagerInstance() It mainly provides all the data related to the conditions, tasks, equipment, and cities in the scene, and the scene list data acquisition.

Before using intelligent scene-related interfaces, you need to understand the two concepts of scene conditions and scene tasks.

1.1. Scene Condition

Scene conditions correspond to the SceneCondition class. Tuya Cloud supports the following condition types:

  • Meteorological conditions: including temperature, humidity, weather, PM2.5, air quality, sunset and sunrise. When the user selects meteorological conditions, he can select the current city.
  • Equipment condition: It means that the user can select the functional status of a device in advance. When the device reaches this state, the task in the current scene will be triggered, but the same device cannot be used as a condition and task at the same time to avoid operation conflicts.
  • Timing condition: It means that the scheduled task can be performed according to the specified time.

1.2. Scene Task

A scenario task refers to having one or more devices perform certain operations when the scenario meets the set weather or equipment conditions, corresponding to the SceneTask class. Or turn off and on an automation.

1.3. Smart Scene Management

1.3.1. Scene List Function

Declaration

Get scene list data. Scenarios are returned with automation, and scenarios and automation are distinguished by whether the conditions field is empty.

void getSceneList(long homeId,ITuyaDataCallback<List<SceneBean>> callback)

Parameters

Parameter Description
homeId Home id
callback Callback

Among them, the main attributes of SceneBean are defined as follows

Field Type Description
id Sting Scene id
name String Scene name
conditions List<SceneCondition> Scene condition list
actions List<SceneTask> Scene task list
matchType int The type that satisfies the condition. Any condition is 1 and all conditions are 2
enable boolean Whether automation is enabled

Example

TuyaHomeSdk.getSceneManagerInstance().getSceneList(long homeId, new ITuyaResultCallback<List<SceneBean>>() {
    @Override
    public void onSuccess(List<SceneBean> result) {
    }

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

1.3.2. Get Condition List

Declaration

Get a list of conditions, such as temperature, humidity, weather, PM2.5, sunset and sunrise, etc. Note: the device can also be used as a condition. The temperature in the conditions is divided into degrees Celsius and Fahrenheit, and the required data is passed in as required.

void getConditionList(boolean showFahrenheit,ITuyaResultCallback<List<ConditionListBean>> callback);

Parameters

Parameter Description
showFahrenheit True:Fahrenheit units,False:Celsius units
callback Callback

Example

TuyaHomeSdk.getSceneManagerInstance().getConditionList(new ITuyaDataCallback<List<ConditionListBean>>() {
    @Override
    public void onSuccess(List<ConditionListBean> conditionActionBeans) {
    }

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

Among them, the main attributes of ConditionListBean are defined as follows

Field Type Description
name Sting Condition name
type String Condition category
Property IProperty Condition attribute

Currently supported weather condition categories with their names and Property types

name Type Property Type
Temperature temp ValueProperty
Humidity humidity EnumProperty
Weather condition EnumProperty
PM2.5 pm25 EnumProperty
Air Quality aqi EnumProperty
Sunset/Sunrise sunsetrise EnumProperty
Timer timer TimerProperty

Property is a commonly used data structure in Tuya Smart, which can be used to control equipment and other functions. There are currently four types of Property: Numeric, Enumerated, Boolean, and Types for Timing (corresponding to Numeric, Enumerated, and Boolean in conditions). Each Property provides different access interfaces. See Rules Introduction for details.

1.3.3. Create Weather Conditions

Declaration

Weather conditions include temperature, humidity, weather, PM2.5, air quality, sunrise and sunset, and the city can be selected freely. The weather conditions that can be selected vary depending on the device in the user account.

SceneCondition createWeatherCondition(PlaceFacadeBean place, String type, Rule rule)

Parameters

Parameter Description
place Corresponding city weather. PlaceFacadeBean objects can be obtained from Get City List, Get cities based on latitude and longitude, Get cities based on city id interface. Currently, access to the city interface is only supported China.
type Condition type.
rule Conditional rules, see rule introduction

Example

 ValueRule tempRule = ValueRule.newInstance(
      "temp", 
      ">",    
      20       
  );
SceneCondition tempCondition = SceneCondition.createWeatherCondition(
      placeFacadeBean,   
      "temp",            
      tempRule          
  );

1.3.4. Create a Device-type Condition

Declaration

A device condition is when one device is in a certain state that triggers a scheduled task for another device or multiple devices. To avoid loop control, the same device cannot be used as a condition and task at the same time.

SceneCondition createDevCondition(DeviceBean devBean, String dpId, Rule rule)

Parameters

Parameter Description
devBean Conditional equipment. DeviceBean is obtained from the Get Condition Device List interface
dpId Condition dpId。
rule Condition rule

Example

BoolRule boolRule = BoolRule.newInstance(
    "dp1",    //"dp" + dpId
    true    //value
);
SceneCondition devCondition = SceneCondition.createDevCondition(
    devBean,    
    "1",        //dpId
    boolRule    //rule
);
SceneCondition createDevCondition(DeviceBean devBean, String dpId, Rule rule)

1.3.5. Create Timing Type Conditions

Declaration

Timing conditions refer to the execution of a scheduled task at a specified time

SceneCondition createTimerCondition(String display,String name,String type,Rule rule)

Parameters

Parameter Description
display User-selected time condition for display
name Name of timing condition
type Condition type
rule Conditional rules

Example

TimerRule timerRule = TimerRule.newInstance("Asia/Shanghai","0111110","16:00","20180310")
SceneCondition.createTimerCondition(
      "Monday, Tuesday, Wednesday, Thursday, Friday",
      "Working day timing",
      "timer",
      timerRule
      )

1.3.6. There Are Four Types of Rules

  • Numerical type

Taking temperature as an example, the final expression of the numerical condition is formatted as "temp > 20". You can get the currently supported temperature maximum, minimum and granularity (stepping) from the Obtain Condition List interface; you can get the supported temperature from the Obtain Condition List, etc. After the configuration is completed on the user interface, the ValueRule.newInstance method is invoked to build the rules, and the rules are used to form the conditions.

Example


  ValueProperty tempProperty = (ValueProperty) conditionListBean.getProperty();       

  int max = tempProperty.getMax();       //Maximum value
  int min = tempProperty.getMin();       //Minimum value
  int step = tempProperty.getStep();     //Granularity
  String unit = tempProperty.getUnit();  //Unit

//The temperature is greater than 20 ℃
  ValueRule tempRule = ValueRule.newInstance(
      "temp",  //Category
      ">",     //operational rule (">", "==", "<")
      20       //Critical value
  ); 
SceneCondition tempCondition = SceneCondition.createWeatherCondition(
      placeFacadeBean,   //City
      "temp",            //Category
      tempRule           //Rule
  );

  • Enumerated type

Taking the weather condition as an example, the final expression of the enumerated condition is formatted as "condition == rainy". You can get the currently supported weather conditions from the Obtain Condition List interface, including the code and name of each weather condition. After the configuration is completed on the user interface, the EnumRule.newInstance method is invoked to build the rules, and the rules are used to form the conditions.

Example

EnumProperty weatherProperty = (EnumProperty) conditionListBean.getProperty();  //Enumeration type Property
/** 
 *{
 *  {"sunny", " fine day"},
 *  {"rainy", "rainy day"}
 *} 
 */
 HashMap<Object, String> enums = weatherProperty.getEnums();
 //It's rainy.
 EnumRule enumRule = EnumRule.newInstance(
               "condition",  //Category 
               "rainy"        // Enumerated value selected
 );
 SceneCondition weatherCondition = SceneCondition.createWeatherCondition(
               placeFacadeBean,    //City
               "condition",        //Category
               enumRule            //Rule 
 );
  • Boolean type

Boolean types are common in device type conditions, and the final expression is formatted as "dp1 == true". You need to invoke the Obtain the condition device list interface to obtain devices that support the configuration of the smart scene, and then query the operations that the device can support based on the device id. See the Obtain Operations Supported by Device for details. After the configuration is completed on the user interface, the BoolRule.newInstance method is invoked to build the rules, and the rules are used to form the conditions.

Example


BoolProperty devProperty = (BoolProperty) conditionListBean.getProperty();  //布尔型Property

/**
{
  {true, “on"},
  {false, "off"}
}
*/
HashMap<Boolean, String> boolMap = devProperty.getBoolMap(); 

//当设备开启时
BoolRule boolRule = BoolRule.newInstance(
    "dp1",    //"dp" + dpId
    true    //bool of triggering conditions
);
SceneCondition devCondition = SceneCondition.createDevCondition(
    devBean,    //Device 
    "1",        //dpId
    boolRule    //Rule
);
  • Timer type

Timer is expressed as a Map type, that is Key: Value. After the user completes the timer configuration, the TimerRule.newInstance is invoked to complete the Map data assembly by the SDK to form the rule condition.

Example



TimerProperty timerProperty = (TimerProperty)conditionListBean.
getProperty();    //Timer-type property

//TimerRule.newInstance provides two construction methods, the difference is whether it will pass the time zone.
//If it does not pass the time zone, read default time zone.
/**
  * 
  * @param timeZoneId time zone, the format like "Asia/Shanghai”
  * @param loops 7-digit character string; each digit represents what day of the week; the first digit represents Sunday, and the second digit represents Monday.
  * By analogy, the character indicates on which days the timer is enabled. 0 indicates not selected; 1 indicates selected, with format like only Monday Selected.
  * Tuesday: "0110000"。 If they are not selected, it means that the timer is only executed once, with the format: "0000000"
  * @param time 24-hour system With format like "08:00", 
  * If the user uses the 12-hour system, the developer needs to convert it to a 24-hour system and upload it.
  * @param date, format like "20180310"
  * @return
 */
public static TimerRule newInstance(String timeZoneId,String loops,String time,String date);

//Create timer rule
TimerRule timerRule = TimerRule.newInstance("Asia/Shanghai","0111110","16:00","20180310") 

/**
 * The required parameters have the same meaning as the parameters of the above method, and the default time zone is read.
 * @param loops
 * @param time
 * @param date
 * @return
*/
public static TimerRule newInstance(String loops,String time,String date);

/**
  * Create timer conditions
  * @param display  is used to display the user-selected time conditions.
  * @param name  Name of Timer condition
  * @param type condition type
  * @param rule  condition regulations
  * @return
 */
public static SceneCondition createTimerCondition(String display,String name,String type,Rule rule);

//Create timer conditions, taking the Timer rule constructed above as an example.
SceneCondition.createTimerCondition(
"Monday, Tuesday, Wednesday, Thursday & Friday",Timer in work day",
"timer",
timerRule
)

1.3.7. Obtain The Condition Device List

Declaration

When selecting a scene condition, a device is selected, and a device dp list needs to be obtained according to the deviceId of the selected device, and then a certain dp function point is selected, that is, the device is designated to execute the dp function as the execution condition of the scene.

void getConditionDevList(long homeId, ITuyaResultCallback<List<DeviceBean>> callback);

Parameters

Parameter Description
homeId home id
callback callback

Example

TuyaHomeSdk.getSceneManagerInstance().getConditionDevList(homeId ,new ITuyaResultCallback<List<DeviceBean>>() {
    @Override
    public void onSuccess(List<DeviceBean> deviceBeans) {
    }

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

1.3.8. Get Device Task Based On Device Id

Declaration

It is used to obtain tasks that can be selected when selecting specific trigger conditions of the device.

void getDeviceConditionOperationList(String devId,ITuyaResultCallback<List<TaskListBean>> callback);

Parameters

Parameter Description
devId device id
callback callback

Example

TuyaHomeSdk.getSceneManagerInstance().getDeviceConditionOperationList(
    devId, //device id
    new ITuyaDataCallback<List<TaskListBean>>() {
        @Override
        public void onSuccess(List<TaskListBean> conditionActionBeans) {
        }

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

Among them, TaskListBean main attribute definition:

Field Type Description
name Sting dp point name for interface display
dpId long deivce dpId
tasks HashMap<Object, String> dp point configurable operation, format: {true, "opened"}, {false, "closed"}
type String Condition type bool, value, enum, etc.

1.3.9. Get City List

Declaration

Used to select cities when creating weather conditions. Note: Currently the city list only supports China.

void getCityListByCountryCode(String countryCode, ITuyaResultCallback<List<PlaceFacadeBean>> callback);

Parameters

Parameter Description
countryCode Country code , China = "cn"
callback callback

Example


TuyaHomeSdk.getSceneManagerInstance().getCityListByCountryCode(
    "cn",  //China
    new ITuyaResultCallback<List<PlaceFacadeBean>>() {
        @Override
        public void onSuccess(List<PlaceFacadeBean> placeFacadeBeans) {
        }

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

Among them, the main properties of the PlaceFacadeBean class are defined as follows:

Field Type Description
area Sting area name
province String province name
city String city name
cityId long cityId

1.3.10. Get Cities Based On Latitude and Longitude

Declaration

The city information is obtained according to the latitude and longitude, and is used to display the existing weather conditions.

void getCityByLatLng(String lon, String lat, ITuyaResultCallback<PlaceFacadeBean> callback);

Parameters

Parameter Description
lon Longitude
lat Latitude
callback callback

Example

TuyaHomeSdk.getSceneManagerInstance().getCityByLatLng(
    String.valueOf(longitude), //Longitude
    String.valueOf(latitude),   //Latitude
    new ITuyaResultCallback<PlaceFacadeBean>() {
        @Override
        public void onSuccess(PlaceFacadeBean placeFacadeBean) {
        }

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

1.3.11. Get Cities Based on City Id

Declaration

The city information is obtained according to the city id, and is used to display the existing weather conditions. The city id can be obtained in the get city list interface.

void getCityByCityIndex(long cityId, ITuyaResultCallback<PlaceFacadeBean> callback);

Parameters

Parameter Description
cityId City Id
callback callback

Example

TuyaHomeSdk.getSceneManagerInstance().getCityByCityIndex(
    cityId, //city id
    new ITuyaResultCallback<PlaceFacadeBean>() {
        @Override
        public void onSuccess(PlaceFacadeBean placeFacadeBean) {
        }

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

1.3.12. Scene Task

Scene task refer to control actions performed when conditions trigger. Tasks executable in manual scenarios include smart device type, group device type, automation scenario type and delay type. The executable actions of automation scenario include smart device type, group device type, manual scene type, automation scene type, delay type and message type. The tasks that users can set vary depending on the user’s device. Please note that not every product supports the scene.

1.3.13. 1.Create Device Type Action

Declaration

It is used to create device type actions.

SceneTask createDpTask(@NonNull String devId, HashMap<String, Object> tasks)

Parameters

Parameter Description
devId device id
tasks tasks to be implemented task format: { dpId: dp point value}

Example

HashMap<String, Object> taskMap = new HashMap<>();
taskMap.put("1", true); //Turn on the device
SceneTask task = TuyaHomeSceneManager.getInstance().createDpTask(
      devId,      //Device id
      taskMap     //Device action
);

1.3.14. A List of Devices Supported by Obtaining Execution Action

Declaration

Obtain a list of devices supporting scene actions for selecting to add to the action to be executed.

void getTaskDevList(long homeId, ITuyaResultCallback<List<DeviceBean>> callback);

Parameters

Parameter Description
homeId home id
callback callback

Among them, the main properties of DeviceBean are defined as follows:

Field Type Description
name String device name
productId String product id
devId String device id
iconUrl String icon url
isOnline Boolean Device online status, note: use this method to get device online status getIsOnline ()

Example

TuyaHomeSdk.getSceneManagerInstance().getTaskDevList(new ITuyaResultCallback<List<DeviceBean>>() {
    @Override
    public void onSuccess(List<DeviceBean> deviceBeans) {
    }

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

1.3.15. Obtain Executable Actions Based on Device Id

Declaration

It is used to obtain the tasks executed by the device when creating an action. The device id can be obtained from the a list of devices supported by obtaining execution action

void getDeviceTaskOperationList(String devId, ITuyaResultCallback<List<TaskListBean>> callback);

Parameters

Parameter Description
devId device id
callback callback

Among them, the main properties of TaskListBean are defined as follows:

Field Type Description
name Sting dp point name for interface display
dpId long Device dpId
tasks HashMap<Object, String> Obtain the operation configured by the dp point,Format::{true, "on"},{false, "off"}
type String Type of condition: bool, value, enum, etc.

Example

TuyaHomeSdk.getSceneManagerInstance().getDeviceTaskOperationList(
    devId, //device id
    new ITuyaResultCallback<List<TaskListBean>>() {
        @Override
        public void onSuccess(List<TaskListBean> conditionActionBeans) {
        }

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

1.3.16. 2.Create Group Device Type Action

Declaration

It is used to create group device type actions.

SceneTask createDpGroupTask(@NonNull long groupId, HashMap<String, Object> tasks);

Parameters

Parameter Description
groupId group id
tasks tasks to be implemented task format: { dpId: dp point value}

Example

HashMap<String, Object> taskMap = new HashMap<>();
taskMap.put("1", true); //Turn on the device
TuyaHomeSceneManager.getInstance().createDpGroupTask(
    groupId,     //group id
    taskMap     //Device action
);

1.3.17. A List of Group Devices to Get Execution Action Support

Declaration

Obtain a list of devices that support scenario actions, including common devices and group devices, for selecting the actions to be added to.

getTaskDevAndGoupList(long homeId, ITuyaResultCallback<SceneTaskGroupDevice> callback)

Parameters

Parameter Description
homeId home id
callback callback

Among them, the main properties of SceneTaskGroupDevice are defined as follows:

Field Type Description
devices List<DeviceBean> List of common devices
goups List< GroupBean> Group device list

Example

TuyaHomeSdk.getSceneManagerInstance().getTaskDevAndGoupList(homeId, new ITuyaResultCallback<SceneTaskGroupDevice>() {
                @Override
                public void onSuccess(SceneTaskGroupDevice sceneTaskGroupDevice) {
                    List<DeviceBean> deviceBeans = sceneTaskGroupDevice.getDevices();
                    List<GroupBean> groupBeans = sceneTaskGroupDevice.getGoups();
                    ...
                }

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

1.3.18. Obtain Executable Actions Based on Group Id

Declaration

It is used to obtain the tasks executed by the group device when creating an action. The group id can be obtained from the a list of group devices to get execution action support

void getDeviceTaskOperationListByGroup(String goupId, ITuyaResultCallback<List<TaskListBean>> callback)

Parameters

Parameter Description
groupId group id
callback callback

Example

TuyaHomeSdk.getSceneManagerInstance().getDeviceTaskOperationListByGroup(groupId, new ITuyaResultCallback<List<TaskListBean>>() {
                @Override
                public void onSuccess(List<TaskListBean> result) {

                }

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

                }
            });

1.3.19. 3.Create Scenario Type Action

Declaration

Scenario type actions are used to create scene type actions, including manual and automated scenarios. Parameters can be obtained through the scenario list interface

SceneTask createSceneTask(SceneBean sceneBean);

Parameters

Parameter Description
sceneBean scene object

Example

TuyaHomeSceneManager.getInstance().createSceneTask(scnenBean);

1.3.20. 4.Create Delay Type Action

Declaration

Used to create a delay-type action. SDK version supports maximum delay time of 300 minutes after 3.13.3, and only supports 59 minutes and 59s before 3.13.3

SceneTask createDelayTask(int minute, int second);

Parameters

Parameter Description
minute minutes
second seconds

Example

TuyaHomeSceneManager.getInstance().createDelayTask(
    2,  //minutes
    2    //seconds
);

1.3.21. 5、Create Message Type Action

Declaration

Used to create a message type action.

SceneTask createPushMessage();

Example

TuyaHomeSceneManager.getInstance().createPushMessage();

1.3.22. Sort Scene

Declaration

Manual scene or automation scene sorting. Note: Manual or automation scenes can only be sorted separately and cannot be shuffled.

void sortSceneList(long homeId, List<String> sceneIds, IResultCallback callback)

Parameters

Parameter Description
homeId home Id
sceneIds Scene id list
callback callback

Example

TuyaHomeSdk.getSceneManagerInstance().sortSceneList(
    homeId, //home id
    sceneIds,//Scene id list
    new IResultCallback() {
        @Override
        public void onSuccess() {
        }

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

1.3.23. Scene Background Images

Declaration

Get scene background images

 void getSceneBgs(ITuyaResultCallback<ArrayList<String>> callback);

Parameters

Parameter Description
callback callback

Example

TuyaHomeSdk.getSceneManagerInstance().getSceneBgs(new ITuyaResultCallback<ArrayList<String>>() {
        @Override
        public void onSuccess(ArrayList<String> strings) {

        }

        @Override
        public void onError(String s, String s1) {

        }
    });

1.4. Scene Operation

TuyaHomeSdk provides four operations for creating, modifying, executing, and deleting a single scene. In addition to creating other operations, the scene ID needs to be initialized. The scene ID can be obtained from the interface of obtaining the scene list interface.

1.4.1. Create Scene

Declaration

To add a scene, you need to pass in the Id of the family, the name of the scene, whether it is displayed on the homepage, the url of the background image, the condition list, the task list (at least one task), and the precondition list (valid time period, can not pass, the default is effective all day) , Executed when either or all of the conditions are met. You can also set only the name and task, background image, and no conditions, but you need to perform it manually.

Parameters

Parameter Description
homeId Home Id
name Scene name
stickyOnTop whether it is displayed on the homepage
background the url of the background image,Can only use the background image provided in the [Get Scene Background Picture List] (#GET_BGS) interface
preConditions Effective time period, which is passed in as a set of pre-condition objects, which may not be passed.
conditions Scene trigger conditions
tasks Scene execution tasks
matchType Condition match type, "AND" or "OR", default value: SceneBean.MATCH_TYPE_OR means that any condition is fulfilled, SceneBean.MATCH_TYPE_AND means that all conditions are met
callback callback

The PreCondition property is defined as follows

Field Type Description
id Sting The effective time period id. After the scene is created, it is automatically generated in the cloud, without manual setting.
condType String Please set PreCondition.TYPE_TIME_CHECK at present, which means the preset condition is the effective time period type
expr PreConditionExpr Precondition rule object

The PreConditionExpr property is defined as follows

Field Type Description
loops String A 7-character string, each of which indicates the day of the week, the first of which indicates Sunday, the second of which indicates Monday, and so on, and which days the automation takes effect. 0 means not selected, 1 means selected. For example, only Monday and Tuesday are selected: "0110000". If neither of them is selected, it means it only takes effect once. Format: "0000000"
start String Start time (only the TIMEINTERVAL_CUSTOM custom type setting will take effect)
end String End time (only the TIMEINTERVAL_CUSTOM custom type setting will take effect)
timeInterval String Effective time period type, PreCondition.TIMEINTERVAL_ALLDAY all day,TIMEINTERVAL_NIGHT night, TIMEINTERVAL_DAYTIME daytime,TIMEINTERVAL_CUSTOM custom
cityId String City Id, which can be obtained through [Get City List] (#GetCityList)
timeZoneId String Effective time zone
cityName String City ​​name

Example

//Data creation in effective period, can be empty
PreCondition preCondition = new PreCondition();
PreConditionExpr expr = new PreConditionExpr();
expr.setCityName("hangzhou");
expr.setCityId("xxxxx");//cityId Available via city list interface
expr.setStart("00:00");
expr.setEnd("23:59");
expr.setLoops("1111111");
expr.setTimeInterval(PreCondition.TIMEINTERVAL_ALLDAY);
preCondition.setCondType(PreCondition.TYPE_TIME_CHECK);
expr.setTimeZoneId(TimeZone.getDefault().getID());
preCondition.setExpr(expr);
List<PreCondition> preConditions = new ArrayList<>();
preConditions.add(preCondition);

TuyaHomeSdk.getSceneManagerInstance().createScene(
     100001,
    "Morning", //scene name
    "https://images.png"
    true,  //Whether to display on the homepage
    preConditions, //Effective period, may not be transmitted
    conditions, //condition
    tasks,     //task
    SceneBean.MATCH_TYPE_AND, //Execution condition type
    new ITuyaResultCallback<SceneBean>() {
        @Override
        public void onSuccess(SceneBean sceneBean) {
            Log.d(TAG, "createScene Success");
        }

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

1.4.2. Modify The Scene

Declaration

It is used to modify the scene. After it succeeded, it will return to new scene data.

void modifyScene(SceneBean sceneReqBean, ITuyaResultCallback<SceneBean> callback);

Parameters

Parameter Description
sceneReqBean Modified scene object

Example

sceneBean.setName("New name");  //Change Scene name
sceneBean.setConditions(Collections.singletonList(condition)); //Change scene conditions
sceneBean.setActions(tasks); //Change scene action

String sceneId = sceneBean.getId();  //Get the Scene id to initialize
TuyaHomeSdk.newSceneInstance(sceneId).modifyScene(
    sceneBean,  //Modified Scene data class
    new ITuyaResultCallback<SceneBean>() {
        @Override
        public void onSuccess(SceneBean sceneBean) {
            Log.d(TAG, "Modify Scene Success");
        }

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

1.4.3. Delete Scene

Declaration

For deleting scene

void deleteScene(IResultCallback callback);

Parameters

Parameter Description
callback callback

Example

String sceneId = sceneBean.getId();  

TuyaHomeSdk.newSceneInstance(sceneId).deleteScene(new 
IResultCallback() {
    @Override
    public void onSuccess() {
        Log.d(TAG, "Delete Scene Success");
    }

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

1.4.4. Execute Scene

Declaration

It is used to execute manual scene.

Note: This method only sends commands to the cloud execution scenario. If the specific device is executed successfully, you need to monitor the device's dp point change through TuyaHomeSdk.newDeviceInstance(devId).registerDevListener().

void executeScene(IResultCallback callback);

Parameters

Parameter Description
callback callback

Example

String sceneId = sceneBean.getId();  
TuyaHomeSdk.newSceneInstance(sceneId).executeScene(new IResultCallback() {
    @Override
    public void onSuccess() {
        Log.d(TAG, "Excute Scene Success");
    }

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

1.4.5. Turn On and Turn Off The Automation Scene

Declaration

It is used to turn on or off the automatic scene.

void enableScene(String sceneId, final IResultCallback callback);

void disableScene(String sceneId, final IResultCallback callback);

Parameters

Parameter Description
sceneId sceneId
callback callback

Example

String sceneId = sceneBean.getId();  

TuyaHomeSdk.newSceneInstance(sceneId).enableScene(sceneId,new 
IResultCallback() {
    @Override
    public void onSuccess() {
        Log.d(TAG, "enable Scene Success");
    }

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

TuyaHomeSdk.newSceneInstance(sceneId).disableScene(sceneId,new 
IResultCallback() {
    @Override
    public void onSuccess() {
        Log.d(TAG, "disable Scene Success");
    }

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

1.4.6. Erase

Declaration

If the user exits the activity of the scene, the scene destruction method should be invoked to reclaim the memory and enhance the experience.

Example

TuyaHomeSdk.getSceneManagerInstance().onDestroy();

TuyaHomeSdk.newSceneInstance(sceneId).onDestroy();

1.4.7. Register

Declaration

The monitoring of scene addition, editing, deletion, execution, opening and closing operations

void registerSmartUpdateListener(ISmartUpdateListener listener);

Parameters

Parameter Description
listener scene status listener

ISmartUpdateListener interface is as follows:

public interface ISmartUpdateListener {
    /**
     * Automatic scene update
     */
    void onSmartUpdateListener();

    /**
     * Recommended
     */
    void onCollectionsUpdateListener();
}

Example

TuyaHomeSdk.getSceneManagerInstance().registerSmartUpdateListener(new ISmartUpdateListener() {
            @Override
            public void onSmartUpdateListener() {

            }

            @Override
            public void onCollectionsUpdateListener() {

            }
        });

1.4.8. Unregister

When you do not need to listen to the scene, you can unregister the listener

Example

TuyaHomeSdk.getSceneManagerInstance().unRegisterSmartUpdateListener(mSmartUpdateListener);

1.4.9. Registration Scene Information Change listener

Declaration

Scene addition, editing, deletion, execution, monitoring of opening and closing operations

void registerSmartUpdateListener(ISmartUpdateListener listener);

Parameters

Parameter Description
listener listener

ISmartUpdateListener 接口如下:

public interface ISmartUpdateListener {
    /**
     * Automatic scene update
     */
    void onSmartUpdateListener();

    /**
     * Recommended scenes to add to the collection update
     */
    void onCollectionsUpdateListener();
}

Example

TuyaHomeSdk.getSceneManagerInstance().registerSmartUpdateListener(new ISmartUpdateListener() {
            @Override
            public void onSmartUpdateListener() {

            }

            @Override
            public void onCollectionsUpdateListener() {

            }
        });

1.4.10. 1.4.8. Unregister Scene Information Change Listener

Declaration

When the scene information change listener is not required, unregister the listener.

Example

TuyaHomeSdk.getSceneManagerInstance().unRegisterSmartUpdateListener(mSmartUpdateListener);

results matching ""

    No results matching ""