Class Hue
public final class Hue extends Object
-
Constructor Summary
Constructors Constructor Description Hue(HueBridgeProtocol protocol, String bridgeIp, String apiKey)A basic constructor for initializing the Hue Bridge connection for this library.Hue(String bridgeIp, String apiKey)The basic constructor for initializing the Hue Bridge connection for this library. -
Method Summary
Modifier and Type Method Description booleanbridgeSupportsApiV2()Tells whether the Bridge supports the CLIP API v2, introduced in November 2021.RoomgetAllLights()Returns all lights known by the Bridge.Collection<AmbientLightSensor>getAmbientLightSensors()Returns all the ambient light sensors configured into the Bridge.Optional<AmbientLightSensor>getAmbientSensorByName(String sensorName)Returns a specific ambient sensor by its name.Collection<DaylightSensor>getDaylightSensors()Returns all the daylight sensors configured into the Bridge.Collection<Room>getGroupsOfType(GroupType... groupTypes)Returns all groups of lights that match any of the specified group types.NewLightsResultgetNewLightsSearchStatus()Returns the status of new lights search -- seesearchForNewLights().Optional<PresenceSensor>getPresenceSensorByName(String sensorName)Returns a specific presence sensor by its name.Collection<PresenceSensor>getPresenceSensors()Returns all the presence sensors configured into the Bridge.RootgetRaw()Returns the raw root node information of the REST API.Optional<Room>getRoomByName(String roomName)Deprecated.UseHue.getRoomByName(String)instead.Collection<Room>getRooms()Deprecated.UseHue.getRooms()instead.Optional<Switch>getSwitchByName(String switchName)Returns a specific switch by its name.Collection<Switch>getSwitches()Deprecated.Optional<TemperatureSensor>getTemperatureSensorByName(String sensorName)Returns a specific temperature sensor by its name.Collection<TemperatureSensor>getTemperatureSensors()Deprecated.Optional<Light>getUnassignedLightByName(String lightName)Returns a specific unassigned light by its name.Collection<Light>getUnassignedLights()Returns all lights that do not belong to any group or zone.Collection<Sensor>getUnknownSensors()Returns all the sensors configured into the Bridge.Optional<Room>getZoneByName(String zoneName)Deprecated.UseHue.getZoneByName(String)instead.Collection<Room>getZones()Deprecated.UseHue.getZones()instead.static HueBridgeConnectionBuilderhueBridgeConnectionBuilder(String bridgeIp)Deprecated.UseHue.hueBridgeConnectionBuilder(String)instead.booleanisCaching()Tells whether this instance caches the states of objects, such as lights.voidrefresh()Refreshes the room, lamp, etc.Future<Collection<Light>>searchForNewLights()Orders the Bridge to search for new lights.voidsetCaching(boolean enabled)Controls whether cached states of objects, such as lights, should be used.
-
Constructor Details
-
Hue
The basic constructor for initializing the Hue Bridge connection for this library. Sets up an encrypted but unverified HTTPS connection -- seeHueBridgeProtocol.UNVERIFIED_HTTPS. Use thehueBridgeConnectionBuilder(String)method instead if you do not have an API key yet.- Parameters:
bridgeIp- The IP address of the Hue Bridge.apiKey- The API key of your application.- Since:
- 1.0.0
-
Hue
A basic constructor for initializing the Hue Bridge connection for this library. Use thehueBridgeConnectionBuilder(String)method if you do not have an API key yet.- Parameters:
protocol- The desired protocol for the Bridge connection. Older Bridges require HTTP or UNVERIFIED_HTTPS, as the certificate that the Bridge uses cannot be verified. Defaults to UNVERIFIED_HTTPS since version 2.4.0 when using the other constructor (used to default to HTTP before that), for Philips will eventually deprecate the plain HTTP connection altogether.bridgeIp- The IP address of the Hue Bridge.apiKey- The API key of your application.- Since:
- 1.0.0
-
-
Method Details
-
setCaching
public void setCaching(boolean enabled)Controls whether cached states of objects, such as lights, should be used. Off (
false) by default. If set on (true), querying light states will NOT actually relay the query to the Bridge. Instead, it uses the state that was valid when this method was called, or the state that was valid when subsequent calls to therefresh()method were made.One should use caching when performing multiple queries in a quick succession, such as when querying the states of all the individual lights in a Hue setup.
If caching is already on and you try to enable it again, this method does nothing. Similarly nothing happens if caching is already disabled and one tries to disable it again.
- Parameters:
enabled- Set totrueto have the lights cache their results from the Bridge. Remember to callrefresh()first when you need to retrieve the absolutely current states.- Since:
- 1.2.0
-
isCaching
public boolean isCaching()Tells whether this instance caches the states of objects, such as lights.- Returns:
trueif cached results are returned,falseif all queries are directed to the Bridge.- Since:
- 1.2.0
-
refresh
public void refresh()Refreshes the room, lamp, etc. data from the Hue Bridge, in case it has been updated since the application was started.This method is particularly useful if caching is enabled with the
setCaching(boolean)method. Calls torefresh()will, in that case, refresh the states of the lights.- Since:
- 1.0.0
-
getGroupsOfType
Returns all groups of lights that match any of the specified group types.- Parameters:
groupTypes- Type or types of groups to get.- Returns:
- A Collection of groups matching the requested types.
- Since:
- 1.3.0
-
getRooms
Deprecated.UseHue.getRooms()instead.Returns all the rooms configured into the Bridge. Acts as a shorthand version of callinggetGroupsOfType(GroupType...)with valueGroupType.ROOM.- Returns:
- A Collection of rooms.
- Since:
- 1.0.0
-
getZones
Deprecated.UseHue.getZones()instead.Returns all the zones configured into the Bridge. Acts as a shorthand version of callinggetGroupsOfType(GroupType...)with valueGroupType.ZONE.- Returns:
- A Collection of zones as Room objects.
- Since:
- 1.1.0
-
getRoomByName
Deprecated.UseHue.getRoomByName(String)instead.Returns a specific room by its name.- Parameters:
roomName- The name of a room- Returns:
- A room or
Optional.empty()if a room with the given name does not exist. - Since:
- 1.0.0
-
getZoneByName
Deprecated.UseHue.getZoneByName(String)instead.Returns a specific zone by its name.- Parameters:
zoneName- The name of a zone- Returns:
- A zone or
Optional.empty()if a zone with the given name does not exist. - Since:
- 1.1.0
-
getRaw
Returns the raw root node information of the REST API. Not required for anything but querying the most technical details of the Bridge setup. Note that it is not possible to change the state of the Bridge or the lights by using any values returned by this method: the results are read-only.The results of this method are also always cached, so a call to this method never triggers a query to the Bridge (unless no other queries have been made to the Bridge since this instance of
Huewas constructed). To refresh the cache call therefresh()method.- Returns:
- A Root element, as received from the Bridge REST API. Always returns a cached version of the data.
- Since:
- 1.0.0
-
getUnknownSensors
Returns all the sensors configured into the Bridge.- Returns:
- A Collection of sensors.
- Since:
- 1.0.0
-
getTemperatureSensors
Deprecated.Returns all the temperature sensors configured into the Bridge.- Returns:
- A Collection of temperature sensors.
- Since:
- 1.0.0
- See Also:
Hue.getTemperatureSensors()
-
getSwitches
Deprecated.Returns all the switches configured into the Bridge. Different kinds of switches include, for example, the Philips Hue dimmer switch and the Philips Hue Tap switch.- Returns:
- A Collection of switches.
- Since:
- 2.0.0
- See Also:
Hue.getSwitches()
-
getPresenceSensors
Returns all the presence sensors configured into the Bridge.- Returns:
- A Collection of presence sensors.
- Since:
- 2.0.0
-
getDaylightSensors
Returns all the daylight sensors configured into the Bridge.- Returns:
- A Collection of daylight sensors.
- Since:
- 1.0.0
-
getAmbientLightSensors
Returns all the ambient light sensors configured into the Bridge.- Returns:
- A Collection of ambient light sensors.
- Since:
- 2.0.0
-
getTemperatureSensorByName
Returns a specific temperature sensor by its name.- Parameters:
sensorName- The name of a sensor- Returns:
- A sensor or
Optional.empty()if a sensor with the given name does not exist. - Since:
- 1.0.0
-
getPresenceSensorByName
Returns a specific presence sensor by its name.- Parameters:
sensorName- The name of a sensor- Returns:
- A sensor or
Optional.empty()if a sensor with the given name does not exist. - Since:
- 2.0.0
-
getAmbientSensorByName
Returns a specific ambient sensor by its name.- Parameters:
sensorName- The name of a sensor- Returns:
- A sensor or
Optional.empty()if a sensor with the given name does not exist. - Since:
- 2.0.0
-
getSwitchByName
Returns a specific switch by its name.- Parameters:
switchName- The name of a switch- Returns:
- A switch or
Optional.empty()if a switch with the given name does not exist. - Since:
- 2.0.0
-
getUnassignedLights
Returns all lights that do not belong to any group or zone.- Returns:
- A collection of lights.
- Since:
- 1.4.0
-
getUnassignedLightByName
Returns a specific unassigned light by its name.- Parameters:
lightName- The name of a light- Returns:
- A light or
Optional.empty()if an unassigned light with the given name does not exist. - Since:
- 2.0.0
-
getAllLights
Returns all lights known by the Bridge. This is a convenience method provided by the API, making it easy to, for example, turn on or off all lights at once.
Note that due to the special nature of this group, caching has no effect on this method. Every time this method is called or the state of this group is queried, a call is made directly into the Bridge.
- Returns:
- A
Roomobject containing all the lights known by the Bridge. - Since:
- 2.4.0
-
searchForNewLights
Orders the Bridge to search for new lights. The operation takes some 40-60 seconds -- longer, if there are many new lights found. Returns aFuturethat is resolved with a collection of new lights found, if any.- Returns:
- A
Futurethat is resolved in some 40-60 seconds with the new lights that have been found, if any. - Since:
- 2.6.0
-
getNewLightsSearchStatus
Returns the status of new lights search -- seesearchForNewLights(). Note that you do not need to call this method manually when you are using thesearchForNewLights()method: internally it checks whether the search is finished by calling this exact method. This method is provided as public for convenience in case you need to return to the results later or need to find out about searches performed by some other means than this library.- Returns:
- Status of the last search for new lights, and the new lights, if any.
- Since:
- 2.6.0
- See Also:
searchForNewLights()
-
bridgeSupportsApiV2
public boolean bridgeSupportsApiV2()Tells whether the Bridge supports the CLIP API v2, introduced in November 2021.- Returns:
trueif there is a support for API v2,falseif not.- Since:
- 3.0.0
-
hueBridgeConnectionBuilder
Deprecated.UseHue.hueBridgeConnectionBuilder(String)instead.The method to be used if you do not have an API key for your application yet. Returns aHueBridgeConnectionBuilderthat initializes the process of adding a new application to the Bridge. You can test if you are connecting to a Hue Bridge endpoint before initializing the connection.- Parameters:
bridgeIp- The IP address of the Bridge.- Returns:
- A connection builder that initializes the application for the Bridge.
- Since:
- 1.0.0
-