-
Notifications
You must be signed in to change notification settings - Fork 1
Examples
The following will provide an overview of the implementation of the GoveeController class into a Java project.
Before beginning make sure you have an API key provided by Govee. Instructions for getting this API can be found in the readme.md.
The GoveeController has a single constructor that accepts a String representing your API key. This value will be stored for all future API calls.
GoveeController controller = new GoveeController("API_KEY");
Govee sets a limit of 100 API calls per minute. To check your current usage you can call getRateLimit()
. This will return a map containing useful information regarding your current usage of the API.
Map<String, List<String>> map = controller.getRateLimit();
for(Map.Entry<String, List<String>> entry : map.entrySet()
System.out.println(entry.getKey() + "" + entry.getValue());
Once your main controller object is instantiated, the first call you'll need to make is to the getConnectedDevices()
method. This will return a JSONObject containing the response from Govee's API. It'll contain the MAC addresses and Device Models as well as the custom names of your devices.
JSONObject response = controller.getConnectedDevices();
You'll either need to read the JSON manually or scrape it for the Device
and Model
fields.
Govee allows for the retrieval of specific device information. This is implemented via the getDeviceState()
method. The method can be called via the following
controller.getDeviceState(macAddress, model);
The GoveeController class has an included enum called Device
which contains the values ON
and OFF
. This is the first parameter in the turnDeviceOnOff()
method.
controller.turnDeviceOnOff(Device.ON, macAddress, model);
To set the brightness of your device use the setBrightness()
method. The brightness value must be an integer between 0-100.
controller.setBrightness(75, macAddress, model);
White lights often are described as having a "temperature". This setting is available through the API via the setColorTem()
method. The temp must be an integer between 2000-9000
controller.setColorTem(5000, macAddress, model);
To set the RGB values of your lights, use the setRGB()
method. Each RGB value must be between 0-255.
//All Red
controller.setRGB(255, 0, 0, macAddress, model);
//All Green
controller.setRGB(0, 255, 0, macAddress, model);
//All Blue
controller.setRGB(0, 0, 255, macAddress, model);
If you for some reason have multiple API keys for different devices, the updateAPIKey()
will allow you to change the API key used when making requests.
controller.updateAPIKey("NEW_API_KEY");