Difference between revisions of "Device Code"

From Hubitat Documentation
Jump to: navigation, search
(Initial work on describing the code inside a device driver.)
 
(Replaced content with " <big>'''We're moving!''' Please visit http://docs2.hubitat.com for the latest documentation.</big> <big> This document is available at: http://docs2.hubitat.com/en/devel...")
(Tag: Replaced)
 
Line 1: Line 1:
==Overview==
 
The bulk of the work a driver does is done inside it's general code section. This is where you write methods and members using the Groovy programming language to define how you driver functions. Drivers can be very different depending on what they do. A driver that communicates with a ZWave device is going to look very different than one that is a virtual device with nothing physical in the real world or one that communicates over Telnet to a LAN device. This article gives you a general overview of device driver code but they will vary greatly depending on what the device driver is intended to do.
 
  
==Built-In Callback Methods==
+
<big>'''We're moving!''' Please visit http://docs2.hubitat.com for the latest documentation.</big>
Device drivers can contain a few built-in callback methods that are triggered but the Hubitat environment in response to certain actions.  
 
  
===<code>installed</code>===
+
<big>
:This method is called when the device is first created and can be used to initialize any device specific configuration and setup.
+
This document is available at: http://docs2.hubitat.com/en/developer/driver/code
 
+
</big>
:;Signature
 
:: <code>void installed()</code>
 
 
 
===<code>uninstalled</code>===
 
:This method is called when the device is removed to allow for any necessary cleanup.
 
 
 
:;Signature
 
:: <code>void uninstalled()</code>
 
 
 
===<code>updated</code>===
 
:This method is called when the preferences of a device are updated.
 
 
 
:;Signature
 
:: <code>void updated()</code>
 
 
 
===<code>parse</code>===
 
:This method is called in response to a message received by the device driver. Depending on the driver this could be from any number of sources. This could be a Z-Wave message, Zigbee message, telnet message, websocket message, etc. Depending on the type of message received you will likely need to parse the <code>description</code> string into something more useful. The following list of methods are useful for decoding the description:
 
 
 
:* MQTT - <code>interfaces.mqtt.parseMessage</code>
 
:* RAW_LAN - <code>parseLanMessage</code>
 
:* Zigbee - <code>zigbee.parse</code>
 
:* Z-Wave - <code>zwave.parse</code>
 
 
 
:;Signature
 
:: <code>Event parse(String description)</code>
 
 
 
==User Defined Methods==
 
User defined methods are where your driver does "everything else." It is where you implement commands, define callbacks for scheduled events, create callbacks for event subscriptions, etc. Essentially you can do just about anything in a user defined method that you can do in a normal Groovy method.
 

Latest revision as of 03:59, 25 September 2022

We're moving! Please visit http://docs2.hubitat.com for the latest documentation.

This document is available at: http://docs2.hubitat.com/en/developer/driver/code