April 18, 2024

How to Use Custom JavaScript Logic in Qubitro Rule Functions

This tutorial will guide you through the steps to integrate custom JavaScript logic into Qubitro's rule functions, enabling advanced data processing and automated responses based on incoming device data.


In Qubitro, Rule Functions automate actions based on the data transmitted by IoT devices. By utilizing predefined keys for instant data access and the internal trigger() function, you can efficiently manage and respond to real-time data conditions.

Accessing Data with Predefined Keys

To simplify the creation of conditions within rules, Qubitro allows the direct access of data fields using the ${{key}} syntax. This method streamlines the process of fetching data for condition checks.

Syntax and Usage

Here’s an example of how to set up variables using predefined keys:

Each variable directly accesses the corresponding value from the sensor data, facilitated by its predefined key.

Writing Conditions

With variables prepared, you can define conditions to trigger actions. These conditions can range from basic comparisons to complex logical statements.

Example Condition: Temperature and Humidity Check

This example demonstrates how to trigger an action if the temperature exceeds 25 degrees Celsius and humidity is above 70%:

Utilizing the trigger() Function

The trigger() function executes predefined actions when the conditions set in the rules are met.

How to Use trigger()

  • Purpose: To execute actions based on rule conditions.
  • Example Usage: Triggering an alert under specific environmental conditions.

Practical Implementation: Environmental Monitoring

Applying the principles learned to a practical scenario in environmental monitoring:

Example Usage: Restricted Zone Alert

Monitoring specific geographical areas is crucial in many applications, such as ensuring personnel remain within safe zones in a facility. The following example shows how to set up a rule that triggers an alert if a device enters a restricted assembly area.

Scenario: Monitoring an Assembly Area

Example Usage: Advanced Environmental Monitoring

Imagine managing an advanced environmental control system where temperature, humidity, light levels, and CO2 concentrations are monitored. Alerts need to be sent when any of these parameters deviate significantly from their target ranges.

Scenario Setup

This example demonstrates the use of multiple sensor variables to monitor and react to changes in environmental conditions. By setting up complex logical conditions that combine several parameters, the system can send targeted alerts to address specific scenarios.


By employing predefined keys and the trigger() function, Qubitro's rule functions provides powerful tools for managing real-time data efficiently. This capability enhances operational efficiency and ensures rapid responses to environmental changes.

For further information and advanced functionalities, refer to the Qubitro Documentation.

Couldn't find the guide you need?
    Qubitro Logo




    Decision Aids



    © 2024 Qubitro, Inc. All rights reserved