1. Home Relationship Management

Get the family list, family management, room and equipment management under the family and information monitoring, etc.

HomeBean description

Parameters Type Description
name String The home name
lon double The home lon
lat double The home lat
geoName String The home location name
homeId long The home Id
admin boolean Administrator status
rooms List<RoomBean> All the rooms
deviceList List<DeviceBean> All the devices
groupList List<GroupBean> All the groups
meshList List<BlueMeshBean> All of the mesh devices
sharedDeviceList List<DeviceBean> Shared devices received
sharedGroupList List<GroupBean> Shared groups received
homeStatus int The home status (1:to be accepted 2:accepted 3:reject)

1.1. Get Family List

Declaration

void queryHomeList(ITuyaGetHomeListCallback callback)

Parameters

Parameters Description
callback Result callback

Example

TuyaHomeSdk.getHomeManagerInstance().queryHomeList(new ITuyaGetHomeListCallback() {
        @Override
        public void onError(String errorCode, String error) {
            // do something
        }
        @Override
        public void onSuccess(List<HomeBean> homeBeans) {
            // do something
        }
    });

1.2. Create Family

Declaration

void createHome(String name, double lon, double lat, String geoName, List rooms, ITuyaHomeResultCallback callback)

Parameters

Parameters Description
name Family name (Support up to 25 characters)
lon longitude (Pass 0 if you don't set family location information)
lat latitude (Pass 0 if you don't set family location information)
geoName Home location name
rooms Room list
callback Result callback

Example

TuyaHomeSdk.getHomeManagerInstance().createHome(name, lon, lat, geoName, rooms, new ITuyaHomeResultCallback() {
        @Override
        public void onError(String errorCode, String errorMsg) {
            // do something
        }
        @Override
        public void onSuccess(HomeBean bean) {
            // do something
        }
    });

1.3. Change of Home Information

Change of registered home information includes: inviting home, adding home and removing home, change of home information, change of shared lists and monitoring of successfully server connection.

Declaration

public interface ITuyaHomeChangeListener {
    /**
     * Family added successfully. 
     * Used for multi-device data synchronization
     *
     * @param homeId Family ID
     */
    void onHomeAdded(long homeId);

    /**
     * Family invitation.
     * @param homeId    Family ID
     * @param homeName  Family name
     */
    void onHomeInvite(long homeId,String homeName);

    /**
     * Family deleted successfully.
     * Used for multi-device data synchronization
     *
     * @param homeId  Family ID
     */
    void onHomeRemoved(long homeId);

    /**
     * Family information changed.
     * Used for multi-device data synchronization
     *
     * @param homeId  Family ID
     */
    void onHomeInfoChanged(long homeId);

    /**
     * Shared device list change.
     * Used for multi-device data synchronization
     *
     * @param sharedDeviceList shared device list
     */
    void onSharedDeviceList(List<DeviceBean> sharedDeviceList);

    /**
     * The mobile phone successfully connects to the Tuya Cloud server and receives this notification.
     * Local data and server data may be inconsistent or the device cannot be controlled,
     * You can call the getHomeDetail interface under Home to reinitialize the data.
     */
    void onServerConnectSuccess();
}

1.3.1. Register the information Change of a home.

Declaration

void registerTuyaHomeChangeListener(ITuyaHomeChangeListener listener);

Parameters

Parameters Description
listener Monitor

Example

ITuyaHomeChangeListener listener = new ITuyaHomeChangeListener() {
        @Override
        public void onHomeInvite(long homeId, String homeName) {
            // do something
        }
        @Override
        public void onHomeRemoved(long homeId) {
            // do something
        }
        @Override
        public void onHomeInfoChanged(long homeId) {
            // do something
        }
        @Override
        public void onSharedDeviceList(List<DeviceBean> sharedDeviceList) {
            // do something
        }
        @Override
        public void onSharedGroupList(List<GroupBean> sharedGroupList) {
            // do something
        }
        @Override
        public void onServerConnectSuccess() {
            // do something
        }
        @Override
        public void onHomeAdded(long homeId) {
            // do something
        }
    };
TuyaHomeSdk.getHomeManagerInstance().registerTuyaHomeChangeListener(listener);

1.3.2. Deregistered the information Change of a home.

Declaration

void unRegisterTuyaHomeChangeListener(ITuyaHomeChangeListener listener)

Parameters

Parameters Description
listener Monitor

Example

ITuyaHomeChangeListener listener = new ITuyaHomeChangeListener() {
        @Override
        public void onHomeInvite(long homeId, String homeName) {
            // do something
        }
        @Override
        public void onHomeRemoved(long homeId) {
            // do something
        }
        @Override
        public void onHomeInfoChanged(long homeId) {
            // do something
        }
        @Override
        public void onSharedDeviceList(List<DeviceBean> sharedDeviceList) {
            // do something
        }
        @Override
        public void onSharedGroupList(List<GroupBean> sharedGroupList) {
            // do something
        }
        @Override
        public void onServerConnectSuccess() {
            // do something
        }
        @Override
        public void onHomeAdded(long homeId) {
            // do something
        }
    };
TuyaHomeSdk.getHomeManagerInstance().registerTuyaHomeChangeListener(listener);
// ...
TuyaHomeSdk.getHomeManagerInstance().unRegisterTuyaHomeChangeListener(listener);

1.3.3. Callback of MQTT Service Connection Success

Declaration

void onServerConnectSuccess()

Example

ITuyaHomeChangeListener listener = new ITuyaHomeChangeListener() {
        @Override
        public void onHomeInvite(long homeId, String homeName) {
            // do something
        }
        @Override
        public void onHomeRemoved(long homeId) {
            // do something
        }
        @Override
        public void onHomeInfoChanged(long homeId) {
            // do something
        }
        @Override
        public void onSharedDeviceList(List<DeviceBean> sharedDeviceList) {
            // do something
        }
        @Override
        public void onSharedGroupList(List<GroupBean> sharedGroupList) {
            // do something
        }
        @Override
        public void onServerConnectSuccess() {
            // do something
        }
        @Override
        public void onHomeAdded(long homeId) {
            // do something
        }
    };

TuyaHomeSdk.getHomeManagerInstance().registerTuyaHomeChangeListener(listener);
// ...
TuyaHomeSdk.getHomeManagerInstance().unRegisterTuyaHomeChangeListener(listener);

2. Family Management

2.1. Get Family Details

Obtain all data under the family, including equipment, groups, rooms, etc

Declaration

void getHomeDetail(ITuyaHomeResultCallback callback)

Parameters

Parameters Description
callback Callback to get results

Example

TuyaHomeSdk.newHomeInstance(10000).getHomeDetail(new ITuyaHomeResultCallback() {
        @Override
        public void onError(String errorCode, String errorMsg) {
            // do something
        }
        @Override
        public void onSuccess(HomeBean bean) {
            // do something
        }
    });

2.2. Get Family Offline Details

Obtain all offline data under the family, including equipment, groups, rooms, etc

Declaration

void getHomeLocalCache(ITuyaHomeResultCallback callback)

Parameters

Parameters Description
callback Callback to get results

Example

TuyaHomeSdk.newHomeInstance(10000).getHomeLocalCache(new ITuyaHomeResultCallback() {
        @Override
        public void onSuccess(HomeBean bean) {
            // do something
        }
        @Override
        public void onError(String errorCode, String errorMsg) {
            //sdk cache error do not deal
        }
    });

2.3. Operate Family Cached Data

ITuyaHomeDataManager provides the ability to access cached data, the interface entry is TuyaHomeSdk.getDataInstance().

Note: Before obtaining this data, you should call the family's initialization interface TuyaHomeSdk.newHomeInstance("homeId").getHomeDetail() or TuyaHomeSdk.newHomeInstance("homeId").getHomeLocalCache(), then you can get it.

2.4. Family Device Status Change Monitoring

The timing of the status change of the equipment in the family includes:

the change of the dp point of the equipment, the online and offline of the equipment, the change of the equipment information

Note: Currently only valid for wifi devices.

Declaration

public interface ITuyaHomeDeviceStatusListener {

    /**
     * data point value change
     *
     * @param devId device id
     * @param dpStr dps
     */
    void onDeviceDpUpdate(String devId, String dpStr);

    /**
     * device online or offline
     *
     * @param devId  device id
     * @param online online or offline
     */
    void onDeviceStatusChanged(String devId, boolean online);

    /**
     * device info updated, ex: name...
     *
     * @param devId device id
     */
    void onDeviceInfoUpdate(String devId);

}

2.5. Update Family Information

Declaration

void updateHome(String name, double lon, double lat, String geoName, List rooms, boolean overWriteRoom, IResultCallback callback)

Parameters

Parameters Description
name Family name (Support up to 25 characters)
lon Longitude of current family
lat Latitude of the current family
geoName Address of geographical location
rooms Room information
overWriteRoom Whether to overwrite the existing room
callback Result callback

Example

TuyaHomeSdk.newHomeInstance(10000).updateHome(name, lon, lat, geoName, rooms, overWriteRoom, new IResultCallback() {
        @Override
        public void onError(String code, String error) {
            // do something
        }
        @Override
        public void onSuccess() {
            // do something
        }
    });

2.6. Disband Family

Declaration

void dismissHome(IResultCallback callback)

Parameters

Parameters Description
callback Result callback

Example

TuyaHomeSdk.newHomeInstance(10000).dismissHome(new IResultCallback() {
        @Override
        public void onError(String code, String error) {
            // do something
        }
        @Override
        public void onSuccess() {
            // do something
        }
    });

2.7. Add Room

Declaration

void addRoom(String name, ITuyaRoomResultCallback callback)

Parameters

Parameters Description
name Room name
callback Result callback

Example

TuyaHomeSdk.newHomeInstance(10000).addRoom(name, new ITuyaRoomResultCallback() {
        @Override
        public void onError(String errorCode, String errorMsg) {
            // do something
        }
        @Override
        public void onSuccess(RoomBean bean) {
            // do something
        }
    });

2.8. Remove Room

Declaration

void removeRoom(long roomId, IResultCallback callback)

Parameters

Parameters Description
roomId Room ID
callback Result callback

Example

TuyaHomeSdk.newHomeInstance(10000).removeRoom(roomId, new IResultCallback() {
        @Override
        public void onError(String code, String error) {
            // do something
        }
        @Override
        public void onSuccess() {
            // do something
        }
    });

2.9. Sorting Rooms

Declaration

void sortRoom(List<Long> idList, IResultCallback callback)

Parameters

Parameters Description
idList Room ID list
callback Result callback

Example

TuyaHomeSdk.newHomeInstance(10000).sortRoom(idList, new IResultCallback() {
        @Override
        public void onError(String code, String error) {
            // do something
        }
        @Override
        public void onSuccess() {
            // do something
        }
    });

3. Family Member Management

3.1. Add Home Member

Declaration

The field autoAccept in MemberWrapperBean was used to control if the member added should accept the invaitation. If the value was false, the added member shuold call processInvitation() and then he/she can join the family.

void addMember(MemberWrapperBean memberWrapperBean, ITuyaDataCallback<MemberBean> callback)

Parameters

Parameters Description
memberWrapperBean Member information

Example

TuyaHomeSdk.getMemberInstance().addMember(memberWrapperBean, new ITuyaDataCallback<MemberBean>() {
        @Override
        public void onError(String errorCode, String errorMessage) {
            // do something
        }
        @Override
        public void onSuccess(MemberBean result) {
            // do something
        }
    });

3.2. Delete Home Member

Declaration

void removeMember(long memberId, IResultCallback callback)

Parameters

Parameters Description
memberId Member ID

Example

TuyaHomeSdk.getMemberInstance().removeMember(memberId, new IResultCallback() {
        @Override
        public void onError(String code, String error) {
            // do something
        }
        @Override
        public void onSuccess() {
            // do something
        }
    });

3.3. Query the Member List Under Home

Declaration

void queryMemberList(long mHomeId, ITuyaGetMemberListCallback callback)

Parameters

Parameters Description
mHomeId Family ID

Example

TuyaHomeSdk.getMemberInstance().queryMemberList(mHomeId, new ITuyaGetMemberListCallback() {
        @Override
        public void onError(String errorCode, String error) {
            // do something
        }
        @Override
        public void onSuccess(List<MemberBean> memberBeans) {
            // do something
        }
    });

3.4. Update Member Information

Declaration

void updateMember(MemberWrapperBean memberWrapperBean, IResultCallback callback)

Parameters

Parameters Description
memberWrapperBean Member information

Example

TuyaHomeSdk.getMemberInstance().updateMember(memberWrapperBean, new IResultCallback() {
        @Override
        public void onError(String code, String error) {
            // do something
        }
        @Override
        public void onSuccess() {
            // do something
        }
    });

3.5. Get the invitation code To Add a Family Member

Declaration

void getInvitationMessage(long homeId, ITuyaDataCallback callback)

Parameters

Parameters Description
homeId Family ID

Example

TuyaHomeSdk.getMemberInstance().getInvitationMessage(homeId, new ITuyaDataCallback<InviteMessageBean>() {
            @Override
            public void onSuccess(InviteMessageBean result) {
                // onSuc
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                // onErr
            }
        });

3.6. Accept or Refuse To Join the Family

Declaration

void processInvitation(long homeId, boolean action, IResultCallback callBack)

Parameters

Parameters Description
homeId Family ID
action Accept \/ reject

Example

TuyaHomeSdk.getMemberInstance().processInvitation(homeId, action, new IResultCallback() {
        @Override
        public void onError(String code, String error) {
            // do something
        }
        @Override
        public void onSuccess() {
            // do something
        }
    });

3.7. Sort Groups or Devices in Your Home

Declaration

void sortDevInHome(String homeId, List<DeviceAndGroupInHomeBean> list, IResultCallback callback)

Parameters

Parameters Description
homeId Home ID
list Room or group liist. The list element DeviceAndGroupInHomeBean here contains two fields. The one is bizType, which is the target type to sort. You can refer to BizParentTypeEnum for details. Another is bizId, which is the id of target, for example, group id or device id.
callback result callback

Meanings of the enum BizParentTypeEnum:

  • LOCATION
  • MESH
  • ROOM
  • GROUP
  • DEVICE

Example

List<DeviceAndGroupInHomeBean> list = new ArrayList<>();
List<DeviceBean> deviceList = homeBean.getDeviceList();
List<GroupBean> groupList = homeBean.getGroupList();
for (GroupBean bean : groupList) {
    DeviceAndGroupInHomeBean deviceInRoomBean = new DeviceAndGroupInHomeBean();
    deviceInRoomBean.setBizId(bean.getDevId());
    deviceInRoomBean.setBizType(BizParentTypeEnum.GROUP.getType());
    list.add(deviceInRoomBean);
}
for (DeviceBean bean : deviceList) {
    DeviceAndGroupInHomeBean deviceInRoomBean = new DeviceAndGroupInHomeBean();
    deviceInRoomBean.setBizId(bean.getDevId());
    deviceInRoomBean.setBizType(BizParentTypeEnum.DEVICE.getType());
    list.add();
}
TuyaHomeSdk.newHomeInstance(10000).sortDevInHome(homeId, list, new IResultCallback() {
        @Override
        public void onSuccess() {
            // do something
        }
        @Override
        public void onError(String code, String error) {
            // do something
        }
    });

3.8. Log Off Monitoring of Information Changes Below Home

Declaration

void unRegisterHomeStatusListener(ITuyaHomeStatusListener listener)

Parameters

Parameters Description
listener Monitor

Example

// define a listener
ITuyaHomeStatusListener listener = new ITuyaHomeStatusListener() {
        @Override
        public void onDeviceAdded(String devId) {
            // do something
        }
        @Override
        public void onDeviceRemoved(String devId) {
            // do something
        }
        @Override
        public void onGroupAdded(long groupId) {
            // do something
        }
        @Override
        public void onGroupRemoved(long groupId) {
            // do something
        }
        @Override
        public void onMeshAdded(String meshId) {
            // do something
        }
    };
// register a listener somewhere
TuyaHomeSdk.newHomeInstance(10000).registerHomeStatusListener(listener);
// ...
// unregister a listener
TuyaHomeSdk.newHomeInstance(10000).unRegisterHomeStatusListener(listener);

4. Room Information Management

RoomBean

Parameters Type Description
roomId long Room id
name String Room name
deviceList List <DeviceBean> Devices of room
groupList List <GroupBean> Groups of room
displayOrder int Room display order

4.1. Update Room Name

Declaration

void updateRoom(String name, IResultCallback callback)

Parameters

Parameters Description
name New room name

Example

TuyaHomeSdk.newRoomInstance(10000).updateRoom(name, new IResultCallback() {
        @Override
        public void onError(String code, String error) {
            // do something
        }
        @Override
        public void onSuccess() {
            // do something
        }
    });

4.2. Update Room Icon

Room support custom background image, you can get the room background image url as below after upload successed. (This method is new in version 3.19)

RoomBean roomBean = homeBean.rooms.get(index);
String roomBgImageurl = roomBean.iconUrl;

Declaration

void updateIcon(File file, IResultCallback callback);

Parameters

Parameters Description
file Room image
callback callback

Example

TuyaHomeSdk.newRoomInstance(10000).updateIcon(file, new IResultCallback() {
        @Override
        public void onSuccess() {
            // do something
        }
        @Override
        public void onError(String code, String error) {
            // do something
        }
    });

4.3. Add Device to a Room

Declaration

void addDevice(String devId, IResultCallback callback)

Parameters

Parameters Description
devId Device ID

Example

TuyaHomeSdk.newRoomInstance(10000).addDevice(devId, new IResultCallback() {
        @Override
        public void onError(String code, String error) {
            // do something
        }
        @Override
        public void onSuccess() {
            // do something
        }
    });

4.4. Remove Device from a Room

Declaration

void removeDevice(String devId, IResultCallback callback)

Parameters

Parameters Description
devId Device ID

Example

TuyaHomeSdk.newRoomInstance(10000).removeDevice(devId, new IResultCallback() {
        @Override
        public void onError(String code, String error) {
            // do something
        }
        @Override
        public void onSuccess() {
            // do something
        }
    });

4.5. Add Group in a Room

Declaration

void addGroup(long groupId, IResultCallback callback)

Parameters

Parameters Description
groupId Group ID

Example

TuyaHomeSdk.newRoomInstance(10000).addGroup(groupId, new IResultCallback() {
        @Override
        public void onError(String code, String error) {
            // do something
        }
        @Override
        public void onSuccess() {
            // do something
        }
    });

4.6. Remove Group in a Room

Declaration

void removeGroup(Long groupId, IResultCallback resultCallback)

Parameters

Parameters Description
groupId Group ID

Example

TuyaHomeSdk.newRoomInstance(10000).removeGroup(groupId, new IResultCallback() {
        @Override
        public void onError(String code, String error) {
            // do something
        }
        @Override
        public void onSuccess() {
            // do something
        }
    });

4.7. Remove Group or Device From Room

Declaration

void moveDevGroupListFromRoom(List list, IResultCallback callback)

Parameters

Parameters Description
list Group or device

Example

TuyaHomeSdk.newRoomInstance(10000).moveDevGroupListFromRoom(list, new IResultCallback() {
        @Override
        public void onError(String code, String error) {
            // do something
        }
        @Override
        public void onSuccess() {
            // do something
        }
    });

4.8. Sort Groups or Devices in a Room

Declaration

void sortDevInRoom(List<DeviceAndGroupInRoomBean> list, IResultCallback callback)

Parameters

Parameters Description
list Group or device

Example

TuyaHomeSdk.newRoomInstance(10000).sortDevInRoom(list, new IResultCallback() {
        @Override
        public void onError(String code, String error) {
            // do something
        }
        @Override
        public void onSuccess() {
            // do something
        }
    });

4.9. Query room info by devId

Declaration

 RoomBean getDeviceRoomBean(String devId);

Parameters

Parameters Description
devId device Id

Example

TuyaHomeSdk.getDataInstance().getDeviceRoomBean(String devId);

4.10. Query room info by groupId

Declaration

 RoomBean getGroupRoomBean(String devId);

Parameters

Parameters Description
groupId groupd Id

Example

TuyaHomeSdk.getDataInstance().getGroupRoomBean(long groupId);

5. Home Weather

5.1. Get Home's Weather Simple Summary Parameters

Sush as state of weather(clear, cloudy, rainy, and so on),weather icon.

Declaration

void getHomeWeatherSketch(double lon,double lat,IIGetHomeWetherSketchCallBack callback);

Parameters

Parameters Description
lon longitude
lat latitude
callback callback

WeatherBean Description

Parameters Description
condition weather description
temp temperature
iconUrl weather icon
inIconUrl weather icon

Example

TuyaHomeSdk.newHomeInstance(mHomeId).getHomeWeatherSketch(120.075652,30.306265
  new IIGetHomeWetherSketchCallBack() {
    @Override
    public void onSuccess(WeatherBean result) {
    }
    @Override
    public void onFailure(String errorCode, String errorMsg) {
    }
  });

5.2. Get Home's Weather Summary Parameters with More Detail

Such as tempature, humidity, ultraviolet index, air quality.

Declaration

void getHomeWeatherDetail(int limit, Map<String,Object> unit, IGetHomeWetherCallBack callback);

Parameters

Parameters Description
limit list count
unit parameter unit
callback callback

More explanations about the unit:

key value
tempUnit Celsius:1
Fahrenheit:2

For example, when the unit of the data you want to obtain is Celsius unit:

Map<String,Object> units = new HashMap<>();
units.put("tempUnit",1);

Example

Map<String,Object> units = new HashMap<>();
units.put("tempUnit",1);

TuyaHomeSdk.newHomeInstance(mHomeId).getHomeWeatherDetail(10, units, new IGetHomeWetherCallBack() {
    @Override
    public void onSuccess(ArrayList<DashBoardBean> result) {

    }

    @Override
    public void onFailure(String errorCode, String errorMsg) {

    }
});

results matching ""

    No results matching ""