# Rule Function

## Functions

Functions in Qubitro allow you to **process, modify, and automate** actions based on incoming device data. There are multiple function types, each serving a specific purpose.

<figure><img src="https://3109056034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfQfo4zX1x0hfOimS9E2u%2Fuploads%2FsTYbeoVOOZKUGbIjjYwf%2FCleanShot%202025-03-04%20at%2014.21.34%402x.png?alt=media&#x26;token=00400562-0b58-468a-93ba-bd98d3441232" alt=""><figcaption></figcaption></figure>

### How It Works <a href="#how-it-works" id="how-it-works"></a>

When data is received from a device, Qubitro processes it through a Rule Function in the following steps:

{% stepper %}
{% step %}
**Check Debounce Period**

Prevents excessive triggering by ensuring the rule is not executed too frequently.
{% endstep %}

{% step %}
**Evaluate Condition**

Determines whether the incoming data meets the defined criteria.
{% endstep %}

{% step %}
**Trigger Action**

If the condition is met, the configured action is executed immediately.
{% endstep %}
{% endstepper %}

{% @mermaid/diagram content="graph LR;
A\[Data Received by Qubitro] --> B{Within Debounce Period?};

B -- Yes --> C\[Ignore Action Within Chosen Time Frame];
B -- No --> D{Check Condition};

D -- No --> E\[Ignore Data];
D -- Yes --> F\[Trigger Action];

F --> G\[Send Email / Slack Notification / Other Actions];

%% Style Adjustments
style A fill:#d9d9d9,stroke:#000,color:#000;
style B fill:#f2f2f2,stroke:#000,color:#000;
style C fill:#f2f2f2,stroke:#000,color:#000;
style D fill:#f2f2f2,stroke:#000,color:#000;
style E fill:#CBC3E3,stroke:#000,color:#000;  %% Purple from your previous diagrams
style F fill:#CBC3E3,stroke:#000,color:#000;  %% Purple from your previous diagrams
style G fill:#e0e0e0,stroke:#000,color:#000;" %}

{% hint style="warning" %}
Rule Functions operate **only on** real-time data – They **cannot** query historical data from the database.
{% endhint %}

{% hint style="info" %}
Each Rule Function executes a single pre-configured action – It **does not support** executing multiple actions within one function.
{% endhint %}

### Creating a Rule Function

{% stepper %}
{% step %}

#### Step 1: Navigate to the Device Page

Go to the **Devices** page, select the device you want to create a function for, and navigate to its **detail page**.
{% endstep %}

{% step %}

#### Step 2: Open the Functions Tab

Click on the **Functions** tab, then click on **Create function**.
{% endstep %}

{% step %}

#### Step 3: Choose a Function Type

Click the **Get started** button and follow the required steps to configure the function.

{% hint style="info" %}
For detailed guidance on each function type, visit its dedicated documentation page.
{% endhint %}
{% endstep %}

{% step %}

#### Step 4: Configure and Save

Each function type has **unique configuration options**. Follow the specific instructions for the selected function type.
{% endstep %}
{% endstepper %}

### Condition Configuration

Rule Functions in Qubitro allow you to define conditions that determine whether an action should be triggered based on incoming device data.&#x20;

There are two ways to configure conditions:

#### JavaScript Logic Builder

For users familiar with coding, the JavaScript Logic Builder allows custom condition creation using JavaScript syntax.

<mark style="background-color:yellow;">For a deeper dive, read our guide:</mark>

{% content-ref url="<https://app.gitbook.com/s/llOFTfRA5L4YRnakI84m/functions-and-data-processing/how-to-use-javascript-for-custom-rule-conditions-in-qubitro>" %}
[How to Use JavaScript for Custom Rule Conditions in Qubitro](https://app.gitbook.com/s/llOFTfRA5L4YRnakI84m/functions-and-data-processing/how-to-use-javascript-for-custom-rule-conditions-in-qubitro)
{% endcontent-ref %}

<figure><img src="https://3109056034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfQfo4zX1x0hfOimS9E2u%2Fuploads%2FT5hXTVceHdl7S3Xe0IgI%2FCleanShot%202025-03-04%20at%2014.28.07%402x.png?alt=media&#x26;token=a1272a2b-9a4c-4093-8873-8d3b00b928f2" alt=""><figcaption></figcaption></figure>

#### Visual Condition Builder

The Visual Condition Builder is a no-code option that allows users to define conditions using dropdown menus.

<figure><img src="https://3109056034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfQfo4zX1x0hfOimS9E2u%2Fuploads%2FSWQJJjfW422fljUaI1uD%2FCleanShot%202025-03-04%20at%2014.26.46%402x.png?alt=media&#x26;token=9845e2f5-b8fb-4900-a51e-1dcb04530673" alt=""><figcaption></figcaption></figure>
