This project provides a java wrapper over the SwitchBot API v1.1 (https://github.com/OpenWonderLabs/SwitchBotAPI)
It presently implements the device apis, but may be updated in the future to support scenes and webhooks as well.
- Listing devices
SwitchBotApi instance = SwitchBotApi.getInstance(token, secret); List<Device> devices = instance.getDeviceApi().getDevices(); - Getting battery status of a device:
SwitchBotApi instance = SwitchBotApi.getInstance(token, secret); List<Device> devices = instance.getDeviceApi().getDevices(); Device status = instance.getDeviceApi().getDeviceStatus(devices.get(0).getDeviceId()); System.out.println("" + status.getBattery()); - Send command to opening a curtain
SwitchBotApi instance = SwitchBotApi.getInstance(token, secret); instance.getDeviceApi().getDevices().stream() .filter(device -> IDeviceTypes.CURTAIN.equals(device.getDeviceType())) .filter(Device::isMaster) .findAny() .ifPresent(curtain -> { try { instance.getDeviceApi() .sendDeviceControlCommands( curtain.getDeviceId(), IDeviceCommands.CURTAIN_CLOSE); } catch (IOException theE) { theE.printStackTrace(); } }); - Send command to turn on a plug mini
SwitchBotApi instance = SwitchBotApi.getInstance(token, secret); instance.getDeviceApi().getDevices().stream() .filter(device -> IDeviceTypes.PLUG_MINI.equals(device.getDeviceType())) .findAny() .ifPresent(plug -> { try { instance.getDeviceApi() .sendDeviceControlCommands( plug.getDeviceId(), IDeviceCommands.PLUG_MINI_ON); } catch (IOException theE) { theE.printStackTrace(); } });