Synthetic Variables' editor
Last updated
Last updated
Ubidots Synthetic Variables' editor allows you to write and configure the synthetic expression that will be computed.
In the bottom right corner of the editor, you'll see a message that indicates whether the expression is valid and can be computed or if there is an issue with the syntax that has to be corrected.
The editor allows selecting a timezone to reference the exact variable's timestamps based on a particular place. This comes in handy when a variable has to be calculated for a client, user, or process that has a different timezone than the one of your location.
Synthetic Variables allow context data handling, meaning you can take the context of the raw variable and use it in the synthetic expression (only if the context value is a number). Accessing it from the editor is straightforward: you just need to use the dot .
operator over the variable, add context and then the context key identifier:
Similarly to accessing context data, timestamps can be accessed in synthetic variables using the dot .
operator.
It's possible to use device properties in a synthetic variable's expression as long as the property has a floating number format. To access it from the synthetic editor, it's necessary to use any of the following syntax to retrieve the device object:
Then, in order to access this device's properties, you need to use the dot operator .
, like this:
Here, you need to replace <device>
with the id
or label
of the device that you wish to calculate the synthetic variable for.
Now you can retrieve any of the device's properties using the property's key, like this:
Where <key>
is the property's key.
For example, suppose that you need to retrieve the property uptime
from a device whose ID is 65fb47fad809281764f8a350
. The following syntax accomplishes that:
Note that in order to use the properties of the device in a synthetic variable, it's necessary to have a mathematical expression with another variable, which will determine the calculation of new data within the synthetic variable.
It is also possible to create a synthetic variable across device types from within the synthetic variables editor at device types module using any of the following syntax:
Here, you should only replace the property's key for the intended value. The keyword self
is a placeholder that gets replaced by the actual device ID for all the devices contained in this device type.