Last Updated on : 2024-11-18 11:33:13download
A device group includes devices of the same type and gathers a series of devices. Wi-Fi and Zigbee devices can be grouped in most cases. Tuya provides the capabilities to implement device group management. For example, create, rename, manage, or dismiss a group, and manage or control multiple devices in the same group.
API description
TuyaHomeSdk.newHomeInstance(homeId).queryDeviceListToAddGroup(groupId, productId,
new ITuyaResultCallback<List<GroupDeviceBean>>() {
@Override
public void onSuccess(List<GroupDeviceBean> arrayList) {
}
@Override
public void onError(String errorCode, String errorMsg) {
}
});
Parameters
Parameter | Description |
---|---|
homeId | The home ID. |
groupId | The group ID.
|
productId | The product ID (PID) of the devices through which a group can be accessed. |
API description
TuyaHomeSdk.newHomeInstance(mHomeId).createGroup(productId, name, selectedDeviceIds,
new ITuyaResultCallback<Long>() {
@Override
public void onSuccess(Long groupId) {
// Returns the value of groupId.
}
@Override
public void onError(String errorCode, String errorMsg) {
}
});
Parameters
Parameter | Description |
---|---|
homeId | The home ID. |
productId | The PID of the devices used to create a group. |
name | The name of the group. |
selectedDeviceIds | The list of the target device IDs specified by deviceId . |
Updates and saves the changes in a group to the cloud after devices are added to or removed from the group.
API description
TuyaHomeSdk.newGroupInstance(groupId).updateDeviceList(deviceIds,
new IResultCallback() {
@Override
public void onError(String s, String s1) {
}
@Override
public void onSuccess() {
}
});
Parameters
Parameter | Description |
---|---|
groupId | The group ID. |
deviceIds | The list of target device IDs. |
A Zigbee group supports Zigbee sub-devices, Sub-G sub-devices, Smart Gateway Pro sub-devices, and other devices that can communicate over Zigbee.
API description
TuyaHomeSdk.newHomeInstance(homeId).queryZigbeeDeviceListToAddGroup(groupId, productId, meshId,
new ITuyaResultCallback<List<GroupDeviceBean>>() {
@Override
public void onSuccess(List<GroupDeviceBean> arrayList) {
}
@Override
public void onError(String errorCode, String errorMsg) {
}
});
Parameters
Parameter | Description |
---|---|
homeId | The home ID. |
groupId | The group ID.
|
productId | The product ID (PID) of the devices through which a group can be accessed. |
meshId | The gateway ID of the group devices. You can call deviceBean.getMeshId() to get the value. |
API description
TuyaHomeSdk.newHomeInstance(homeId).createZigbeeGroup(productId, meshId, name,
new ITuyaResultCallback<CloudZigbeeGroupCreateBean>() {
@Override
public void onSuccess(CloudZigbeeGroupCreateBean cloudZigbeeGroupCreateBean) {
// Returns the result.
long mGroupId = cloudZigbeeGroupCreateBean.getGroupId();
String mGId = cloudZigbeeGroupCreateBean.getLocalId();
}
@Override
public void onError(String errorCode, String errorMsg) {
}
});
Parameters
Parameter | Description |
---|---|
homeId | The home ID. |
productId | The PID of the devices used to create a group. |
meshId | The gateway ID of the group devices. You can call deviceBean.getMeshId() to get the value. |
name | The name of the group. |
In this interaction, the node IDs of the new devices are written to the gateway firmware of the group.
API description
mITuyaZigbeeGroup.addDeviceToGroup(meshId, selectedDeviceIds, gid,
new ITuyaResultCallback<ZigbeeGroupCreateResultBean>() {
@Override
public void onSuccess(ZigbeeGroupCreateResultBean zigbeeGroupCreateResultBean) {
if (zigbeeGroupCreateResultBean != null) {
// The success callback.
if (zigbeeGroupCreateResultBean.getSuccess() != null && zigbeeGroupCreateResultBean.getSuccess().size() > 0) {
List<String> mAddSuccessDeviceIds = new ArrayList<>();
mAddSuccessDeviceIds.addAll(zigbeeGroupCreateResultBean.getSuccess());
}
// The failure callback.
if (zigbeeGroupCreateResultBean.getFailure() != null && zigbeeGroupCreateResultBean.getFailure().size() > 0) {
List<String>mAddFailDeviceIds = new ArrayList<>();
mAddFailDeviceIds.addAll(zigbeeGroupCreateResultBean.getFailure());
}
// Call the API method at the right time to update and save the group relationship.
//TuyaHomeSdk.newZigbeeGroupInstance(groupId).updateGroupDeviceList()
}
}
@Override
public void onError(String errorCode, String errorMsg) {
}
});
Parameters
Parameter | Description |
---|---|
meshId | The gateway ID of the group devices. You can call deviceBean.getMeshId() to get the value. |
selectedDeviceIds | The list of the target device IDs specified by deviceId . |
gid | The value of localId for the group.
|
Removes one or more devices from a group through a gateway.
API description
mITuyaZigbeeGroup.delDeviceToGroup(meshId, selectedDeviceIds, gid,
new ITuyaResultCallback<ZigbeeGroupCreateResultBean>() {
@Override
public void onSuccess(ZigbeeGroupCreateResultBean zigbeeGroupCreateResultBean) {
if (zigbeeGroupCreateResultBean != null) {
// The success callback.
if (zigbeeGroupCreateResultBean.getSuccess() != null && zigbeeGroupCreateResultBean.getSuccess().size() > 0) {
List<String> mDelSuccessDeviceIds = new ArrayList<>();
mDelSuccessDeviceIds.addAll(zigbeeGroupCreateResultBean.getSuccess());
}
// The failure callback.
if (zigbeeGroupCreateResultBean.getFailure() != null && zigbeeGroupCreateResultBean.getFailure().size() > 0) {
List<String> mDelFailDeviceIds = new ArrayList<>();
mDelFailDeviceIds.addAll(zigbeeGroupCreateResultBean.getFailure());
}
// Call the API method at the right time to update and save the group relationship.
//TuyaHomeSdk.newZigbeeGroupInstance(groupId).updateGroupDeviceList()
}
}
@Override
public void onError(String errorCode, String errorMsg) {
}
});
Parameters
Parameter | Description |
---|---|
meshId | The gateway ID of the group devices. You can call deviceBean.getMeshId() to get the value. |
selectedDeviceIds | The list of the target device IDs specified by deviceId . |
gid | The value of localId for the group.
|
Updates and saves the changes in a group to the cloud by using the interaction with the gateway firmware after devices are added to or removed from the group.
API description
TuyaHomeSdk.newZigbeeGroupInstance(groupId).updateGroupDeviceList(homeId, selectedDeviceIds,
new IResultCallback() {
@Override
public void onError(String s, String s1) {
}
@Override
public void onSuccess() {
}
});
Parameters
Parameter | Description |
---|---|
groupId | The group ID. |
homeId | The home ID. |
selectedDeviceIds | The success callback. A list of existing device IDs is returned. |
API description
ITuyaGroup mITuyaGroup= TuyaHomeSdk.newGroupInstance(groupId);
Parameters
Parameter | Description |
---|---|
groupId | The group ID. |
API description
TuyaHomeSdk.newGroupInstance(groupId).renameGroup(titleName,
new IResultCallback() {
@Override
public void onError(String s, String s1) {
}
@Override
public void onSuccess() {
}
});
Parameters
Parameter | Description |
---|---|
groupId | The group ID. |
titleName | The name of the group. |
API description
TuyaHomeSdk.newGroupInstance(groupId).dismissGroup(new IResultCallback() {
@Override
public void onError(String s, String s1) {
}
@Override
public void onSuccess() {
}
});
Parameters
Parameter | Description |
---|---|
groupId | The target group ID. |
API description
mTuyaGroup.publishDps(String command, IResultCallback listener);
Parameters
Parameter | Description |
---|---|
command | The control commands. |
Example
// Sample code for switching on a light in a group.
LampBean bean = new LampBean();
bean.setOpen(true);
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put(STHEME_LAMP_DPID_1, bean.isOpen());
mTuyaGroup.publishDps(JSONObject.toJSONString(hashMap),callback);
// The callback to invoke when a group is registered.
mITuyaGroup.registerGroupListener(new IGroupListener() {
@Override
public void onDpUpdate(long l, String s) {
}
@Override
public void onGroupInfoUpdate(long l) {
}
@Override
public void onGroupRemoved(long l) {
}
});
// The callback to invoke when a group is unregistered.
mITuyaGroup.unRegisterGroupListener();
If the result is returned after a control command is sent to a group, it indicates that the command has been sent to the cloud. However, it does not mean that device control is implemented as expected.
Before this call, you must call getHomeDetail()
or getHomeLocalCache()
to initialize a home
. Then, group details can be queried.
// Returns the details of a specified group.
TuyaHomeSdk.getDataInstance().getGroupBean(long groupId);
// Returns a list of devices in the group.
TuyaHomeSdk.getDataInstance().getGroupDeviceList(long groupId);
// Destroys group data. We recommend that you call this API method to exit group control.
mITuyaGroup.onDestroy();
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback