Device Object

From Hubitat Documentation
Revision as of 15:51, 5 April 2020 by Dman2306 (talk | contribs) (Added documentation for most of the updateSetting overloads)
Jump to: navigation, search

The Device object (Technically DeviceWrapper, ChildDeviceWrapper and ParentDeviceWrapper) is composed of methods that allow you to interact with the settings and values of a device. This object is available to Apps that have been given access via a device selection input, as child devices of Apps and other devices and a driver also has access to this via the device object.

events

Retrieve a list of events for the device. By default the maximum number of events returned in the list is 10 which can be overridden by the max option.
Signature
List<Event> events()
List<Event> events(Map options)
Parameters
options - Optional values for getting the list of events. Possible values:
max - The maximum number of events to retrieve.
Returns
List of Event objects for the device


eventsSince

Retrieve a list of events since a date/time.
Signature
List<Event> eventsSince(Date startDate)
List<Event> eventsSince(Date startDate, Map options)
Parameters
startDate - The date/time to list events since.
options - Optional values for getting the list of events. Possible values:
max - The maximum number of events to retrieve.
Returns
A list of Events (defaults to 10 events unless otherwise specified in options)
Examples
// Get events since 8:00 am today
def events = eventsSince(timeToday("08:00"))
// Get a maximum of 5 events
def events = eventsSince(timeToday("08:00"), [max:5])

getName

Retrieve the name of the device.
Signature
String getName()
Parameters
none
Returns
String - The name of the device

setName

Update the name of the device.
Signature
void setName(String name)
Parameters
name - the new name for the device.
Returns
none

getLabel

Retrieve the label of the device.
Signature
String getLabel()
Parameters
none
Returns
String - The label of the device

setLabel

Update the label of the device.
Signature
void setLabel(String label)
Parameters
label - the new label for the device.
Returns
none

hasAttribute

Determines if the device has the specified attribute. This works for both built-in and custom attributes.
Signature
Boolean hasAttribute(String attribute)
Parameters
attribute- The attribute to check for.
Returns
True if the attribute exists, false otherwise.

hasCapability

Determines if the device has the specified capability.
Signature
Boolean hasCapability(String capability)
Parameters
capability - The capability to check for.
Returns
True if the capability exists, false otherwise.

hasCommand

Determines if the device has the specified command. This works for both built-in and custom commands.
Signature
Boolean hasCommand(String command)
Parameters
command - The command to check for.
Returns
True if the command exists, false otherwise.

updateSetting

Updates the value of a setting (preference) to the specified value. If the setting does not exist, this method will create it.
Signature
void updateSetting(String name, Long value)
void updateSetting(String name, Boolean value)
void updateSetting(String name, String value)
void updateSetting(String name, Double value)
void updateSetting(String name, Date value)
void updateSetting(String name, List value)
Parameters
name - The name of the setting to update
value - The value to store in the setting
Returns
None

Additional to be documented

List<Event> eventsBetween(Date startDate, Date endDate)
List<Event> eventsBetween(Date startDate, Date endDate, Map options = null)
List<State> statesSince(String attributeName, Date startDate)
List<State> statesSince(String attributeName, Date startDate, Map options = null)
void sendEvent(Map properties)
void updateSetting(String name, Map options)
void removeSetting(String name)
void clearSetting(String name)
Long getIdAsLong()
String getId()
String getEndpointId()
String getZigbeeId()
Hub getHub()
Map getData()
void updateDataValue(String name, String value)
String getDataValue(String name)
String getDeviceDataByName(String name)
String getStatus()
String getDisplayName()
void setDisplayName(String displayName)
String getDeviceNetworkId()
void setDeviceNetworkId(String dni)
Object currentValue(String attributeName)
Object currentValue(String attributeName, boolean skipCache)
State currentState(String attributeName)
State currentState(String attributeName, boolean skipCache)
Object latestValue(String attributeName)
Object latestValue(String attributeName, boolean skipCache)
State latestState(String attributeName)
State latestState(String attributeName, boolean skipCache)
List<State> getCurrentStates()
List<Command> getSupportedCommands()
List<Attribute> getSupportedAttributes()
List<Capability> getCapabilities()
Date getLastActivity()
Long getParentDeviceId()
Long getParentAppId()
Boolean getIsComponent()
boolean isDisabled()