Scene Control

Last Updated on : 2023-02-13 03:26:03download

The scene created with the Tap-to-Run feature on the mobile app is synchronized to the central control device for device control and status synchronization. This topic describes the APIs used in scene control.

Get the scene list

Function prototype OPERATE_RET tuya_scene_info_list_get(OUT TUYA_SCENE_INFO_S **pp_list, OUT UINT_T *p_cnt)
Function description Get the scene list
Parameter pp_list: The scene list.

p_cnt: The number of scene lists.
Return value OPERATE_RET, 0: Success. Other values: Failure. See the error code.
Detailed description Call tuya_scene_info_list_free to free resources.

Example

UINT_T count = 0;
TUYA_SCENE_INFO_S *scene = NULL;
OPERATE_RET op_ret = OPRT_OK;
op_ret = tuya_scene_info_list_get(&scene, &count);
PR_DEBUG("op_ret===================================%d count:%d", op_ret, count);
if (op_ret == OPRT_OK && scene){
    for (i = 0; i < count; i++){
        PR_DEBUG("scene[%d]: id:%s, name:%s, icon_path:%s", i, scene[i].id, scene[i].name, scene[i].icon_path);
    }
}

Free the scene list

Function prototype OPERATE_RET tuya_scene_info_list_free(IN TUYA_SCENE_INFO_S *p_list, IN UINT_T p_cnt)
Function description Get the scene list.
Parameter pp_list: The scene list.

p_cnt: The number of scene lists.
Return value OPERATE_RET, 0: Success. Other values: Failure. See the error code.
Detailed description -

Example

if (count > 0 && NULL != scene) {
    tuya_scene_info_list_free(scene, count);
}

Synchronize the scene

Function prototype OPERATE_RET tuya_scene_sync()
Function description Synchronize the scene.
Parameter VOID
Return value OPERATE_RET, 0: Success. Other values: Failure. See the error code.
Detailed description -

Run the scene

Function prototype OPERATE_RET tuya_scene_triggle(IN CHAR_T *id, OUT TUYA_SCENE_DEV_STAT_E *status)
Function description Run the specified scene.
Parameter id: The scene ID.

status: The scene status.
Return value OPERATE_RET, 0: Success. Other values: Failure. See the error code.
Detailed description -

Example

TUYA_SCENE_DEV_STAT_E result;
tuya_scene_triggle(id, &result);
PR_DEBUG("scene action result is %d", result);