Skip to main content
All CollectionsUser Guides
Events: Set variable action
Events: Set variable action

The "Set variable" action allows you to automatically log values into other variables based on Events' logic.

Sergio M avatar
Written by Sergio M
Updated over a week ago

Thanks to the "Set variable" action, Ubidots enables the automated interaction between variables based on the logic configured in Events to guarantee rapid and precise responses. With it, a variable that reaches certain threshold can trigger values, context or both being logged into another variable.

In this article you’ll learn how to trigger a Set variable action using Ubidots' Events Engine.


1. Create a new Event

To begin, head to the “data” tab →"Events" and hover over the “+” button, located at the upper right corner of the screen, and create a conditional event, global event, or scheduled event depending on your needs.

Next, configure the event’s logic using triggers with an AND/OR logic. For additional details on how to configure these triggers, head to their corresponding guides: value based, inactivity, geofence.

2. Configure the set variable action

With the "trigger" logic configured, it’s now time to set up the set variable action.

1. Click on the “+ add action” button to start the process. From the available options, choose “set variable”.

2. Define whether the target variables of this event will be manually selected (by choosing “selected variables”) or will be a common variable across a device group (by choosing “device group”).

  • If “selected variables” was chosen, click on the “variable label(s)” field and, in the modal that appears, select the target variables by first clicking on the device that contains them. You can select multiple variables here if they belong to the same device.

  • If “device group” was selected in the previous step, click on the field of “device group” and select the device group you want to target in the modal that opens up. Then click on the field of “variable label” and select the label of the variable you want to target.

3. Customize the “active trigger” and the “back to normal” (optional) messages. Here's an example of a valid message following Ubidots-compatible JSON format. Check out our API documentation to learn more.
{“value”:11.5, “timestamp“:1613665401000, ”context“:{”status“:”active“}}

Note: The “timestamp” and “context” keys are optional.

By using the tag icon at the upper right corners of the “subject” and “message” fields you can easily add information such as device ID, timestamp, variable name, etc.

Note: By default, data inputs involving timestamps are sent in human-readable format (YYY-MM-DD HH:mm:ss TZ). If you'd rather attach UNIX epoch time in milliseconds, double-click on the data input and delete the text from the pipe symbol ("|") until the end, as shown below.

4. Optionally, enable the “repeat action” option if you want to set the variable multiple times while the event is active. You can choose how often and up to how many times the action will be repeated. There’s a limit of 50 action repetitions.

5. Click on “save” once you finish configuring the action and then on “next”, unless you want to set up multiple actions.

6. After completing the action configuration you’ll proceed to the final step, the “settings” tab. There, you’ll name the event and give it a description (optional).

7. Another optional step is to use a tag on the event. This is a great tool to control what your end users see in your app. In this case, for instance, you could decide that your end user sees one event, but not another, using tags. Learn more about tags here.

Finally (unless the event you created is a scheduled event), determine the activity window in which the events should be executed. An event can have multiple active windows by clicking on the “+ add window button” and configuring them correspondingly. After finishing this, click on “save” and your event will be deployed.

Did this answer your question?