DataTriggerInfo

The DataTriggerInfo object is intended for obtaining the state of the data trigger (its data source).

Fields

Examples

The following example demonstrates access to data triggers. In this example, the expression has two data triggers with the names hypotenuse and cathetus and the corresponding data sources. Changing any of these triggers initiates the execution of the expression's code and updates its value.

// For brevity, we will save the length of the cathetus in an intermediate variable
var b = context.data['cathetus'].state.value;

// For brevity, we will save the length of the hypotenuse in an intermediate variable
var c = context.data['hypotenuse'].state.value;

return Math.sqrt(c*c - b*b);

The example below shows an expression that returns True if the data trigger value has not changed within 5 minutes, otherwise it returns False. In this example, the expression has a data trigger named slow and a periodic trigger (with the period of 1000 ms) that initiates the code execution.

// Interval
const INTERVAL = 5 * 60 * 1000;

var now = Date.now();
j
// Saving the time of the last update
var last = context.data['slow'].state.time;
 
// Difference in milliseconds
var millis = now - last;

if (millis > INTERVAL)
  return true;
else return false;

Last updated