The device object (technically com.hubitat.app.DeviceWrapper
, com.hubitat.app.ChildDeviceWrapper
, and com.hubitat.app.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 well as child devices of apps and parent devices. The device driver itself also has access via the device
object.
Retrieve the current value of an attribute. (Note: If you are looking to set the value of an attribute, use sendEvent()
or equivalent.)
Object currentValue(String attributeName)
Object currentValue(String attributeName, boolean skipCache)
attributeName
- The attribute to get the current value of.skipCache
- Optional; defaults to false
. If true
, do not use the cached value of the attribute (values are cached during a single execution of the driver); instead force the system to read the latest from the database.The current value of an attribute.
Deletes the value of an attribute. (Not recommended for attributes required by any capabilities or custom attributes defined in the driver.)
void deleteCurrentState(String attributeName)
attributeName
- The attribute to remove the current value ofnone
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.
List<Event> events()
List<Event> events(Map options)
options
- Optional values for getting the list of events. Possible values:
max
- The maximum number of events to retrieve.List of Event objects for the device
Retrieve a list of events since a date/time.
List<Event> eventsSince(Date startDate)
List<Event> eventsSince(Date startDate, Map options)
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.A list of Events (defaults to 10 events unless otherwise specified in options)
// 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])
Retrieve the name of the device.
String getName()
none
String
- The name of the device
Update the name of the device.
void setName(String name)
name
- the new name for the device.
none
Retrieve the label of the device.
String getLabel()
none
String
- The label of the device
Update the label of the device.
void setLabel(String label)
label
- the new label for the device.
none
Determines if the device has the specified attribute. This works for both built-in and custom attributes.
Boolean hasAttribute(String attribute)
attribute
- The attribute to check for.
True if the attribute exists, false otherwise.
Determines if the device has the specified capability.
Boolean hasCapability(String capability)
capability
- The capability to check for.
True if the capability exists, false otherwise.
Determines if the device has the specified command. This works for both built-in and custom commands.
Boolean hasCommand(String command)
command
- The command to check for.
True if the command exists, false otherwise.
Object getSetting(String name)
String name
: name of settingValue of the setting with the specified name
Updates the value of a setting (preference) to the specified value. If the setting does not exist, this method will create it.
void updateSetting(String name, Map options)
options
- Map
with keys type
and value
, e.g.,[type: "number", value: 5]
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)
name
- The name of the setting to updatevalue
- The value to store in the settingNone
Removes specified setting from saved settings (device preferences)
void removeSetting(String name)
String name
- name of setting to removeNone
Get all data values for this device.
Map getData()
None
Map
- All data values.
Get a data value that was set for this device.
String getDataValue(String name)
DEPRECATED: See getDataValue
; this method is a wrapper for getDataValue.
Update or create a data value for this device.
void updateDataValue(String name, String value)
name
- The name of the data item to store.value
- The value of the data item to store.None.
Remove a data value from a device.
void removeDataValue(String name)
(Since 2.2.1)
name
- The name of the data item to remove.
None.
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 clearSetting(String name)
Long getIdAsLong()
String getId()
String getEndpointId()
String getZigbeeId()
Hub getHub()
String getStatus()
String getDisplayName()
void setDisplayName(String displayName)
String getDeviceNetworkId()
void setDeviceNetworkId(String dni)
State currentState(String attributeName)
- same as currentValue()
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()