How to Use JavaScript for Custom Rule Conditions in Qubitro
By following this guide, you can customize Qubitro rule functions using JavaScript to create dynamic conditions.
This guide explains how to use JavaScript within Qubitro’s rule functions to define custom conditions and automate actions based on real-time data.
A few notes to remember:
Rule Functions operate only on real-time data – They cannot query historical data from the database.
Each Rule Function executes a single pre-configured action – It does not support executing multiple actions within one function.
Actions are predefined during function setup – The trigger() function executes only the action assigned when creating the rule.
Although the examples here focus on environmental monitoring and geofencing, the same approach applies to any scenario requiring event-driven automation.
Accessing Data with Predefined Keys
Qubitro provides a simple way to access sensor values in JavaScript using predefined keys. These keys allow you to reference the latest device data without complex parsing.
Syntax and Usage
Define variables using predefined keys:
Each variable directly pulls the corresponding real-time value from the incoming data.
Writing Rule Conditions
With variables defined, you can create logical conditions to decide when the function should trigger an action.
Example: Trigger an Action Based on Temperature and Humidity
This function triggers an action if the temperature is above 25°C and humidity exceeds 70%.
Utilizing the trigger() Function
The trigger()
function is used to execute predefined action when conditions are met.
Example: Alert When Temperature and Humidity Are Too High
Practical Implementations
Example 1: Geofencing a Restricted Area
This example ensures that a device does not enter a restricted assembly area. If it does, the function triggers an alert.
Example 2: Advanced Environmental Monitoring
Last updated