Creating Triggers on Streams

Streams are the way that you gather data on states of your devices. Taking for example a leak detector, you might have a stream, “leakDetected” that reports a 0 when the probe is dry, and reports a 1 when the probe senses water. If streams are the way you gather telemetry from your devices, a trigger is your programmed response to those streams.

An easy way to think about triggers is to imagine a tea kettle over the stove, with a temperature sensor following its temperature as it rises. You might program the sensor’s stream to report the temperature every second, and deploy a trigger to turn off the heating plate when the stream reports a temperature above 100 degrees. The stream is the telemetric data gathered from your sensor, and the trigger is the threshold or value at which you tell your device to elicit some action.

From a device’s page, click on the “Triggers” tab and then the “Add New Trigger” button to prompt a pop-up. The first step is to decide whether your trigger will respond to an event (like a kettle reaching boil) –called a “data-driven” trigger– or to act repetitively based on time –a “scheduled” trigger. If you choose a scheduled trigger, you will see space to define the schedule for your trigger. Next, the “Reference to stream” drop-down menu will offer you a list of available streams that your trigger will respond to. You can then name your trigger and set parameters like minimum and maximum values and sensitivity. Finally, you can define the action to be taken, the result of the triggered event.

The actions available to you are formula, webrequest, email, alert, command, TurnOnForMaxTurnOffForMin, and TurnOffForMaxTurnOnForMin.

The formula option offers you the ability to take a followed value and do some calculations with it. The webrequest lets you fill in a url and define whether you will GET, POST, or PUT. The email and alert allow you to send a message to an email address or SMS number of your choosing. And the command option has a list of possible actions, such as restarting the device or triggering a device update. The remaining two options, TurnOnForMaxTurnOffForMin and TurnOffForMaxTurnOnForMin, allow you to turn the device on and off based on the threshold minimum and maximum values you previously set. These triggers will afford you reliable actions for any stream you want to follow on any device in your project.