Skip to main content

Managing Transient Triggers

To install a Transient Trigger, one should issue a watch event in the Channel, given he is authorized to do so. The payload of such an event is identical to a Trigger definition, hence it looks like this:

{
"name": "datatrigger",
"device_id": "f0VMRgIBAQAAAAAAAAAAAA",
"simple_trigger": {
"type": "data_trigger",
"on": "incoming_data",
"interface_name": "org.astarte-platform.genericsensors.Values",
"interface_major": 0,
"match_path": "/streamTest/value",
"value_match_operator": ">",
"known_value": 0.6
}
}

This installs in the Room a Transient Trigger which will trigger an event everytime a value higher than 0.6 is sent on the path /streamTest/value of the datastream interface org.astarte-platform.genericsensors.Values by the device f0VMRgIBAQAAAAAAAAAAAA, and will be received by every user currently in the room. If a user isn't in the room at the time of the event, he will not get it, and there's no way he can retrieve it if he joined at a later time.

Triggers can be uninstalled by issuing an unwatch event in the Channel. The payload of the event should be the name of the trigger which should be uninstalled.

Group Triggers​

Transient triggers can also target an Data Orchestrator group instead of a single device. To install a group volatile trigger, pass the group_name key in the JSON payload instead of the device_id key.

For example, the trigger below is equivalent to the one in the previous section, but it targets all devices that are in the group mygroup.

{
"name": "groupdevicetrigger",
"group_name": "mygroup",
"simple_trigger": {
"type": "data_trigger",
"on": "incoming_data",
"interface_name": "org.astarte-platform.genericsensors.Values",
"interface_major": 0,
"match_path": "/streamTest/value",
"value_match_operator": ">",
"known_value": 0.6
}
}

Note that the devices belonging to the group are evaluated when the trigger is installed, i.e. if a device is added to the group when the trigger is already installed, the trigger will not target the newly added device. The same goes for devices removed from the group, that will still be targeted by the trigger until it is removed.