Library Definition

From Hubitat Documentation
Revision as of 20:14, 5 June 2022 by RobertM (talk | contribs)
Jump to: navigation, search


The library definition provides the Hubitat Elevation hub with information about the library, which can be added to Libraries Code in the hub Developer Tools. Libraries provide a way to share code among multiple apps or drivers by defining a library with variables, methods, etc. just as they would appear in app/driver:

library (
 author: "myName",
 category: "samples",
 description: "Some description",
 name: "SampleLibrary1",
 namespace: "myNamespace",
 documentationLink: ""

// put methods, etc. here

The name and namespace can include only letters (upper or lower case), numbers, dots, dashes, and underscores. It is recommended the namespace be unique to you as a developer.

Using Libraries in Apps or Drivers

To use a library in an app or driver, begin a line with #include (no spaces are allowed before the # symbol), followed by a space, the library namesapce, a period, and the library name. For example, to include the above library:

#include myNamespace.SampleLibrary1

When the app or driver is saved, the “included” code will be substituted behind the scenes. All apps/drivers using a library are recompiled when the library is changed. You can select the download icon next to Import button to see exactly how the include gets into the source code (or to download a full version for distribution if you do not want to share the app/driver and library code separately).