Hi everyone,
I’m implementing fuel consumption calculations in Traccar using computed attributes. Currently, I’m using the formula:
9999999 - 100.00 * totalDistance / 100000
This works fine for the consumption calculation, but I’d like to make it more flexible. I understand that fuel consumption is an adjusted value and not something directly from the GPS. However, I have multiple vehicles with different fuel efficiencies (e.g., 15 km/l, 14 km/l, and 11.5 km/l).
I know that I would need to edit the code for this to work, but my question is more about how I can dynamically fetch the value from the device attributes (such as "fuel" or "consumption") in the computed attributes formula. For example, something like:
9999999 - device.attributes.fuel * totalDistance / 100000
Obviously, this syntax is incorrect, but I’m wondering if there’s a way to reference custom device attributes like this. Or is there another method to achieve variable fuel consumption calculations based on a device-specific attribute?
Any guidance, examples, or alternative ideas would be greatly appreciated.
Thanks in advance!
You can enable processing.computedAttributes.deviceAttributes
in the config and then use device attributes. Make sure there's no names overlap though.
Thank you, that was exactly what I required.
Hi everyone,
I’m implementing fuel consumption calculations in Traccar using computed attributes. Currently, I’m using the formula:
This works fine for the consumption calculation, but I’d like to make it more flexible. I understand that fuel consumption is an adjusted value and not something directly from the GPS. However, I have multiple vehicles with different fuel efficiencies (e.g., 15 km/l, 14 km/l, and 11.5 km/l).
I know that I would need to edit the code for this to work, but my question is more about how I can dynamically fetch the value from the device attributes (such as "fuel" or "consumption") in the computed attributes formula. For example, something like:
Obviously, this syntax is incorrect, but I’m wondering if there’s a way to reference custom device attributes like this. Or is there another method to achieve variable fuel consumption calculations based on a device-specific attribute?
Any guidance, examples, or alternative ideas would be greatly appreciated.
Thanks in advance!