Device: Disconnect Trigger
The Device: Disconnect Trigger fires a workflow whenever one or more devices disconnect from the Losant Platform, via the MQTT broker or whenever the connection status is changed to “disconnected” using the REST API.
Node Properties
The behavior of the Device: Disconnect Trigger varies depending on the type of workflow it is utilized in.
Application Workflows
The Device: Disconnect Trigger can be configured with one or more specific devices, or a selection of tags (or both). When a device that matches anything in the selection disconnects from Losant, the workflow will trigger. See the device query documentation for more info about how ID and tag matching works.
In the above example, the workflow will be triggered whenever any device that has a type=Smoke Detector
tag disconnects from Losant.
Edge Workflows
For Edge Workflows, you cannot use device queries. Instead, it will trigger when the Edge Compute Device running the Edge Workflow disconnects from Losant.
Payload
The payloads associated with the Device: Disconnect Trigger depend on the type of workflow the trigger is used in.
Application Workflow Payload
The trigger’s initial payload includes information about the device that caused the workflow to fire. Additionally, it includes a data
object with the following properties:
address
: The client IP address.connectedAt
: A Date object representing the time the device last connected.disconnectReason
: A human-readable explanation of why the device disconnected if one is available (i.e. “Keepalive Timeout”).messagesFromDevice
: The number of messages sent from the device to the MQTT broker during the connection period. This includes state reports and any messages published by the device on custom topics.messagesToDevice
: The number of messages sent from the MQTT broker to the device during the connection period. This includes device commands and any messages received on custom topics the device is subscribed to.method
: The method used to connect to Losant (either “mqtt” or “rest”).secure
: Indicates whether the connection is secure (true) or insecure (false).
In the general case, a Device: Disconnect workflow payload in an Application Workflow looks like the following:
{
"applicationId": "555555555555eeeeeeeeeeee",
"applicationName": "My Great Application",
"data": {
"address": "192.168.0.1",
"connectedAt": Fri Feb 19 2016 17:26:00 GMT-0500 (EST),
"disconnectReason": "<Human-readable explanation of disconnection cause>",
"messagesFromDevice": 456,
"messagesToDevice": 123,
"method": "<mqtt|rest>",
"secure": true
},
"device": {
"_etag": "\"567-SY26IHrVRzUBMUwxnY59Fn6vOvo\"",
"applicationId": "555555555555eeeeeeeeeeee",
"attributes": {
"exampleNumber": {
"attributeTags": {
"attrTagKey": "tagValue1"
},
"dataType": "number",
"description": "",
"name": "exampleNumber"
},
"exampleString": {
"attributeTags": {
"attrTagKey": "tagValue2"
},
"dataType": "string",
"description": "",
"name": "exampleString"
}
},
"creationDate": "2018-03-16T18:19:03.376Z",
"description": "",
"deviceClass": "standalone",
"deviceId": "222222222222bbbbbbbbbbbb",
"id": "222222222222bbbbbbbbbbbb",
"lastUpdated": "2020-08-26T13:09:11.814Z",
"name": "My Great Device",
"tags": {
"aTagKey": [
"exampleTagValue"
],
"tagWithMultipleValues": [
"tagValue",
"anotherTagValue"
]
}
},
"deviceName": "My Great Device",
"deviceTags": {
"aTagKey": [
"exampleTagValue"
],
"tagWithMultipleValues": [
"tagValue",
"anotherTagValue"
]
},
"flowId": "333333333333cccccccccccc",
"flowName": "My Great Workflow",
"flowVersion": "myFlowVersion",
"globals": {
"aJsonGlobal": {
"key": "value"
},
"aNumberGlobal": 42,
"aStringGlobal": "My value"
},
"relayId": "<ID of the resource that disconnected the device>",
"relayType": "<apiToken|device|flow|user>",
"time": Fri Feb 19 2016 17:26:00 GMT-0500 (EST),
"triggerId": "<trigger key>",
"triggerType": "deviceIdDisconnect"
}
Edge Workflow Payload
The payload’s data
object contains the following properties:
lastConnectTime
: A Date object representing the time the device last connected.reason
: A human-readable explanation of why the device disconnected if one is available (i.e. “MQTT offline”).
In the general case, a Device: Disconnect payload in an Edge Workflow looks like the following:
{
"agentEnvironment": {
"EXAMPLE": "Environment Variable"
},
"agentVersion": "1.31.0",
"applicationId": "555555555555eeeeeeeeeeee",
"applicationName": "My Great Application",
"data": {
"lastConnectTime": Fri Feb 19 2016 17:26:00 GMT-0500 (EST),
"reason": "<Human-readable explanation of disconnection cause>"
},
"device": {
"applicationId": "555555555555eeeeeeeeeeee",
"attributes": {
"exampleNumber": {
"attributeTags": {
"attrTagKey": "tagValue1"
},
"dataType": "number",
"name": "exampleNumber"
},
"exampleString": {
"attributeTags": {
"attrTagKey": "tagValue2"
},
"dataType": "string",
"name": "exampleString"
}
},
"creationDate": "2018-03-16T18:19:03.376Z",
"deviceClass": "edgeCompute",
"deviceId": "222222222222bbbbbbbbbbbb",
"id": "222222222222bbbbbbbbbbbb",
"name": "My Great Device",
"tags": {
"aTagKey": [
"exampleTagValue"
],
"tagWithMultipleValues": [
"tagValue",
"anotherTagValue"
]
}
},
"deviceId": "222222222222bbbbbbbbbbbb",
"deviceName": "My Great Device",
"deviceTags": {
"aTagKey": [
"exampleTagValue"
],
"tagWithMultipleValues": [
"tagValue",
"anotherTagValue"
]
},
"flowId": "333333333333cccccccccccc",
"flowName": "My Great Workflow",
"flowVersion": "myFlowVersion",
"globals": {
"aJsonGlobal": {
"key": "value"
},
"aNumberGlobal": 42,
"aStringGlobal": "My value"
},
"isConnectedToLosant": true,
"time": Fri Feb 19 2016 17:26:00 GMT-0500 (EST),
"triggerId": "<trigger key>",
"triggerType": "onDisconnect"
}
Related Nodes
Was this page helpful?
Still looking for help? You can also search the Losant Forums or submit your question there.