Kotlin SDK

Shade's Kotlin SDK provides simple type-safe access to your Hue lights. Shade is built using Kotlin's Coroutines to provide a simple straightforward API on Android or the JVM.

Set up the SDK in Gradle

Shade's SDK is available in Maven Central, with the with the following coordinates in your build.gradle file

implementation("com.inkapplications.shade:core:2.+")

Create a Shade Object

All of Shade's commands can be run through the Shade object. To use it, you can start by creating an Instance of the class for your application:

val shade = Shade()

Bridge Discovery

The discovery process uses Hue's API to find Hue Bridges on the local network. This is the only command in the SDK that requires an internet connection, and is only used to find bridges. If you know the IP address of the hue bridge that you want to connect to, this step can be skipped.

Request a list of local devices on the network with the getDevices() command:

val devices = shade.onlineDiscovery.getDevices()

Authorize with the Hue Bridge

Shade's Auth module can be used to obtain an access token from the hue bridge using it's single button authorization.

To request a token call the awaitToken() method, providing information about your application:

val token = shade.auth.awaitToken(
    appId = AppId(
        appName = "MyApp",
        instanceId = "android",
    ),
)

This will suspend until the button on the hue bridge is pressed and an AuthToken is returned. Shade will automatically set this token for use internally. However, you should save the returned token for future connections.

Optionally, you may set a maximum number of retries and change the timeout between checks that is used for authorization by including the retries or timout arguments when calling awaitToken.

Control Lights

Individual lights can be controlled through the lights module:

shade.lights.updateLight(
    id = lightId,
    parameters = LightUpdateParameters(
        brightness = 10.percent,
    ),
)

The lights module supports the following actions:

Configure Rooms

Rooms can be created and updated through the rooms module:

shade.rooms.createRoom(
    parameters = RoomCreateParameters(
        metadata = RoomMetadata(
            name = "Game Room",
            archetype = RoomArchetype.Recreation,
        ),
        children = listOf(lightReference),
    ),
)

The rooms module supports the following actions:

Configure Zones

Zones can be created and updated through the zones module:

shade.zones.listZones()

The zones module supports the following actions:

Configure Grouped Lights

Grouped Light resources can be fetched and updated groupedLights module:

shade.groupedLights.listGroups()

The zones module supports the following actions:

Configure Devices

Devices information can be retrieved/updated through the devices module:

shade.devices.listDevices()

The devices module supports the following actions:

Resources

Bridge API resources can be retrieved using the resources module:

shade.resources.listResources()

Configure Scenes

Scenes can be controlled through the scenes module:

shade.scenes.listScenes()