# MQTT Rules Engine

MQTT Rule is a Rule defined in Thingsup to Process MQTT Message. Before setting up MQTT Rule, user need [**Add Device**](/mqtt/add-mqtt-device.md) to his account. User need to provide following parameters.

#### Topic

User need to provide a topic on which data is incoming. For example, *Test.* Thingsup also support standard Wildcard subscriptions like Test/+ or Test/# or Test/+/LocationData

#### Data Validation/Transform

Here user can write a JavaScript code to validate or change data i.e "payload"  which is received as payload to given MQTT Topic.

The "payload" object here in this code, can get changed or transformed before passing to Thingsup Actions. Also user can assign "null" to payload if he want to avoid action trigger after data validation.

```
// This code checks if payload is JSON and contains Location data 
if(typeof payload === 'object') 
{
    if(payload.Location == undefined) 
    {
        payload = null;
    }
    else
    {
        payload["time"] = Date.now(); // Transform payload
    }
}
else
{
    payload = null;
}
```

#### Action ID

User need to provide an Action ID of Action to be triggered.

![Add MQTT Rule](/files/JUDNeZBQ1BcUiosq6TzA)

Please note the following points:

{% hint style="info" %}

* "null" payload results into Rule Failure which doesn't trigger Action
* Avoid using Rule Engine directly to trigger Send SMS /Email Action, bad configuration can result into High Credits Usage
  {% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.thingsup.io/rules/mqtt-rule.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
