Computed Attributes

The Computed Attributes feature allows you to dynamically modify the attributes reported by devices and can assist in solving a number of problems:

Computed attributes are applied to all incoming positions of appropriate device.

Permissions

Computed attributes permissions model is the same as for Geofences.

If computed attribute linked to a device, it means that Traccar will apply this attribute to positions from that device.

If computed attribute linked to a group, it means that Traccar will apply this attribute to all members of that group and subgroups.

If user has access to a computed attribute, it means that the User can edit/remove that attribute and link/unlink it to/from devices/groups that he has access to.

Model

Computed attributes have following fields:

Type

There are three types: Number, Boolean and String. They help control the computing result and format values on the front-end.

Attribute

There is list of "standard" attributes with predefined types, but it is also possible to use your own.

Expression

Expression is the heart of computed attributes functionality. It uses very flexible JEXL Syntax to compute result.

All position fields are mapped as primitive objects (latitude, longitude, speed, course etc), they are always defined.

All position attributes also mapped as primitive objects (satellites, battery, ignition, distance etc). The set of defined attributes different for every device, and it might be different from one reported position to another.

Empty result of computation (null, but not the empty string) will not be stored to position.

Testing

Expression can be tested on the last position of some device.

Recommendations

Using undefined variables will create warning messages in the log. If you are not certain that the device always reports an attribute, then it is recommended to wrap it in a ternary operator to check if the value is present. A ternary operator is a conditional check with examples for this shown below.

The order in which computed attributes are applied to the device is not defined. It is therefore not recommended to use the result of one computed attribute in another computed attribute.

Examples

You have a device connected to a vehicles electrical system and report its voltage in the "power" attribute, but do not have separate ignition status input. You can try to use the following computed attribute to assign a value to the ignition attribute:

Ignition
power ? power > 13.2 : null
Boolean

You have a device with some configurable inputs and you connected ignition wire to second one.

It is reported as boolean attribute "in2"

Ignition
in2 ? true : false
Boolean

or as 0/1

Ignition
in2 ? in2 == 1 : false
Boolean

or as a second bit in flags attribute

Ignition
flags ? (flags & 2) != 0 : false
Boolean

You have a device with some configurable analog inputs and connected fuel sensor to first one. Let's say analog input has 10 bit resolution (0..1024) and maximum value 20 volt. Fuel sensor report rest of fuel as voltage from 0 to 12 volts, where 0 V is empty and 12 V is full 40 liters tank.

Fuel
adc1 ? adc1 * 0.065 : null
Number

Here is a non standard case. There is a device that do not have any inputs to determine ignition. It has internal battery, and its charger connected to ACC wire inside car. Was noticed that then device is charging it reports 4.18 V battery voltage, if not charging then voltage usually less than 4.18 V. Sometimes it is fluctuating and speed might be used for additional correction.

Ignition
battery < 4.18 && speed < 1 ? false : true
Boolean

Different devices with wondex protocol have different meaning of event attribute, some of them can be interpreted as alarms. Here is a couple of examples for Wonde Proud M7: