Computed attributes allow dynamic position attributes modification. Most common use cases for computed attributes:
Computed attributes are applied to all incoming positions of a linked device. 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.
Each computed attributes contains 4 fields:
You can pick from a list of standard attributes with predefined types, but it is also possible to define your own custom attribute.
Expression is the core of computed attributes feature. It uses a very flexible JEXL syntax to compute the result.
All position fields are mapped as primitive objects (latitude, longitude, speed, course etc), they are always defined. Position attributes also mapped as primitive objects (satellites, battery, ignition, distance etc). The set of attributes depends on what the device is reporting.
An empty result of computation (null, but not an empty string) will not be stored to position and will clear any existing attribute with the same name.
The expression can be tested on the last position of some device.
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.
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 des not have any inputs to determine ignition. It has an internal battery, and its charger connected to ACC wire inside car. It was noticed that when 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