These methods are available for use in driver code.
TIP: See also Common Methods, which includes methods available to both apps and drivers.
Creates a new child device and returns that device from the method call.
ChildDeviceWrapper addChildDevice(String namespace, String typeName, String deviceNetworkId, Map properties = [:])
ChildDeviceWrapper addChildDevice(String typeName, String deviceNetworkId, Map properties = [:])
namespace - The namespace of the child driver to add as a child device (optional, if not specified it will default to the namespace of the parent)
typeName - The name of the child driver to add as a child device
deviceNetworkId - unique identifier for this device
properties - optional parameters for this child device. Possible values:
boolean isComponent - true or false, if true, device will still show up in device list but will not be able to be deleted or edited in the UI. If false, device can be modified/deleted on the UI.
String name - name of child device, if not specified, driver name is used.
String label - label of child device, if not specified it is left blank.
ChildDeviceWrapper
Gets a list of all child devices for this device.
List<ChildDeviceWrapper> getChildDevices()None
List<ChildDeviceWrapper>
Gets a specific child device with the device network id specified.
ChildDeviceWrapper getChildDevice(String deviceNetworkId)deviceNetworkId - The unique identifier for the deviceChildDeviceWrapper
Deletes a specific child device with the device network id specified.
void deleteChildDevice(String deviceNetworkId)deviceNetworkId - The unique identifier for the deviceNone
Returns the parent device (ParentDeviceWrapper) or app (InstalledAppWrapper) when called from a child device.
Object getParent()The ParentDeviceWrapper or InstalledAppWrapper
Get a data value that was set for this device.
String getDataValue(String name)name - The String value of the data item.String - The value of the data.
DEPRECATED: See getDataValue; this method is a wrapper for getDataValue.
Returns the user-specified name of the Room to which the user has assigned this device, or null if no room assigned.
String getRoomName()None
String - The name of the assigned room, or null if no room assigned.
Returns the unique ID of the Room to which the user has assigned this device.
String getRoomId()None
Long - The unique ID of the assigned room
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.
Use this method to send a HubAction immediately.
void sendHubCommand(HubAction hubAction)hubAction - The HubAction object to send.none
Creates a Map representing data for an event. This will not fire an event on its own; the resulting Map (or a List of such Map objects) must be returned from the parse() method in the driver. Alternatively, use sendEvent() to create and fire an event (our recommendation). These methods are otherwise identical.
Map createEvent(Map options)options identical to those for sendEvent() (see below)createEvent(name: "switch", value: "off")Map with event dataFires an event, i.e., sets the value of an attribute based on the values in the provided map. (Attributes can be seen under Current States on the device detail page in the regular hub interface.)
void sendEvent(Map properties)properties - a Map of properties for the event. Valid keys are:
String name (required) - name of the event (normally the an name of a device attribute)value (required) - value of the event (data type should match the type defined for the attribute as defined by either the capability or custom attribute type)String unit - units corresponding to the value (e.g., could be "%" for level or omitted for switch)String descriptionText - a human-friendly description of the event, optional but often provided in a format like "[Device name] [event name] is [event value]," possibly with additional information, e.g., "Living Room Dimmer level is 50%" or "Bedroom Button pushed is 1 [physical]".Boolean isStateChange - set to true to force an event to be generated even if the new value is the same as the old value (optional and usually omitted in favor of default filtering by platform; button events are one case where it is often needed)String type - the type of event, normally "physical" (generated by a physical action on the device itself) or "digital" (generated as a result of a command sent from the hub); optional (see the Event object)data - additional data to attach to the event; a Map is stored as JSON (see getJsonData() on the Event object), and any other value is converted to a String; optionalString linkText - the display name to use for the event's source; optionalsendEvent(name: "colorTemperature", value: 2700, unit: "K")none
Returns the map that stores this device's state, also available as the state property (e.g., state.lastPoll = now()).
Map getState()None
The state Map. Keys and values are defined by the driver.
Deletes all current attribute states for this device.
void deleteAllCurrentStates()None
none
Retrieve a list of events for the device since a date/time.
List<Event> eventsSince(Date startDate, Map options = null)startDate - The date/time to list events since (inclusive).options - Optional values for getting the list of events. Possible values:
max - The maximum number of events to retrieve (defaults to 10).A list of Event objects (defaults to 10 unless otherwise specified in options)
Tests whether a device attribute value differs from its current stored value.
boolean isStateChange(DeviceWrapper device, String name, String value)device - Device whose attribute state is checked.name - Attribute name.value - Proposed text value.true if the stored value differs from the proposed value (or if there is no current value and the proposed value is not empty), false otherwise.
Returns the display name used as an event link label.
String getLinkText(DeviceWrapper device)device - Device whose display name supplies the label.Device display name.
Adds a delay between each of the command strings in a list. The delay is 100 milliseconds unless otherwise specified.
List<String> delayBetween(List<String> cmds)List<String> delayBetween(List<String> cmds, Long delay)cmds - The list of command strings to separate.delay - The delay between commands, in milliseconds (defaults to 100).A new list containing the commands with a delay between each pair; the original list is not modified.
Creates a hub action from a protocol command. Accepts a formatted Z-Wave, Zigbee, or Matter command String, a Z-Wave command object, or a list of commands.
HubAction response(Command cmd)HubMultiAction response(List cmds)HubAction response(String cmd)cmd - The command to send: a formatted Z-Wave, Zigbee, or Matter command String, or a Z-Wave command object.cmds - A list of commands or formatted actions to include.A HubAction (a HubMultiAction when given a list). For a String command, null if the command is not for a supported protocol.
Returns the Zigbee helper object; also available as the zigbee property. See Zigbee Object.
Zigbee getZigbee()None
The Zigbee object
Returns the Z-Wave helper object; also available as the zwave property. See Z-Wave Object.
Zwave getZwave()None
The Zwave object
Returns the Matter helper object; also available as the matter property. See Matter Object.
Matter getMatter()None
The Matter object
Returns the object that provides access to Hubitat interfaces such as MQTT, raw sockets, and WebSockets; also available as the interfaces property. See Interfaces.
InterfaceHelper getInterfaces()None
The interface helper object
Returns the hub's Z-Wave node id.
Short getZwaveHubNodeId()None
Hub node id as a Short; the newer Z-Wave stack reports node 1.
Returns the Z-Wave generic and specific device class as hexadecimal digits.
String getZwaveDeviceType()None
Two-byte hexadecimal device class when available, otherwise null.
Reports whether this Z-Wave device listens for commands without being polled.
Boolean isZwaveListening()None
True when the node is listening or frequently listening, false when it is not, or null when the device is not Z-Wave or its node is unavailable.
Adds the security encapsulation (S0 or S2) required by this device's stored Z-Wave pairing data to a Z-Wave command, if it is required.
String zwaveSecureEncap(Command cmd)String zwaveSecureEncap(String cmd)cmd - The command to encapsulate: a hexadecimal Z-Wave command String or a Z-Wave command object.The formatted command, with security encapsulation added when required.
Opens (or reuses) this device's Telnet connection. Use the options variant for additional connection settings.
void telnetConnect(Map options, String ip, int port, String username, String password)void telnetConnect(String ip, int port, String username, String password)options - Optional Telnet settings; null uses the interface defaults.
ip - Remote host address.port - Remote Telnet port.username - Login name passed to the Telnet controller.password - Password passed to the Telnet controller.none
See also the Telnet Interface page.
Closes this device's Telnet interface.
void telnetClose()None
none
See also the Telnet Interface page.
Returns the number of queued hub commands for this device execution.
int getPendingHubCommandCount()None
Number of commands waiting in the device command queue.
Parses a signed hexadecimal string as an integer.
Long hexStrToSignedInt(String hexStr)hexStr - Hexadecimal digits to parse.Parsed signed value, or null when the input is null or empty.
Parses an unsigned hexadecimal string as an integer.
Long hexStrToUnsignedInt(String hexStr)hexStr - Hexadecimal digits to parse.Parsed unsigned value, or null when the input is null or empty.
Formats an integer as a hexadecimal string with a minimum byte width.
String intToHexStr(Long value, Integer minBytes = 1)value - Integer to format.minBytes - Optional; Minimum output width in bytes; defaults to 1.Uppercase hexadecimal string, or null when value is null.
Converts a value to a double and clamps it to an inclusive range.
Double limitDoubleRange(Object value, double min, double max)value - Value parsed as a number; invalid text becomes zero before clamping.min - Inclusive lower bound.max - Inclusive upper bound.Parsed double clamped between min and max.
Converts a value to an integer and clamps it to an inclusive range.
Integer limitIntegerRange(Object value, int min, int max)value - Value parsed as a number; invalid text becomes zero before clamping.min - Inclusive lower bound.max - Inclusive upper bound.Parsed integer clamped between min and max.
Parses a relaxed JSON-style object string into a map.
Map stringToMap(String str)str - String containing quoted or unquoted map keys and values; square brackets are converted to braces before parsing.Map with String keys and recursively parsed JSON-compatible values (maps, lists, strings, numbers, booleans, or null); an empty or null string returns an empty map. Invalid non-empty input can throw a parse exception.
For callback methods — executed in response to certain actions in the Hubitat environment — and more on driver code, see: Device Code.