设备品类控制

更新时间:2023-02-14 08:51:20下载pdf

同步设备或房间

函数原型 OPERATE_RET tuya_ctrl_center_sync()
函数描述 同步设备、房间
参数说明 VOID
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 本 API 仅同步设备与房间,常与场景同步 tuya_scene_sync 搭配使用。

获取设备列表

函数原型 OPERATE_RET tuya_get_dev_brief_info_list(OUT TUYA_DEV_BRIEF_INFO_S **pp_list, OUT UINT_T *p_cnt)
函数描述 获取设备列表
参数说明
  • 出参
    • pp_list:设备列表
    • p_cnt:设备列表的数量
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 需要调用 tuya_dev_brief_info_list_free 释放

用法示例

TUYA_DEV_BRIEF_INFO_S* dev_list;
UINT_T dev_count = 0;
OPERATE_RET result = tuya_get_dev_brief_info_list(&dev_list, &dev_count);
if (OPRT_OK != result) {
    PR_ERR("tuya_get_dev_brief_info_list failed %d", result);
    return OPRT_COM_ERROR;
}

释放设备列表

函数原型 OPERATE_RET tuya_dev_brief_info_list_free(IN TUYA_DEV_BRIEF_INFO_S *p_list, IN UINT_T *p_cnt)
函数描述 释放设备列表
参数说明
  • 入参
    • p_list:设备列表
    • p_cnt:设备列表的数量
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 -

获取房间列表

函数原型 OPERATE_RET tuya_get_room_info_list(OUT TUYA_ROOM_INFO_S **pp_list, OUT UINT_T *p_cnt)
函数描述 获取房间列表
参数说明
  • 出参
    • pp_list:房间列表
    • p_cnt:房间列表的数量
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 需要调用 tuya_room_info_list_free 释放

用法示例

int result;
UINT_T room_count = 0;
TUYA_ROOM_INFO_S *room_list;

result = tuya_get_room_info_list(&room_list, &room_count);
if (OPRT_OK != result) {
    PR_ERR("tuya_get_room_info_list failed %d", result);
    return OPRT_COM_ERROR;
}
if (home->room_list && home->room_count) {
    tuya_room_info_list_free(home->room_list, home->room_count);
}
home->room_list   = room_list;
home->room_count  = room_count;

释放房间列表

函数原型 OPERATE_RET tuya_room_info_list_free(IN TUYA_ROOM_INFO_S *p_list, IN UINT_T cnt)
函数描述 释放房间列表
参数说明
  • 入参
    • p_list:房间列表
    • cnt:房间列表的数量
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 -

用法示例

if (home->room_list && home->room_count) {
    tuya_room_info_list_free(home->room_list, home->room_count);
}

打开指定设备

函数原型 TY_HOME_CTRL_DEV_T tuya_home_ctrl_dev_open(IN CONST CHAR_T* dev_id, IN CONST TY_HOME_CTRL_DEV_CB* dev_cb)
函数描述 打开指定设备
参数说明
  • 入参
    • dev_id:设备 ID
    • report_cb:设备回调接口
返回值 TY_HOME_CTRL_DEV_T:设备描述符
详细描述 需要调用 tuya_home_ctrl_dev_close 关闭

用法示例

void callback_fun(const TY_HOME_CTRL_DEV_DP_S* dp, void* user_arg)
{
    DEV_INFO *dev_info = (DEV_INFO *)user_arg;

    printf("dev_id:%s", dev_info->dev_id);

    bool_value = true;
    tuya_home_ctrl_dev_set_dp_value(dev_info->dev_des, HOME_CTRL_SWITCH_SWITCH_INDEX(1), PROP_BOOL,
                                    (TY_HOME_CTRL_DEV_DP_VALUE_U *)(&bool_value));
}

typedef struct {
    char *dev_id;
    TY_HOME_CTRL_DEV_T dev_des;
} DEV_INFO;

DEV_INFO dev[255];

// 如果需要控制红外设备,请注意实现该回调接口
void __dps_update_fun(void *user_arg)
{
// reopen dev
tuya_home_ctrl_dev_close(dev_des);
tuya_home_ctrl_dev_open[dev_des], &dev_cb);
}

TY_HOME_CTRL_DEV_CB dev_cb = {0}; // 需要初始化函数指针为空
dev_cb.report_cb.function = __dp_callback_fun; // dp 变化后的回调函数
dev_cb.dev_online_cb.function = __dev_online_cb; // 设备上下线的回调函数
dev_cb.dp_name_update_cb.function = __dp_name_fun; // dp 名称变化后的回调函数
dev_cb.dps_update_cb.function = __dps_update_fun; // dp 数量等变化后的回调函数

for (int i = 0; i < sizeof(dev) / sizeof(dev[0]; i++) {
    dev_cb.report_cb.user_arg = &(dev[i]);
    dev[i].dev_des = tuya_home_ctrl_dev_open[dev[i].dev_id], &dev_cb);
}

3.4.2 版本开始,open 支持多实例。多次 open 同一个 dev_id,会返回多个句柄,但是指向同一片内存,当且仅当同一个 dev_id 的所有句柄都 close 后,内存才会被释放。3.4.2 之前的版本,仅支持单实例,open 同一个 dev_id,会返回相同的句柄。请注意代码适配。

关闭指定设备

函数原型 OPERATE_RET tuya_home_ctrl_dev_close(IN TY_HOME_CTRL_DEV_T dev_des)
函数描述 关闭指定设备
参数说明
  • 入参
    • dev_des:设备描述符
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 -

获取设备所有 DP

函数原型 OPERATE_RET tuya_home_ctrl_dev_get_all_dp(IN CONST TY_HOME_CTRL_DEV_T dev_des, OUT BYTE_T* dp_num, OUT TY_HOME_CTRL_DEV_DP_S** dp_sets)
函数描述 获取设备所有 DP
参数说明
  • 入参
    • dev_des:设备描述符
  • 出参
    • dp_num:DP 数量
    • dp_sets:DP 集合
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 -

用法示例

TY_HOME_CTRL_DEV_T dev_info = tuya_home_ctrl_dev_open(dev_id, &dev_cb);

BYTE_T                   dp_num;
TY_HOME_CTRL_DEV_DP_S* dp_sets;
OPERATE_RET              ret = tuya_home_ctrl_dev_get_all_dp(dev_info, &dp_num, &dp_sets);
if (ret != OPRT_OK) {
    PR_ERR("tuya_home_ctrl_dev_get_all_dp err:%d", ret);
    ret = tuya_home_ctrl_dev_close(dev_info);
    return;
}

PR_DEBUG("dev_id:%s, support %d dps:", dev_id, dp_num);
for (BYTE_T i = 0; i < dp_num; i++) {
    tuya_home_ctrl_dev_show_dp(&(dp_sets[i]));
}

ret = tuya_home_ctrl_dev_close(dev_info);
if (ret != OPRT_OK) {
    PR_ERR("tuya_home_ctrl_light_close err:%d, dev_id:%s", ret, dev_id);
    return;
}

获取设备指定 DP

函数原型 OPERATE_RET tuya_home_ctrl_dev_get_dp_value(IN CONST TY_HOME_CTRL_DEV_T dev_des, IN CONST CHAR_T* dp_code, OUT CONST TY_HOME_CTRL_DEV_DP_S** dp_info)
函数描述 获取设备指定 DP
参数说明
  • 入参
    • dev_des:设备描述符
    • dp_code:DP
  • 出参
    • dp_value:值
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 -

用法示例

TY_HOME_CTRL_DEV_T dev_info = tuya_home_ctrl_dev_open(dev_id, &dev_cb);
CONST TY_HOME_CTRL_DEV_DP_S* dp_info;
tuya_home_ctrl_dev_get_dp_value(dev_info, HOME_CTRL_LIGHT_SWITCH_LED, &dp_info);
tuya_home_ctrl_dev_show_dp(dp_info);

ret = tuya_home_ctrl_dev_close(dev_info);
if (ret != OPRT_OK) {
    PR_ERR("tuya_home_ctrl_light_close err:%d, dev_id:%s", ret, dev_id);
    return;
}

设置设备指定 DP

函数原型 OPERATE_RET tuya_home_ctrl_dev_set_dp_value(IN CONST TY_HOME_CTRL_DEV_T dev_des, IN CONST CHAR_T* dp_code, IN TY_HOME_CTRL_DEV_DP_DATA_TP_E dp_type, IN CONST TY_HOME_CTRL_DEV_DP_VALUE_U* dp_value)
函数描述 获取设备指定 DP
参数说明
  • 入参
    • dev_des:设备描述符
    • dp_code:DP
    • dp_type:DP 值的类型
    • dp_value:值
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 设置整型 DP,建议使用 TY_BASE_DP_DATA_TP_VALUE_SACLE

用法示例

TY_HOME_CTRL_DEV_T dev_info = tuya_home_ctrl_dev_open(dev_id, &dev_cb);
BOOL_T bool_value = true;
tuya_home_ctrl_dev_set_dp_value(dev_info, HOME_CTRL_LIGHT_SWITCH_LED, PROP_BOOL, (TY_HOME_CTRL_DEV_DP_VALUE_U*)(&bool_value));

ret = tuya_home_ctrl_dev_close(dev_info);
if (ret != OPRT_OK) {
    PR_ERR("tuya_home_ctrl_light_close err:%d, dev_id:%s", ret, dev_id);
    return;
}
	/* 获取设备 DP 时,INT 类型 DP 有 prop_value.scale 属性
	scale_true 为云端下发的 DP 缩放属性
{"unit":"℃","min":160,"max":300,"scale":1,"step":5}
	1.当 scale_set>scale_true 实际 value_true=value_set/pow(10,scale_set-scale_true)
	2.当 scale_set<scale_true 实际 value_true=value_set*pow(10,scale_true-scale_set)
	3.当 scale_true=scale_set 不处理 */
//设置温度为 18 度,scale_set>scale_true,实际 value_true=18*pow(10,1)=180
    TY_HOME_CTRL_SCALE_INTEGER temp_scale_value;
    temp_scale_value.value = 18;
    temp_scale_value.scale = 0;
    tuya_home_ctrl_dev_set_dp_value(dev_info, HOME_CTRL_LIGHT_BRIGHT, TY_BASE_DP_DATA_TP_VALUE_SACLE,
           (TY_HOME_CTRL_DEV_DP_VALUE_U*)(&temp_scale_value));

不同品类设备支持的 DP

本章节包含 DP 是设备支持的标准 DP,请根据 UI 的显示能力以及产品的侧重点,自行挑选需要使用的标准 DP。

本章节表格中 加粗 的标准 DP,是使用频次较高的,仅供参考。

开关(kg)

DP 说明
HOME_CTRL_SWITCH_SWITCH_INDEX(index_num) 开关 1-8
HOME_CTRL_SWITCH_COUNTDOWN_INDEX(index_num) 开关 1-8 倒计时
HOME_CTRL_SWITCH_SWITCH_ALL 总开关

插座(cz)

DP 说明
HOME_CTRL_SOCKET_SWITCH 开关
HOME_CTRL_SOCKET_CHILD_LOCK 童锁
HOME_CTRL_SOCKET_RELAY_STATUS 上电状态设置
HOME_CTRL_SOCKET_LIGHT_MODE 指示灯状态设置
HOME_CTRL_SOCKET_COUNTDOWN_1 倒计时

灯具(dj)

DP 说明
HOME_CTRL_LIGHT_SWITCH_LED 开关
HOME_CTRL_LIGHT_WORK_MODE 模式
HOME_CTRL_LIGHT_BRIGHT 亮度
HOME_CTRL_LIGHT_TEMP 冷暖
HOME_CTRL_LIGHT_COLOUR 彩光模式
HOME_CTRL_LIGHT_SCENE 情景模式

窗帘(cl)

DP 说明
HOME_CTRL_CURTAIN_CONTROL 控制
HOME_CTRL_CURTAIN_PERCENT_CONTROL 开启百分比控制
HOME_CTRL_CURTAIN_MODE 工作模式
HOME_CTRL_CURTAIN_CONTROL_BACK_MODE 电机反转模式
HOME_CTRL_CURTAIN_AUTO_POWER 自动开启
HOME_CTRL_CURTAIN_COUNTDOWN_SET 倒计时(新)
HOME_CTRL_CURTAIN_PERCENT_STATE 开启百分比状态
HOME_CTRL_CURTAIN_WORK_STATE 工作状态
HOME_CTRL_CURTAIN_COUNTDOWN_LEFT 倒计时剩余时间
HOME_CTRL_CURTAIN_TIME_TOTAL 全程运行时间
HOME_CTRL_CURTAIN_SITUATION_SET 位置状态

空调(kt)

DP 说明
HOME_CTRL_AC_SWITCH 开关
HOME_CTRL_AC_TEMP_SET 设置摄氏温度
HOME_CTRL_AC_TEMP_CURRENT 当前温度
HOME_CTRL_AC_MODE 工作模式
HOME_CTRL_AC_FAN_SPEED_ENUM 风速模式
HOME_CTRL_AC_MODE_ECO ECO
HOME_CTRL_AC_HEAT 辅热
HOME_CTRL_AC_LIGHT 灯光
HOME_CTRL_AC_LOCK 童锁
HOME_CTRL_AC_SWITCH_VERTICAL 上下摆风开关
HOME_CTRL_AC_SWING_3D 3D 扫风
HOME_CTRL_AC_SLEEP 睡眠
HOME_CTRL_AC_HEALTH 健康
HOME_CTRL_AC_CLEANING 自清洁
HOME_CTRL_AC_GEAR_HORIZONTAL 左右摆风
HOME_CTRL_AC_POWER_CONSUMPTION 能耗统计
HOME_CTRL_AC_TEMP_SET_F 设置华氏温度
HOME_CTRL_AC_WINDSPEED 风速档位
HOME_CTRL_AC_MODE_AUTO 自动模式
HOME_CTRL_AC_MODE_DRY 干燥模式
HOME_CTRL_AC_MODE_VENTILATION 换气模式
HOME_CTRL_AC_ANION 负离子
HOME_CTRL_AC_SWITCH_HORIZONTAL 左右摆风开关
HOME_CTRL_AC_WINDSHAKE 风摆
HOME_CTRL_AC_BEEP 蜂鸣
HOME_CTRL_AC_HUMIDITY_SET 设置湿度
HOME_CTRL_AC_TEMP_UNIT_CONVERT 温标切换
HOME_CTRL_AC_COUNTDOWN 倒计时
HOME_CTRL_AC_TEMP_CURRENT_F 当前华氏温度
HOME_CTRL_AC_WORK_STATUS 工作状态
HOME_CTRL_AC_HUMIDITY_CURRENT 当前湿度
HOME_CTRL_AC_COUNTDOWN_LEFT 倒计时剩余时间
HOME_CTRL_AC_STATUS 工作状态

新风机(xfj)

DP 说明
HOME_CTRL_FRESH_AIR_SWITCH 开关
HOME_CTRL_FRESH_AIR_MODE 工作模式
HOME_CTRL_FRESH_AIR_PM25 PM2.5
HOME_CTRL_FRESH_AIR_UV_LIGHT UV 灯
HOME_CTRL_FRESH_AIR_ANION 负离子
HOME_CTRL_FRESH_AIR_ECO2 eCO2
HOME_CTRL_FRESH_AIR_TVOC TVOC
HOME_CTRL_FRESH_AIR_HUMIDITY_INDOOR 室内湿度
HOME_CTRL_FRESH_AIR_TEMP_INDOOR 室内温度
HOME_CTRL_FRESH_AIR_UV_LIFE UV 寿命
HOME_CTRL_FRESH_AIR_FILTER_LIFE 滤网寿命
HOME_CTRL_FRESH_AIR_FAN_SPEED_ENUM 风速
HOME_CTRL_FRESH_AIR_FILTER_RESET 滤芯复位
HOME_CTRL_FRESH_AIR_CHILD_LOCK 童锁开关
HOME_CTRL_FRESH_AIR_FACTORY_RESET 恢复出厂设置
HOME_CTRL_FRESH_AIR_COUNTDOWN_SET 倒计时
HOME_CTRL_FRESH_AIR_COUNTDOWN_LEFT 倒计时剩余时间
HOME_CTRL_FRESH_AIR_FAULT 故障告警
HOME_CTRL_FRESH_AIR_HCHO_SENSOR_VALUE 甲醛(HCHO)参数
HOME_CTRL_FRESH_AIR_PM10 PM10
HOME_CTRL_FRESH_AIR_HUMIDITY_OUTDOOR 室外湿度
HOME_CTRL_FRESH_AIR_TEMP_OUTDOOR 室外温度
HOME_CTRL_FRESH_AIR_AIR_QUALITY 空气质量
HOME_CTRL_FRESH_AIR_AIR_VOLUME 风量
HOME_CTRL_FRESH_AIR_LOOP_MODE 循环模式
HOME_CTRL_FRESH_AIR_SUPPLY_FAN_SPEED 送风风速
HOME_CTRL_FRESH_AIR_EXHAUST_FAN_SPEED 排风风速
HOME_CTRL_FRESH_AIR_SUPPLY_TEMP 送风温度
HOME_CTRL_FRESH_AIR_EXHAUST_TEMP 排风温度
HOME_CTRL_FRESH_AIR_SUPPLY_AIR_VOL 送风风量
HOME_CTRL_FRESH_AIR_EXHAUST_AIR_VOL 排风风量
HOME_CTRL_FRESH_AIR_FRESH_AIR_VALVE 新风阀
HOME_CTRL_FRESH_AIR_AIR_EXHAUST_FAN 排风扇
HOME_CTRL_FRESH_AIR_PRIMARY_FILTER_LIFE 初效滤网剩余
HOME_CTRL_FRESH_AIR_PRIMARY_FILTER_RESET 初效滤网复位
HOME_CTRL_FRESH_AIR_MEDIUM_FILTER_LIFE 中效滤网剩余
HOME_CTRL_FRESH_AIR_MEDIUM_FILTER_RESET 中效滤网复位
HOME_CTRL_FRESH_AIR_HIGH_FILTER_LIFE 高效滤网剩余
HOME_CTRL_FRESH_AIR_HIGH_FILTER_RESET 高效滤网复位
HOME_CTRL_FRESH_AIR_STERILIZE 杀菌
HOME_CTRL_FRESH_AIR_BYPASS_FUNCTION 旁通功能
HOME_CTRL_FRESH_AIR_HEAT 加热
HOME_CTRL_FRESH_AIR_PM25_SET PM2.5 参数设定
HOME_CTRL_FRESH_AIR_ECO2_SET eCO2 参数设定
HOME_CTRL_FRESH_AIR_TEMP_SET 温度设置
HOME_CTRL_FRESH_AIR_HUMIDITY_SET 湿度设置
HOME_CTRL_FRESH_AIR_TVOC_SET TVOC 参数设定
HOME_CTRL_FRESH_AIR_AIR_CONDITIONING 空调
HOME_CTRL_FRESH_AIR_BACKLIGHT 背光亮度
HOME_CTRL_FRESH_AIR_PURIFY_MODE 净化模式
HOME_CTRL_FRESH_AIR_PURIFICATION 净化
HOME_CTRL_FRESH_AIR_DEHUMIDIFIER 除湿
HOME_CTRL_FRESH_AIR_DEFROST 除霜
HOME_CTRL_FRESH_AIR_PM10_SET PM10 参数设定

温控器(wk)

DP 说明
HOME_CTRL_TEMP_CTRL_SWITCH 开关
HOME_CTRL_TEMP_CTRL_MODE 工作模式
HOME_CTRL_TEMP_CTRL_ECO ECO
HOME_CTRL_TEMP_CTRL_ANION 负离子
HOME_CTRL_TEMP_CTRL_LIGHT 灯光
HOME_CTRL_TEMP_CTRL_SOUND 声音
HOME_CTRL_TEMP_CTRL_FACTORY_RESET 恢复出厂设置
HOME_CTRL_TEMP_CTRL_WINDOW_CHECK 开窗检测
HOME_CTRL_TEMP_CTRL_SLEEP 睡眠功能
HOME_CTRL_TEMP_CTRL_FROST 防霜冻功能
HOME_CTRL_TEMP_CTRL_VALVE_CHECK 阀门检测
HOME_CTRL_TEMP_CTRL_SWITCH_VERTICAL 上下摆风开关
HOME_CTRL_TEMP_CTRL_SWITCH_HORIZONTAL 左右摆风开关
HOME_CTRL_TEMP_CTRL_FAN_HORIZONTAL 左右摆风角度
HOME_CTRL_TEMP_CTRL_FAN_VERTICAL 上下摆风角度
HOME_CTRL_TEMP_CTRL_TEMP_SET 目标摄氏温度
HOME_CTRL_TEMP_CTRL_UPPER_TEMP 设置摄氏温度上限
HOME_CTRL_TEMP_CTRL_LOWER_TEMP 设置温度下限
HOME_CTRL_TEMP_CTRL_TEMP_SET_F 目标华氏温度
HOME_CTRL_TEMP_CTRL_UPPER_TEMP_F 设置华氏温度上限
HOME_CTRL_TEMP_CTRL_LOWER_TEMP_F 设置华氏温度下限
HOME_CTRL_TEMP_CTRL_CAPACITY_SET 功率设置
HOME_CTRL_TEMP_CTRL_TEMP_CORRECTION 温度校准
HOME_CTRL_TEMP_CTRL_LEVEL 档位
HOME_CTRL_TEMP_CTRL_WORK_DAYS 工作日设置
HOME_CTRL_TEMP_CTRL_HOLIDAY_TEMP_SET 假日模式摄氏温度设置
HOME_CTRL_TEMP_CTRL_HOLIDAY_TEMP_SET_F 假日模式华氏度温度设置
HOME_CTRL_TEMP_CTRL_HOLIDAY_DAYS_SET 假日模式天数设置
HOME_CTRL_TEMP_CTRL_HOLIDAY_SET 假日模式时间设置
HOME_CTRL_TEMP_CTRL_CHILD_LOCK 童锁
HOME_CTRL_TEMP_CTRL_COUNTDOWN 倒计时
HOME_CTRL_TEMP_CTRL_SENSOR_CHOOSE 传感器选择
HOME_CTRL_TEMP_CTRL_BACKLIGHT 背光亮度
HOME_CTRL_TEMP_CTRL_BACKLIGHT_ENUM 背光亮度快捷设置
HOME_CTRL_TEMP_CTRL_TEMP_UNIT_CONVERT 温标切换
HOME_CTRL_TEMP_CTRL_LOOP_MODE 循环模式
HOME_CTRL_TEMP_CTRL_FAN_SPEED_ENUM 风速设置
HOME_CTRL_TEMP_CTRL_WORK_STATE 工作状态
HOME_CTRL_TEMP_CTRL_WORK_POWER 当前功率
HOME_CTRL_TEMP_CTRL_TEMP_CURRENT 当前摄氏温度
HOME_CTRL_TEMP_CTRL_WINDOW_STATE 窗户状态
HOME_CTRL_TEMP_CTRL_TEMP_CURRENT_F 当前华氏温度
HOME_CTRL_TEMP_CTRL_VALVE_STATE 阀门状态
HOME_CTRL_TEMP_CTRL_COUNTDOWN_LEFT 倒计时剩余分钟
HOME_CTRL_TEMP_CTRL_BATTERY_PERCENTAGE 电池电量
HOME_CTRL_TEMP_CTRL_HUMIDITY 湿度

空气净化器(kj)

DP 说明
HOME_CTRL_AIR_PURIFIER_SWITCH 开关
HOME_CTRL_AIR_PURIFIER_MODE 模式
HOME_CTRL_AIR_PURIFIER_SPEED 风速档位
HOME_CTRL_AIR_PURIFIER_FAN_SPEED_ENUM 风速模式
HOME_CTRL_AIR_PURIFIER_ANION 负离子
HOME_CTRL_AIR_PURIFIER_LOCK 童锁
HOME_CTRL_AIR_PURIFIER_LIGHT 灯光
HOME_CTRL_AIR_PURIFIER_UV UV
HOME_CTRL_AIR_PURIFIER_WET 加湿
HOME_CTRL_AIR_PURIFIER_FILTER_RESET 滤芯复位
HOME_CTRL_AIR_PURIFIER_COUNTDOWN_SET 倒计时
HOME_CTRL_AIR_PURIFIER_FILTER 滤芯使用率
HOME_CTRL_AIR_PURIFIER_PM25 PM2.5
HOME_CTRL_AIR_PURIFIER_TEMP 室内温度
HOME_CTRL_AIR_PURIFIER_HUMIDITY 室内湿度
HOME_CTRL_AIR_PURIFIER_TVOC TVOC
HOME_CTRL_AIR_PURIFIER_ECO2 eCO2
HOME_CTRL_AIR_PURIFIER_FILTER_DAYS 滤芯剩余天数
HOME_CTRL_AIR_PURIFIER_TOTAL_TIME 累计运行时间
HOME_CTRL_AIR_PURIFIER_TOTAL_PM 累计吸收颗粒
HOME_CTRL_AIR_PURIFIER_COUNTDOWN_LEFT 倒计时剩余时间
HOME_CTRL_AIR_PURIFIER_AIR_QUALITY 室内空气质量

晾衣架(lyj)

DP 说明
HOME_CTRL_AIRER_SWITCH 开关
HOME_CTRL_AIRER_CONTROL 设备控制
HOME_CTRL_AIRER_LIGHT 灯光
HOME_CTRL_AIRER_DISINFECTION 消毒
HOME_CTRL_AIRER_WIND_DRY 风干
HOME_CTRL_AIRER_HOT_DRY 烘干
HOME_CTRL_AIRER_DISINFECTION_SET 消毒倒计时设置
HOME_CTRL_AIRER_HOT_DRY_SET 烘干倒计时设置
HOME_CTRL_AIRER_ANION_SET 负离子倒计时设置
HOME_CTRL_AIRER_WIND_DRY_SET 风干倒计时设置
HOME_CTRL_AIRER_ANION 负离子
HOME_CTRL_AIRER_POSITION 位置
HOME_CTRL_AIRER_DISINFECT_LEFT 消毒剩余时间
HOME_CTRL_AIRER_WIND_LEFT 风干剩余时间
HOME_CTRL_AIRER_HOT_LEFT 烘干剩余时间
HOME_CTRL_AIRER_ANION_LEFT 负离子剩余时间
HOME_CTRL_AIRER_WORK_STATE 工作状态

排插(pc)

DP 说明
HOME_CTRL_SOCKETS_SWITCH 开关
HOME_CTRL_SOCKETS_SWITCH_1 开关 1
HOME_CTRL_SOCKETS_SWITCH_2 开关 2
HOME_CTRL_SOCKETS_SWITCH_3 开关 3
HOME_CTRL_SOCKETS_SWITCH_4 开关 4
HOME_CTRL_SOCKETS_SWITCH_5 开关 5
HOME_CTRL_SOCKETS_SWITCH_6 开关 6
HOME_CTRL_SOCKETS_COUNTDOWN_1 开关 1 倒计时
HOME_CTRL_SOCKETS_COUNTDOWN_2 开关 2 倒计时
HOME_CTRL_SOCKETS_COUNTDOWN_3 开关 3 倒计时
HOME_CTRL_SOCKETS_COUNTDOWN_4 开关 4 倒计时
HOME_CTRL_SOCKETS_COUNTDOWN_5 开关 5 倒计时
HOME_CTRL_SOCKETS_COUNTDOWN_6 开关 6 倒计时
HOME_CTRL_SOCKETS_SWITCH_USB1 USB1
HOME_CTRL_SOCKETS_SWITCH_USB2 USB2
HOME_CTRL_SOCKETS_SWITCH_USB3 USB3
HOME_CTRL_SOCKETS_SWITCH_USB4 USB4
HOME_CTRL_SOCKETS_SWITCH_USB5 USB5
HOME_CTRL_SOCKETS_SWITCH_USB6 USB6
HOME_CTRL_SOCKETS_COUNTDOWN_USB1 USB1 倒计时
HOME_CTRL_SOCKETS_COUNTDOWN_USB2 USB2 倒计时
HOME_CTRL_SOCKETS_COUNTDOWN_USB3 USB3 倒计时
HOME_CTRL_SOCKETS_COUNTDOWN_USB4 USB4 倒计时
HOME_CTRL_SOCKETS_COUNTDOWN_USB5 USB5 倒计时
HOME_CTRL_SOCKETS_COUNTDOWN_USB6 USB6 倒计时
HOME_CTRL_SOCKETS_CHILD_LOCK 童锁
HOME_CTRL_SOCKETS_RELAY_STATUS 上电状态设置
HOME_CTRL_SOCKETS_LIGHT_MODE 指示灯状态设置
HOME_CTRL_SOCKETS_SWITCH_BACKLIGHT 背光开关
HOME_CTRL_SOCKETS_CUR_CURRENT 当前电流
HOME_CTRL_SOCKETS_CUR_POWER 当前功率
HOME_CTRL_SOCKETS_CUR_VOLTAGE 当前电压

调光开关(tgkg)

DP 说明
HOME_CTRL_DIMMER_SWITCH_COLOUR_DATA 彩光
HOME_CTRL_DIMMER_SWITCH_TEMP_VALUE 冷暖值
HOME_CTRL_DIMMER_SWITCH_LIGHT_MODE 指示灯状态设置
HOME_CTRL_DIMMER_SWITCH_RELAY_STATUS 上电状态设置
HOME_CTRL_DIMMER_SWITCH_WORK_MODE 模式
HOME_CTRL_DIMMER_SWITCH_SWITCH_LED_1 开关 1
HOME_CTRL_DIMMER_SWITCH_SWITCH_LED_2 开关 2
HOME_CTRL_DIMMER_SWITCH_SWITCH_LED_3 开关 3
HOME_CTRL_DIMMER_SWITCH_BRIGHTNESS_MIN_1 最小亮度 1
HOME_CTRL_DIMMER_SWITCH_BRIGHTNESS_MIN_2 最小亮度 2
HOME_CTRL_DIMMER_SWITCH_BRIGHTNESS_MIN_3 最小亮度 3
HOME_CTRL_DIMMER_SWITCH_BRIGHTNESS_MAX_1 最大亮度 1
HOME_CTRL_DIMMER_SWITCH_BRIGHTNESS_MAX_2 最大亮度 2
HOME_CTRL_DIMMER_SWITCH_BRIGHTNESS_MAX_3 最大亮度 3
HOME_CTRL_DIMMER_SWITCH_BRIGHT_VALUE_1 亮度值 1
HOME_CTRL_DIMMER_SWITCH_BRIGHT_VALUE_2 亮度值 2
HOME_CTRL_DIMMER_SWITCH_BRIGHT_VALUE_3 亮度值 3
HOME_CTRL_DIMMER_SWITCH_COUNTDOWN_1 开关 1 倒计时
HOME_CTRL_DIMMER_SWITCH_COUNTDOWN_2 开关 2 倒计时
HOME_CTRL_DIMMER_SWITCH_COUNTDOWN_3 开关 3 倒计时
HOME_CTRL_DIMMER_SWITCH_LED_TYPE_1 光源类型 1
HOME_CTRL_DIMMER_SWITCH_LED_TYPE_2 光源类型 2
HOME_CTRL_DIMMER_SWITCH_LED_TYPE_3 光源类型 3

香薰机(xxj)

DP 说明
HOME_CTRL_AROMA_DIFFUSER_SWITCH 总开关
HOME_CTRL_AROMA_DIFFUSER_SWITCH_SPRAY 喷雾开关
HOME_CTRL_AROMA_DIFFUSER_MODE 喷雾模式(雾量)
HOME_CTRL_AROMA_DIFFUSER_COUNTDOWN 喷雾倒计时
HOME_CTRL_AROMA_DIFFUSER_SWITCH_LED 灯光开关
HOME_CTRL_AROMA_DIFFUSER_WORK_MODE 灯光模式
HOME_CTRL_AROMA_DIFFUSER_COLOUR_DATA_HSV 灯光值 HSV 设置
HOME_CTRL_AROMA_DIFFUSER_BRIGHT_VALUE 亮度值
HOME_CTRL_AROMA_DIFFUSER_SWITCH_SOUND 声音开关
HOME_CTRL_AROMA_DIFFUSER_LEVEL 喷雾档位
HOME_CTRL_AROMA_DIFFUSER_MOODLIGHTING 氛围灯
HOME_CTRL_AROMA_DIFFUSER_COLOUR_DATA 彩光值
HOME_CTRL_AROMA_DIFFUSER_COUNTDOWN_LEFT 喷雾倒计时剩余分钟

加湿器(jsq)

DP 说明
HOME_CTRL_HUMIDIFIER_SWITCH 总开关
HOME_CTRL_HUMIDIFIER_SWITCH_SPRAY 喷雾开关
HOME_CTRL_HUMIDIFIER_MODE 喷雾模式(雾量)
HOME_CTRL_HUMIDIFIER_SPRAY_MODE 喷雾模式(调节)
HOME_CTRL_HUMIDIFIER_LEVEL 喷雾档位
HOME_CTRL_HUMIDIFIER_COUNTDOWN_SET 喷雾倒计时设置
HOME_CTRL_HUMIDIFIER_SWITCH_LED 灯光开关
HOME_CTRL_HUMIDIFIER_WORK_MODE 灯光模式
HOME_CTRL_HUMIDIFIER_COLOUR_DATA_HSV 彩光值
HOME_CTRL_HUMIDIFIER_BRIGHT_VALUE 亮度值
HOME_CTRL_HUMIDIFIER_SWITCH_SOUND 声音开关
HOME_CTRL_HUMIDIFIER_TEMP_SET 温度设置
HOME_CTRL_HUMIDIFIER_TEMP_SET_F 华氏温度设置
HOME_CTRL_HUMIDIFIER_HUMIDITY_SET 湿度设置
HOME_CTRL_HUMIDIFIER_SLEEP 睡眠功能
HOME_CTRL_HUMIDIFIER_TEMP_UNIT_CONVERT 温标切换设置
HOME_CTRL_HUMIDIFIER_STERILIZATION 除菌
HOME_CTRL_HUMIDIFIER_CHILD_LOCK 童锁开关
HOME_CTRL_HUMIDIFIER_COUNTDOWN 喷雾倒计时
HOME_CTRL_HUMIDIFIER_COLOUR_DATA 彩光值
HOME_CTRL_HUMIDIFIER_C_F 温标切换
HOME_CTRL_HUMIDIFIER_MOODLIGHTING 氛围灯
HOME_CTRL_HUMIDIFIER_COUNTDOWN_LEFT 喷雾倒计时剩余分钟
HOME_CTRL_HUMIDIFIER_TEMP_CURRENT 当前温度
HOME_CTRL_HUMIDIFIER_TEMP_CURRENT_F 当前华氏温度
HOME_CTRL_HUMIDIFIER_HUMIDITY_CURRENT 当前湿度
HOME_CTRL_HUMIDIFIER_LEVEL_CURRENT 当前水位

门磁传感器(mcs)

DP 说明
HOME_CTRL_DOOR_SENSOR_DOORCONTACT_STATE 门磁状态
HOME_CTRL_DOOR_SENSOR_TEMPER_ALARM 防拆报警
HOME_CTRL_DOOR_SENSOR_BATTERY_PERCENTAGE 电池电量百分比
HOME_CTRL_DOOR_SENSOR_BATTERY_VALUE 电池电量值
HOME_CTRL_DOOR_SENSOR_BATTERY_STATE 电池电量状态

水浸传感器(sj)

DP 说明
HOME_CTRL_WATER_SENSOR_WATERSENSOR_STATE 水浸检测状态
HOME_CTRL_WATER_SENSOR_TEMPER_ALARM 防拆报警
HOME_CTRL_WATER_SENSOR_BATTERY_PERCENTAGE 电池电量百分比
HOME_CTRL_WATER_SENSOR_BATTERY_VALUE 电池电量值
HOME_CTRL_WATER_SENSOR_BATTERY_STATE 电池电量状态

PIR 人体移动传感器(pir)

DP 说明
HOME_CTRL_PIR_SENSOR_PIR 人体感应状态
HOME_CTRL_PIR_SENSOR_TEMPER_ALARM 防拆报警
HOME_CTRL_PIR_SENSOR_BATTERY_PERCENTAGE 电池电量百分比
HOME_CTRL_PIR_SENSOR_BATTERY_STATE 电池电量状态
HOME_CTRL_PIR_SENSOR_BATTERY 电池电量
HOME_CTRL_PIR_SENSOR_BATTERY_VALUE 电池电量值

温湿度传感器(wsdcg)

DP 说明
HOME_CTRL_THTB_SENSOR_VA_TEMPERATURE 当前温度值
HOME_CTRL_THTB_SENSOR_VA_HUMIDITY 当前湿度值
HOME_CTRL_THTB_SENSOR_TEMPER_ALARM 防拆报警
HOME_CTRL_THTB_SENSOR_BATTERY_PERCENTAGE 电池电量百分比
HOME_CTRL_THTB_SENSOR_BATTERY_STATE 电池电量状态
HOME_CTRL_THTB_SENSOR_VA_BATTERY 电池电量
HOME_CTRL_THTB_SENSOR_BATTERY_VALUE 电池电量值

燃气报警器(rqbj)

DP 说明
HOME_CTRL_GAS_ALARM_SENSOR_MUFFLING 消音
HOME_CTRL_GAS_ALARM_SENSOR_ALARM_RINGTONE 报警铃声
HOME_CTRL_GAS_ALARM_SENSOR_ALARM_TIME 报警时长
HOME_CTRL_GAS_ALARM_SENSOR_SELF_CHECKING 设备自检
HOME_CTRL_GAS_ALARM_SENSOR_ALARM_VOLUME 报警音量
HOME_CTRL_GAS_ALARM_SENSOR_ALARM_SWITCH 报警开关
HOME_CTRL_GAS_ALARM_SENSOR_PREHEAT 是否预热中
HOME_CTRL_GAS_ALARM_SENSOR_TEMPER_ALARM 防拆报警
HOME_CTRL_GAS_ALARM_SENSOR_LIFECYCLE 使用寿命
HOME_CTRL_GAS_ALARM_SENSOR_CHECKING_RESULT 设备自检结果
HOME_CTRL_GAS_ALARM_SENSOR_BATTERY_PERCENTAGE 电池电量百分比
HOME_CTRL_GAS_ALARM_SENSOR_BATTERY_VALUE 电池电量值
HOME_CTRL_GAS_ALARM_SENSOR_BATTERY_STATE 电池电量状态
HOME_CTRL_GAS_ALARM_SENSOR_GAS_SENSOR_VALUE 燃气检测值
HOME_CTRL_GAS_ALARM_SENSOR_GAS_SENSOR_STATUS 燃气检测状态值

沙发(sf)

DP 说明
HOME_CTRL_SOFA_SWITCH 开关
HOME_CTRL_SOFA_STOP 停止
HOME_CTRL_SOFA_LOCK 童锁
HOME_CTRL_SOFA_LIE 一键平躺
HOME_CTRL_SOFA_HEAD_RUN 头部电机行程
HOME_CTRL_SOFA_WHOLE_RUN 整体电机行程
HOME_CTRL_SOFA_MODE 工作模式

场景开关(cjkg)

DP 说明
HOME_CTRL_SCENE_SWITCH_SCENE_INDEX (index_num) 场景 1-8
HOME_CTRL_SCENE_SWITCH_COUNTDOWN_INDEX (index_num) 开关 1-8 倒计时
HOME_CTRL_SCENE_SWITCH_SWITCH_INDEX(index_num) 开关 1-8

SOS 传感器(sos)

DP 说明
HOME_CTRL_SOS_SENSOR_SOS_STATE 紧急模式
HOME_CTRL_SOS_SENSOR_BATTERY_STATE 电池电量状态
HOME_CTRL_SOS_SENSOR_TEMPER_ALARM 防拆报警
HOME_CTRL_SOS_SENSOR_BATTERY_PERCENTAGE 电池电量

获取设备 DP 名称列表

函数原型 OPERATE_RET tuya_home_ctrl_get_dp_name_list(IN CONST TY_HOME_CTRL_DEV_T dev_des, OUT TY_HOME_CTRL_DP_NAME_S **pp_list, OUT BYTE_T *num)
函数描述 获取设备指定 DP
参数说明
  • 入参
    • dev_des:设备描述符
  • 出参
    • pp_list:DP 名称列表
    • num:DP 名称数量
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 -

用法示例

TY_HOME_CTRL_DEV_T dev_info = tuya_home_ctrl_dev_open(dev_id, &dev_cb);
    BYTE_T dp_name_num;
    TY_HOME_CTRL_DP_NAME_S *dp_name_list = NULL;
    ret = tuya_home_ctrl_get_dp_name_list(dev_info, &dp_name_list, &dp_name_num);
    if (ret != OPRT_OK) {
        PR_ERR("tuya_home_ctrl_get_dp_name_list err:%d", ret);
        ret = tuya_home_ctrl_dev_close(dev_info);
        return;
    }

    for (i = 0; i < dp_name_num; i++) {
        PR_DEBUG("dp std_code : %s --> dp_name : %s", dp_name_list[i].std_code, dp_name_list[i].dp_name);
    }

根据设备描述符获取设备简要信息

函数原型 OPERATE_RET tuya_home_ctrl_get_dev_brief(IN CONST TY_HOME_CTRL_DEV_T dev_des, OUT TY_HOME_CTRL_DEV_BRIEF_S *brief_info)
函数描述 根据设备描述符,获取设备简要信息
参数说明
  • 入参
    • dev_des:设备描述符
  • 出参
    • brief_info:设备简要信息
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 -

用法示例

    TY_HOME_CTRL_DEV_BRIEF_S brief_info = {0};
    OPERATE_RET ret                     = tuya_home_ctrl_get_dev_brief(dev_info, &brief_info);
    if (ret != OPRT_OK) {
        PR_ERR("tuya_home_ctrl_get_dev_brief err:%d", ret);
    }
    PR_DEBUG("dev_id:%s, dev_name:%s, category:%s, online:%d", brief_info.id, brief_info.name, brief_info.category,
             brief_info.online_stat);

场景开关

获取场景开关信息

函数原型 OPERATE_RET tuya_home_ctrl_dev_get_scene_switch_info(IN CONST TY_HOME_CTRL_DEV_T dev_des, OUT TY_HOME_CTRL_DEV_SCENE_SWITCH_INFO_S *p_scene_switch_info)
函数描述 获取场景开关标准 DP 和场景名称映射信息
参数说明
  • 入参
    • dev_des:设备描述符
  • 出参
    • p_scene_switch_info :映射信息
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 通过该接口获取场景开关标准 DP 和场景名称之间的映射信息,例如 std_code:scene1 rule_name:睡眠模式,详情可参考 demo。使用后,需要用 tuya_home_ctrl_dev_scene_switch_info_destroy 释放内存

释放场景开关信息内存

函数原型 OPERATE_RET tuya_home_ctrl_dev_scene_switch_info_destroy(IN TY_HOME_CTRL_DEV_SCENE_SWITCH_INFO_S* p_scene_switch_info)
函数描述 释放场景开关信息内存
参数说明
  • 入参
    • p_scene_switch_info:映射信息
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 -

自定义 DP

自定义 DP 的 Demo 参考 test_home_ctrl_switch.c 文件。

获取设备所有自定义 DP

函数原型 OPERATE_RET tuya_home_ctrl_dev_get_all_custom_dp(IN CONST TY_HOME_CTRL_DEV_T dev_des,OUT BYTE_T *dp_num,OUT TUYA_CUSTOM_DP_PROP_S **dp_sets)
函数描述 获取所有自定义 DP 信息
参数说明
  • 入参
    • dev_des:设备描述符
  • 出参
    • dp_num:DP 数量
    • dp_sets:DP 集合
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 -

设置设备指定自定义 DP 值

函数原型 OPERATE_RET tuya_home_ctrl_dev_set_custom_dp_value(IN CONST TY_HOME_CTRL_DEV_T dev_des,IN CONST INT_T dp_id,IN TY_HOME_CTRL_DEV_DP_DATA_TP_E dp_type,IN CONST TY_HOME_CTRL_DEV_DP_VALUE_U *dp_value)
函数描述 设置设备指定自定义 DP 值
参数说明
  • 入参
    • dev_des:设备描述符
    • dp_id:DP 的 ID
    • dp_type:DP 类型
    • dp_value:值
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 -

获取设备指定自定义 DP 值

函数原型 OPERATE_RET tuya_home_ctrl_dev_get_custom_dp_value(IN CONST TY_HOME_CTRL_DEV_T dev_des,IN CONST INT_T dp_id,OUT TUYA_CUSTOM_DP_PROP_S **dp_info)
函数描述 获取设备指定自定义 DP 值
参数说明
  • 入参
    • dev_des:设备描述符
    • dp_id:DP 的 ID
  • 出参
    • dp_info:Dp 值
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 -

打印自定义 DP 内容

函数原型 VOID tuya_home_ctrl_dev_show_custom_dp(IN CONST TUYA_CUSTOM_DP_PROP_S *dp)
函数描述 打印自定义 DP 内容
参数说明
  • 入参
    • dev_des:设备描述符
    • dp_id:DP 的 ID
    • dp_type:DP 类型
    • dp_value:值
返回值 OPERATE_RET:
  • 0:成功
  • 其他:失败,详见错误码
详细描述 -

自定义 DP 改变回调

函数原型 VOID (*TY_HOME_CTRL_DEV_REPORT_CUSTOM_FUNC)(IN CONST TUYA_CUSTOM_DP_PROP_S *dp, IN VOID *user_arg);
函数描述 设备自定义 DP 状态改变的回调
参数说明
  • 入参
    • dp:dp 数据
    • user_arg:用户参数
返回值 VOID
详细描述 -