Editing Asset tags and attributes
Asset tags provide a quick way to determine an asset's state like speeding, idling, PTO, or some other value that's important to you. Attributes provide a way to track metrics like fuel consumption, freezer temperature, and other non-boolean states.
When developing custom behaviour scripts, it's very possible (if you're at all like me) to incorrectly modify your asset's states. As with all complex systems, sometimes it's easier to fix it yourself.
Modifying the asset's status tags
Adding and removing status tags is a simple exercise. When invoking the mergeAsset method, simply provide a tags key with an array of strings representing the tags you want the asset to have. The whole tags array is replaced on the asset, so all adds and removes are done in one operation. You can provide any string value for each tags, however, they will all be converted to the codified format, and blank strings will be removed.
This command:
mergeAsset {
"id": 429304,
"v": [12, 62874],
"tags": ["on-duty", "Speeding!", "---", "speeding"]
}
Will be resolved with the following tags values:
assetAdvancedMerged {
/* other values */
"tags": ["on-duty", "speeding"]
}
Adding, removing, and updating attributes
Editing asset attributes is more tricky. The mergeAsset method supports patch semantics (similar to the HTTP PATCH verb) for the attributes key, where only those values specified will be changed.
Asset attributes require several values to be processed by the API, and several more optional values are available as well.
- name string
The human readable name of this attribute. The name is converted to codified format, and the codified name is used as the attribute's key in the attributes object. This means that you can rename an attribute by submitting the new value with the old key. - simple string (optional)
A human read-able string to represent the raw value. For example, the raw value may be 5348.192273218585, so the simple value should be 5348.2. If not provided a blank string is used. - unit string (optional)
A description of the simple value like Km, mpg, or °C. If not provided a blank string is used. - complex string (optional)
The complex value can contain HTML or other code to help display this information for a human. An example would be an HTML bar graph to show the relative level of fuel in the tank. If not provided a blank string is used. - raw string
The raw value is used by scripts as the computer friendly value of the attribute. The given value is converted by the system into either a null, a boolean, a string, or a double-precision floating point number. The raw value cannot be set to an object, or any other value type. - dts string (optional) datetime format
The date and time that this attribute changed. If not provided, current time is used. - provider string (optional)
Identifier of the device that set this value. If not provided a blank string is used. - global boolean (optional)
When set to true, the Fleet Freedom UI will display the attribute. Default is false, the attribute is hidden.
To add or update an attribute:
mergeAsset {
"id": 429304,
"v": [12, 62874],
"attributes": {
"fuel-level": {
"name": "Fuel Level",
"simple": "87.1",
"unit": "L",
"raw": 87.129374,
"dts": "2017-02-08T03:55:28Z",
"global": true
}
}
}
To rename an attribute:
mergeAsset {
"id": 429304,
"v": [12, 62874],
"attributes": {
"old-name": {
"name": "New Name"
/* other values */
}
}
}
To remove an attribute:
mergeAsset {
"id": 429304,
"v": [12, 62874],
"attributes": {
"attr-name": null
}
}
The Fleet Freedom UI only displays values whose global is true. It tries to display the complex value first, and if no value is specified, it uses the simple (with unit). If no simple value is specified it will display the raw value.