The bulk of the work an app does is done inside its general code section. This is where you write methods and other code using the Groovy programming language to define how your app functions. Apps can be very different depending on what they do. For most apps — ones that are used to create automations, as most apps are — an app may subscribe to device or location events, run a handler in response, and run commands on other devices or schedule a job that will execute later with its own handler method. A very different "service manager" type of app may assist in the integration of LAN or cloud devices or make adding these devices to Hubitat easier.
This article gives you a general overview of Hubitat app code, but how you write an app will depend on exactly what you want the app to do.
Apps should, at minimum, contain a few built-in callback methods that are triggered but the Hubitat environment in response to certain actions.
This method is called when the app is first installed (via the Done or Install button, or upon first open if installOnOpen
is true
) and can be used to initialize any specific configuration or setup.
void installed()
This method is called when the app is removed to allow for any necessary cleanup.
void uninstalled()
This method is called when the preferences of an app are updated, i.e., when the user selects Done in the interface.
void updated()
Apps that make use of hub variables will likely want to implement the callback method for handling hub variable renames; see Hub Variable API. Other apps may require handlers for HTTP endpoint mappings or other methods as required by the way in which you write the app.
User-defined methods are where your app does "everything else." If you have created subscriptions or scheduled jobs that will run handler methods, you should define them here, for example.
For a minimal app example, see App Overview. Continue with the suggested documentation after the overview to continue learning more about how to build real, functional Hubitat Elevation apps.