Skip to content

Action Triggers

An Action Trigger will monitor a data source and evaluate device and service data to see if a predefined condition is true and if so, invoke the associated action.

Three varieties of action triggers are supported:

  • Direct
  • Streamed
  • Polled

Direct triggers respond to user actions or HTTP requests to the device cloud endpoints.

Streamed triggers monitor data as it is received by the device cloud from devices.

Polled triggers run at a per-trigger frequency. This can be set to any number of minutes, hours, or days. While event triggers are run whenever the designated event is received by the Ioto device cloud.

Source Type Description
Database Value Polled Read a device database item value.
Database Sync Event Monitor synchronized device data that matches trigger expressions in the device schema.
HTTP Event Respond to an incoming HTTP request.
Metric Polled Monitor device and service metrics.
User Event Respond to a user action from a device manager interface.

Matching Triggers

When a trigger event is received or polled, the associated trigger data is evaluated and compared with a trigger expression. If the expression evaluates to true, the trigger action is automatically invoked. For example, if you were polling a temperature field for a device, you could define a trigger expression to activate when the temperature exceeds 100 degrees.

When a trigger is activatated, it will pass parameters to the action to customize its behavior based on the specific trigger conditions.

Trigger Expressions

The trigger expression is a JavaScript like expression that is evaluated to yield a true or false result. If true, the Trigger action is invoked.

The trigger expression is provided with a context of variables that can be accessed by the expression. The fields for a database item are provided as named variables. For metric data sources, the metric result is provided as a "value" variable. For example:

1
value > 0

The query language supports the operators:

1
+ - * / ( ) ^ ! % == != < <= > >= ^= ^!= $= $!= << >> && || <> ><

These extension operators have the following meaning:

  • a ^= b means a starts with the string b
  • a ^!= b means a does not start with the string b
  • a $= b means a ends with the string b
  • a $!= b means a does not end with the string b
  • a >< b means a contains the string b
  • a <> b means a does not contain the string b

Sub-expressions can be grouped with parenthesis and the boolean operators && and || can group conditional operands.

Regular expressions (delimited by slashes) may be used with the "==" and "!=" operators. The regular expression can be on either side of the operator.

The expression language understands the types: Numbers, Boolean, String literals, Regular Expressions and null.

The expression is run-time limited to evaluate up to 100 terms. This is to protect your cloud against denial of service attacks.

Database Value

Database values can be queried according to a polling schedule. To specify the database item to query, you must specify the:

  • Table name
  • Item keys
  • Item filter properties

The Builder and Device Cloud provides data modeling and storage of application data. Data items can be retrieved by specifying the appropriate item key. Other properties can be provided to further filter the data to be queried.

Polled Metric Value

Metric values can also be queried according to a polling schedule. To specify the metric item to query, you must specify the:

  • Metric namespace
  • Metric name
  • Metric dimensions
  • Metric statistic
  • Metric period

Metrics are grouped into namespaces and have a unique metric name. Metrics can also have dimensions where a set of resources may have unique metric values for each resource.

The metric statistics supported are: min, max, avg, sum, count and current. Sum is the sum of values over the request period. Count is the number of values sampled over the period. Current is the most recent updated value.

The metric period should be set to the last 5 minutes, hour, day, week, month or year.

The Builder console provides pulldown lists for each of these fields based on the available metrics on your system.

For more information on metrics, please see Metrics.

Streamed Device Data

As device data is sent to the device cloud, data can be used to activate an automation trigger.

UI Actions

The UI triggers listen the following endpoint for POST requests:

1
https://DEVICE_CLOUD/tok/trigger/invoke

The POST request accepts a JSON body with the following parameters:

  • name
  • ...parms

Where name is the name of the trigger to invoke. You can add any other parameters that will be made available to the Trigger expression as variables.

See Authentication for how to authenticate HTTP requests.

HTTP Requests

HTTP Post requests can utilize the same endpoint as for UI actions:

1
https://DEVICE_CLOUD/tok/trigger/invoke

The POST request has the same arguments as for UI actions above.