The driver definition provides the Hubitat Elevation hub with information about a driver you wish to create. The format is slightly different from an app as the definition must appear inside of a metadata
block. Additionally, it allows you to define the capabilities, commands, and attributes associated with the driver.
metadata {
definition(
// ...
) {
// ...
}
}
author
- The author of this driver (often the author's real name)
description
- A text description of the app that is displayed in the pop-up when the Add User App button is selected
importUrl
- The URL where the Groovy code for this app can be found (raw text, no formatting); will be pre-filled when Import button is selected in editor to facilitate updating driver via this manner.
name
- The name of the app
namespace
- The namespace within which the Groovy class for the application will be stored
A device driver can provide one or more capabilities. Capabilities are defined by the Hubitat environment. When you specify that a driver supports a specific capability, you must also implement any commands it requires. The list of supported capabilities can be found in the Driver Capability List
capability "Capability Name"
Fingerprints provide a way for you to tell Hubitat how to identify a Zigbee or Z-Wave device based on certain properties and characteristics of the device.
To generate a fingerprint for a device already paired to the hub, switch to the "Device" driver, run the "Get Info" command, and observe the "fingerprint" output in "Logs." These can also be built manually if you know the required information ("clusters" corresponds to "command classes" for Z-Wave). The "deviceJoinName" parameter is currently not used.
fingerprint profileId: "profileId", inClusters: "clusters", outClusters: "clusters", manufacturer: "manufacturerId", model: "modelId", deviceJoinName: "name"
fingerprint deviceId: "id", inClusters: "clusters", outClusters: "clusters", mfr: "manufacturerId", prod: "productTypeId", deviceJoinName: "name"
Sometimes you will work with a device that has a command that does not exist in one of the existing capabilities. Hubitat gives you the ability to define custom commands to support these scenarios. Commands can also have parameters allowing you to define how data is passed to the command.
parameters
- a list of the parameters to pass to the command. Each parameter is, itself, a map that defines details about the parameter. See below for information on defining parameters.
The simplest way of defining parameters is to just specify a list of types. The parameters can be of type string
, number
, date
, enum
, and json_object
. When specified as a list of types, no validation is performed.
An example of this simple format is:
command "myCommand", ["string", "number"]
An expanded format also exists that allows you to provide more details about the parameter such as its name, whether or not it is required, and in the case of an enum, the available values. In this mode each parameter is specified as a map with the following entries:
name
- The name of the parameter. If the name ends with an asterisk (*) the parameter is considered required.type
- The type of the parameter which can be any of STRING
, NUMBER
, DATE
, ENUM
, JSON_OBJECT
, or COLOR_MAP
. Note that a driver can only have a single command that accepts a COLOR_MAP
.description
- The description of the parameter that is shown in the tooltip when you hover over the parameter.constraints
- A list of the valid options for an ENUM
command "commandName"
command "commandName", parameters
Sometimes you will work with a device that has an attribute that does not exist in one of the existing capabilities. Hubitat gives you the ability to define custom attributes to support these scenarios.
attribute "AttributeName", "type"
attribute "EnumAttribute", "enum", values
type
- The type of the attribute. This can be string
, number
, or enum
.
values
- If the type is enum, you must also provide a Groovy list of values that the enum accepts.
definition(
name: "My First Driver",
namespace: "myfirstdriver",
author: "John Smith"
) {
capability "Actuator"
capability "Switch"
command "myCommand"
attribute "myAttribute", "string"
attribute "enumAttribute", "enum", ["value 1", "value 2"]
}