Scene Recommendation

Last Updated on : 2024-07-18 10:10:59download

Scene recommendation is designed to improve connections between users and smart devices through scene services and enhance smart scene capabilities for the devices. This topic describes API methods for scene recommendation to implement a range of features. For example, get a list of recommended scenes, get a list of recommended scenes for a specific device, get details of a recommended scene, add a recommended scene, and remove a recommended scene. For more information about scene recommendation, see Scene Recommendation Management.

Get recommended scenes

API description

Get a list of recommended scenes. This API method is only applicable to apps developed based on App SDK v5.10.0 or later.

fun getUnifiedRecommendAll(                          
    relationId: Long,                                
    source: String,                                  
    size: Int = 10,                                  
    withAdded: Boolean = false,                      
    devId: String?,                                  
    recommendSource: String,                         
    callback: IResultCallback<List<RecommendScene>?>?
)                                                    

Parameters

Parameter Description
relationId The home ID.
source The source of the method call, fixed as TAB.
size (Optional) The number of recommended scene lists. The default is 10 items if not specified.
withAdded (Optional) Whether to return the added recommended scene. The default is false if not specified.
devId (Optional) The device ID. Pass null if not needed.
recommendSource The recommendation type to retrieve. For example, linkage,energy,warning, separated by a comma (,).
callback The callback.

The following table lists the properties of RecommendScene.

Field Type Description
id Long The ID of the recommended scene.
recommendId String The ID of the recommended scene. recommendId is recommended.
matchType Int The rules of matching conditions. Valid values:
  • 1: Scene actions are triggered when all conditions are met.
  • 0: Scene actions are triggered when any of the conditions are met.
ownerId String The home ID.
name String The scene name.
coverIcon String The URL of the scene icon.
background String The background image.
displayColor String The background color.
recomDescription String The description of the scene.
recomCoefficient Int The recommendation coefficient.
hotCount String The number of users who have accessed the recommended scene.
ruleGenre Int The type of linkage that triggers the scene.
conditions List<SceneCondition> The list of scene conditions.
actions List<SceneAction> The list of actions in the scene.

Example

ThingHomeSdk.getSceneServiceInstance().recommendService().getUnifiedRecommendAll(
   relationId,                                                     
    "TAB",                                                                       
    10,                                                                          
    false,                                                                       
    null,                                                                        
    "linkage,energy,warning",                                                    
    object : IResultCallback<List<RecommendScene>?> {                          
        override fun onSuccess(result: List<RecommendScene>?) {                  

        }                                                                        

        override fun onError(errorCode: String?, errorMessage: String?) {        

        }                                                                        
    })                                                                            

Get recommended scenes for a device

API description

Get a list of recommended scenes for a device. This API method is only applicable to apps developed based on App SDK v3.29.0 or later.

fun getRecommendsByDevice(
    relationId: Long,
    deviceId: String,
    size: Int,
    callback: IResultCallback<List<RecommendScene>?>?
)

Parameters

Parameter Description
relationId The home ID.
deviceId The device ID.
size The number of recommended scenes. For more information, see Scene Recommendation Rules.
callback The callback.

Example

  • For App SDK v3.34.5 and later:

    ThingHomeSdk.getSceneServiceInstance().recommendService().getRecommendsByDevice(
        relationId, devId, 3,                                                       
        object : IResultCallback<List<RecommendScene>?> {                         
            override fun onSuccess(result: List<RecommendScene>?) {                 
    
            }                                                                       
            override fun onError(errorCode: String?, errorMessage: String?) {       
    
            }                                                                       
        })                                                                           
    
  • For App SDK earlier than v3.34.5:

    TuyaHomeSdk.getSceneManagerInstance().getRecommendSceneListByDev(homeId, devId, 3, new ITuyaResultCallback<List<SceneBean>>() {
        @Override                                                                                                                  
        public void onSuccess(List<SceneBean> result) {                                                                            
    
        }                                                                                                                          
    
        @Override                                                                                                                  
        public void onError(String errorCode, String errorMessage) {                                                               
    
        }
    });
    

Get recommended scenes for multiple devices (including energy saving and alerts)

API description

Get the recommended scenes for multiple devices simultaneously, including those for energy saving and alerts. This API method is only applicable to apps developed based on App SDK v5.10.0 or later.

fun requestRecommendSceneWithDevList(
    relationId: Long,
    devIds: String,
    from: String? = null,
    callback: IResultCallback<DeviceRecommendScene?>?
)

Parameters

Parameter Description
relationId The home ID.
devIds The list of device IDs, separated by a comma (,). Example: "6cda1ca75a5a768f5czn9i,6cda1ca75a5a768f5czn9b"
from (Optional) The request source. The default is null if not specified.
callback The callback.

DeviceRecommendScene is a map structure with the device ID as the key and List<RecommendSceneData> as the value, containing the following properties.

Field Type Description
recommendId String The ID of the recommended scene.
libraryId String The template ID.
name String The scene name.
jumpType String The redirection type.
jumpUrl String The redirection link.
recommendSource String The source of the recommendation.
  • energy: Energy saving
  • linkage: Scene
  • warning: Alert
background String The background image.
displayColor String The background color.

Example

ThingHomeSdk.getSceneServiceInstance().recommendService().requestRecommendSceneWithDevList(relationId, devIds, null,
    object : IResultCallback<DeviceRecommendScene?> {                                                               
        override fun onSuccess(result: DeviceRecommendScene?) {                                                     

        }                                                                                                           

        override fun onError(errorCode: String?, errorMessage: String?) {                                           

        }                                                                                                           
    })                                                                                                               

Get recommended scenes for multiple devices

API description

Get the recommended scenes for multiple devices simultaneously. This API method is only applicable to apps developed based on App SDK v3.34.5 or later.

fun requestRecommendSceneWithDeviceIds(
    relationId: Long,
    devIds: String,
    source: Int,
    callback: IResultCallback<ArrayList<RecommendPlainScene?>?>
)

Parameters

Parameter Description
relationId The home ID.
devIds The list of device IDs, separated by a comma (,). Example: "6cda1ca75a5a768f5czn9i,6cda1ca75a5a768f5czn9b"
source The source.
  • 1: The recommended scenes are retrieved from the device list.
  • 2: The recommended scenes are retrieved from the device details page. This value is currently unavailable.
callback The callback.

Example

ThingHomeSdk.getSceneServiceInstance().recommendService().requestRecommendSceneWithDeviceIds(relationId, devIds, 1,
            object : IResultCallback<ArrayList<RecommendPlainScene?>?> {
                override fun onSuccess(result: ArrayList<RecommendPlainScene?>?) {

                }
                override fun onError(errorCode: String?, errorMessage: String?) {

                }
    })

Get details of a recommended scene

API description

Get the details of a recommended scene. This API method is only applicable to apps developed based on App SDK v3.34.5 or later.

fun requestRecommendDetail(
  relationId: Long,
  sceneId: String,
  callback: IResultCallback<RecommendScene?>?
)

Parameters

Parameter Description
relationId The home ID.
sceneId The ID of the recommended scene, corresponding to the recommendId field of RecommendScene.
callback The callback.

Example

ThingHomeSdk.getSceneServiceInstance().recommendService().requestRecommendDetail(
    relationId, recommendId,                                                     
    object : IResultCallback<RecommendScene?> {                                
        override fun onSuccess(result: RecommendScene?) {                        

        }                                                                        

        override fun onError(errorCode: String?, errorMessage: String?) {        

        }                                                                        
    })                                                                            

Add a recommended scene

API description

Add a recommended scene from the scene details page.

After the scene is added, refresh the list of recommended scenes and existing scenes. A scene will not be recommended once it is added to the list of existing scenes. This API method is only applicable to apps developed based on App SDK v3.21.0 or later.

fun handleRecommend(                    
    relationId: Long,                   
    sceneId: String,                    
    action: String,                     
    sceneData: NormalScene?,            
    callback: IResultCallback<Boolean?>?
)                                       

Parameters

Parameter Description
relationId The home ID.
sceneId The ID of the recommended scene, corresponding to the recommendId field of RecommendScene.
action The action to add or save the recommended scene.
sceneData The scene data in the edit area.
callback The callback.

Example

  • For App SDK v3.34.5 and later:

    ThingHomeSdk.getSceneServiceInstance().recommendService().handleRecommend(
        relationId, sceneId, "save", normalScene,                             
        object : IResultCallback<Boolean?> {                                
            override fun onSuccess(result: Boolean?) {                        
    
            }                                                                 
    
            override fun onError(errorCode: String?, errorMessage: String?) {
    
            }                                                                 
        })                                                                     
    
  • For App SDK earlier than v3.34.5:

    final SceneBean bean = new SceneBean();                                                                                     
    bean.setActions(smartSceneBean.getActions());                                                                               
    bean.setBackground(smartSceneBean.getBackground());                                                                         
    bean.setCode(smartSceneBean.getCode());                                                                                     
    bean.setConditions(smartSceneBean.getConditions());                                                                         
    bean.setEnabled(smartSceneBean.isEnabled());                                                                                
    bean.setStickyOnTop(smartSceneBean.isTop());                                                                                
    bean.setId(smartSceneBean.getId());                                                                                         
    bean.setName(smartSceneBean.getName());                                                                                     
    bean.setMatchType(smartSceneBean.getMatchType());                                                                           
    bean.setBoundForPanel(smartSceneBean.isBoundForPanel());                                                                    
    bean.setPreConditions(smartSceneBean.getPreConditions());                                                                   
    bean.setNewLocalScene(smartSceneBean.isNewLocalScene());                                                                    
    bean.setLocalLinkage(smartSceneBean.isLocalLinkage());                                                                      
    bean.setStickyOnTop(smartSceneBean.isTop());                                                                                
    bean.setHotCount(smartSceneBean.getHotCount());                                                                             
    bean.setDisplayColor(smartSceneBean.getCoverColor());                                                                       
    bean.setCoverIcon(smartSceneBean.getCoverIcon());                                                                           
    
    TuyaHomeSdk.getSceneManagerInstance().recommendSceneSave(homeId, Long.parseLong(bean.getId()), bean, new IResultCallback() {
        @Override                                                                                                               
        public void onError(String code, String error) {                                                                        
        }                                                                                                                       
    
        @Override                                                                                                               
        public void onSuccess() {                                                                                               
        }                                                                                                                       
    });                                                                                                                          
    

Remove a recommended scene

API description

Users remove an undesired recommended scene from the scene details page. The scene will disappear from the list of recommended scenes.

After the scene is removed, refresh the list of recommended scenes. The scene will no longer be recommended. This API method is only applicable to apps developed based on App SDK v3.21.0 or later.

fun handleRecommend(                    
    relationId: Long,                   
    sceneId: String,                    
    action: String,                     
    sceneData: NormalScene?,            
    callback: IResultCallback<Boolean?>?
)                                       

Parameters

Parameter Description
relationId The home ID.
sceneId The ID of the recommended scene, corresponding to the recommendId field of RecommendScene.
action The action to remove or cancel the recommended scene.
sceneData The scene data in the edit area. Pass null if not needed.
callback The callback.

Example

  • For App SDK v3.34.5 and later:

    ThingHomeSdk.getSceneServiceInstance().recommendService().handleRecommend(
        relationId, sceneId, "remove", null,                                  
        object : IResultCallback<Boolean?> {                                
            override fun onSuccess(result: Boolean?) {                        
    
            }                                                                 
    
            override fun onError(errorCode: String?, errorMessage: String?) {
    
            }                                                                 
        })                                                                     
    
  • For App SDK earlier than v3.34.5:

    TuyaHomeSdk.getSceneManagerInstance().recommendSceneRemove(homeId, sceneId, null, new IResultCallback() {
        @Override                                                                                            
        public void onError(String code, String error) {                                                     
        }                                                                                                    
    
        @Override                                                                                            
        public void onSuccess() {                                                                            
        }                                                                                                    
    });                                                                                                       
    

Dismiss a recommended scene

API description

Users remove an undesired recommended scene from the scene details page. The scene will disappear from the list of recommended scenes.

After the scene is removed, refresh the list of recommended scenes. The scene will no longer be recommended. This API method is only applicable to apps developed based on App SDK v5.5.0 or later.

fun dislikeRecommend(
  relationId: Long,
  recommendId: String,
  recommendSource: String,
  callback: IResultCallback<Boolean>?
)

Parameters

Parameter Description
relationId The home ID.
recommendId The ID of the recommended scene, corresponding to the recommendId field of RecommendScene.
recommendSource The source of the recommendation, corresponding to the recommendSource field of RecommendScene. Example: energy, linkage, or warning.
callback The callback.

Example

ThingHomeSdk.getSceneServiceInstance().recommendService().dislikeRecommend(
    relationId,                                                            
    recommendId, // Get from the recommended scene model, RecommendScene.getRecommendId              
    "linkage", //  Get from the recommended scene model, RecommendScene.getRecommendSource            
    object : IResultCallback<Boolean> {                                    
        override fun onSuccess(result: Boolean) {                          

        }                                                                  

        override fun onError(errorCode: String?, errorMessage: String?) {  

        }                                                                  
    })