Creating a new sensor template
Who can do it: Service provider
Where: Wialon Platform Studio
Sensor templates are reusable detailed configuration of telemetry parameters and formatting rules. They let you save and reuse different configurations, for example, for various device models.
You can create a new template only within a predefined sensor type.
You can’t add more than 100 sensor templates
To create a new template:
- In the Sensor template dropdown menu, select Create new in the bottom of the list.
- Enter a descriptive name for your template (for example,
Engine temp while driving). - In the Measurement unit field, set the unit of measurement (for example,
°C). - In the Formula field, define the formula to calculate the sensor’s value from the raw data. For example, use the parameter
can.engine.coolant.temperatureto see how much heat the engine is producing. - In the Validation section, add a validation condition to ensure the accuracy of the data:
- In the Type field, select a condition, for example, Parameter is not null to ensure the parameter has some value.
- In the Parameter name field, indicate the system name of the parameter. For example,
position.speed. You can click Add validation to add more conditions.
- Click Save to save your new sensor template.
The created template allows displaying the engine temperature when the vehicle is moving with the graph. The template is now stored in these settings and can be applied to other devices.
Filling in the “Formula” field
To calculate a sensor value from incoming raw data parameters, you must create an expression in the Formula field.
The formula field uses a syntax similar to programming expressions, incorporating data parameters, mathematical operators, and built-in functions, including logical operators and conditional functions.
You can create your expression using the methods described below.
- Referencing parameters: Always use the
$prefix when referencing parameter values ,for example,$position.speed, to prevent errors if the parameter is not present in a message. When specifying the parameter name as a string (for example, inexists()), do not use$or#. - Access previous values: Use
previous("parameter.name")for stateful calculations.previous(X)will return the current value of parameterXfrom device telemetry, ornullif the message being registered has a timestamp older than whenXwas last set in telemetry. - Use functions:
round(), Returns the nearest whole number (integer) toX. Standard rounding rules apply (for example,$.5$is rounded up).abs(), Returns the absolute value ofX.if(CONDITION, WHEN-TRUE, WHEN-FALSE): Evaluates condition. If true, returns when-true; otherwise, returns when-false.exists('FIELD-NAME'): Returns true if the specified field exists in the message, false otherwise.hex(), Converts the numeric argumentXinto its hexadecimal string representation.not(X): Inverts the boolean value ofX. If X is zero or false, it returns non-zero/true, and vice versa.isnumber(X): Returns true ifXis a number, false otherwise.isstring(X): Returns true ifXis a string, false otherwise.isboolean(X): Returns true ifXis a boolean, false otherwise.isnull(X): Returns true ifXis null, false otherwise.isjson(X): Returns true ifXis a JSON object or array, false otherwise.
- Use logical and mathematical operators: +, -, *, /, >, <, ==, !=, &&, ||. See the list of operators with descriptions in the Logical expression format section.
Example expression for the Acceleration sensor calculating linear acceleration. We count acceleration in m/s2 if time between messages is more than 0 and less than 15.
if( (timestamp - previous('timestamp')) > 0 && (timestamp - previous('timestamp')) <= 15, (position.speed - previous('position.speed')) / (3.6*(timestamp - previous('timestamp'))), 0 )