MQTT Interface

From Hubitat Documentation
Revision as of 12:45, 1 May 2019 by Cschwer (talk | contribs) (Created page with "=Overview= '''NOTE: This interface is in alpha status and is liable to change. Once sufficient feedback has been received it will be finalized and the method names will chang...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Overview

NOTE: This interface is in alpha status and is liable to change. Once sufficient feedback has been received it will be finalized and the method names will change. Hubitat allows for opening and maintaining a connection to an MQTT broker from the hub. All code needs to be contained in a driver, there is no option to open an MQTT client connection from an app. Hubitat provides methods to connect and disconnect to the broker, subscribe and publish messages to topics. In addition it is required to create a method in the driver that accepts incoming messages (parse) and another method that will be called with any status updates for the client connection (mqttClientStatus).

Methods

Hubitat Provided Methods

mqttConnect

Signature
void hubitat.helper.InterfaceUtils.alphaV1mqttConnect(DeviceWrapper device, String broker, String clientId, String username, String password)
Parameters
device - The current device that is calling the method.
broker - The url of the broker to connect to.
clientId - The client id to use when connecting to the broker.
username - The username to use when connecting to the broker, use null if no username is necessary.
password - The password to use when connecting to the broker, use null if no password is necessary.

mqttDisconnect

Signature
void hubitat.helper.InterfaceUtils.alphaV1mqttDisconnect(DeviceWrapper device)
Parameters
device - The current device that is calling the method.

User defined methods

parse(String message) - This method is called with any incoming messages from the subscribed topics of the MQTT broker. This is a standard method for drivers.
mqttClientStatus(String message) - This method is called with any status messages from the MQTT client connection (disconnections, errors during connect, etc)