Last Updated on : 2023-05-25 06:23:50
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
ThingHomeSdk.newHomeInstance(homeId).queryDeviceListToAddGroup(groupId, productId,
new IThingResultCallback<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
ThingHomeSdk.newHomeInstance(mHomeId).createGroup(productId, name, selectedDeviceIds,
new IThingResultCallback<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
ThingHomeSdk.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
ThingHomeSdk.newHomeInstance(homeId).queryZigbeeDeviceListToAddGroup(groupId, productId, meshId,
new IThingResultCallback<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
ThingHomeSdk.newHomeInstance(homeId).createZigbeeGroup(productId, meshId, name,
new IThingResultCallback<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
mIThingZigbeeGroup.addDeviceToGroup(meshId, selectedDeviceIds, gid,
new IThingResultCallback<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.
//ThingHomeSdk.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
mIThingZigbeeGroup.delDeviceToGroup(meshId, selectedDeviceIds, gid,
new IThingResultCallback<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.
//ThingHomeSdk.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
ThingHomeSdk.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
IThingGroup mIThingGroup= ThingHomeSdk.newGroupInstance(groupId);
Parameters
Parameter | Description |
---|---|
groupId | The group ID. |
API description
ThingHomeSdk.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
ThingHomeSdk.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
mThingGroup.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());
mThingGroup.publishDps(JSONObject.toJSONString(hashMap),callback);
// The callback to invoke when a group is registered.
mIThingGroup.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.
mIThingGroup.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.
ThingHomeSdk.getDataInstance().getGroupBean(long groupId);
// Returns a list of devices in the group.
ThingHomeSdk.getDataInstance().getGroupDeviceList(long groupId);
// Destroys group data. We recommend that you call this API method to exit group control.
mIThingGroup.onDestroy();
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback