Driver Object
Driver Object
These methods are available for use in driver code.
TIP: See also Common Methods, which includes methods available to both apps and drivers.
Hubitat-Provided Methods
addChildDevice
Creates a new child device and returns that device from the method call.
Signature
-
ChildDeviceWrapper addChildDevice(String namespace, String typeName, String deviceNetworkId, Map properties = [:]) -
ChildDeviceWrapper addChildDevice(String typeName, String deviceNetworkId, Map properties = [:])
Parameters
-
namespace- The namespace of the child driver to add as a child device (optional, if not specified it will default the 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.
-
Returns
ChildDeviceWrapper
getChildDevices
Gets a list of all child devices for this device.
Signature
List<ChildDeviceWrapper> getChildDevices()
Parameters
None
Returns
List<ChildDeviceWrapper>
getChildDevice
Gets a specific child device with the device network id specified.
Signature
ChildDeviceWrapper getChildDevice(String deviceNetworkId)
Parameters
deviceNetworkId- The unique identifier for the device
Returns
ChildDeviceWrapper
deleteChildDevice
Deletes a specific child device with the device network id sepcified.
Signature
void deleteChildDevice(String deviceNetworkId)
Parameters
deviceNetworkId- The unique identifier for the device
Returns
None
getParent
Returns the parent device (ParentDeviceWrapper) or app (InstalledAppWrapper) when called from a child device.
Signature
Object getParent()
Returns
The ParentDeviceWrapper or InstalledAppWrapper
getDataValue
Get a data value that was set for this device.
Signature
String getDataValue(String name)
Parameters
name- The String value of the data item.
Returns
String - The value of the data.
getDeviceDataByName
DEPRECATED: See getDataValue; this method is a wrapper for getDataValue.
getRoomName
Returns the user-specified name of the Room to which the user has assigned this device, or null if no room assigned.
Signature
String getRoomName()
Parameters
None
Returns
String - The name of the assigned room, or null if no room assigned.
getRoomId
Returns the unique ID of the Room to which the user has assigned this device.
Signature
String getRoomId()
Parameters
None
Returns
Long - The unique ID of the assigned room
updateDataValue
Update or create a data value for this device.
Signature
void updateDataValue(String name, String value)
Parameters
-
name- The name of the data item to store. -
value- The value of the data item to store.
Returns
None
removeDataValue
Remove a data value from a device.
Signature
void removeDataValue(String name)(Since 2.2.1)
Parameters
name- The name of the data item to remove.
Returns
None.
sendHubCommand
Use this method to send a HubAction immediately.
Signature
void sendHubCommand(HubAction hubAction)
Parameters
hubAction- The HubAction object to send.
Returns
none
createEvent
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.
Signature
Map createEvent(Map options)
Parameters
optionsidentical to those forsendEvent()(see below)
Example
createEvent(name: "switch", value: "off")
Returns
Mapwith event data
sendEvent
Fires 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.)
Signature
void sendEvent(Map properties)
Parameters
properties- aMapof 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"%"forlevelor omitted forswitch)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 totrueto 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)
Example
sendEvent(name: "colorTemperature", value: 2700, unit: "K")
Returns
none
User-Defined Methods
For callback methods — executed in response to certain actions in the Hubitat environment — and more on driver code, see: Device Code.
Additional to be Documented
Map getState()Zwave getZwave()Zigbee getZigbee()HubAction response(String cmd)HubAction response(hubitat.zwave.Command cmd)HubMultiAction response(List cmds)Short getZwaveHubNodeId()ListeventsSince(Date startDate, Map options = null)void telnetConnect(Map options, String ip, int port, String username, String password)void telnetConnect(String ip, int port, String username, String password)void telnetClose()ListdelayBetween(Listcmds, Long delay)ListdelayBetween(Listcmds)