GPS devices installed on vehicles that already had mileage, need to add offset

msolomos9 days ago

Hello,

I'm trying to set up computed attributes to add an odometer offset for vehicles where GPS was installed after purchase. Here's my setup:

Traccar Version: 5.12
Issue: GPS devices installed on vehicles that already had mileage, need to add offset

Current Setup:

  • Attribute: odometer
  • Expression: deviceId == 6 ? totalDistance + 43441000 : deviceId == 5 ? totalDistance + 78625000 : totalDistance
  • Type: number

Expected Results:

  • Device ID 6 (IPO7483): Should show ~84,810 km (41,369 + 43,441)
  • Device ID 5 (IPN8745): Should show ~115,257 km (36,632 + 78,625)

Actual Results:

  • Device ID 6: Shows 27,864 km
  • Device ID 5: Shows 22,640 km

The API returns the computed odometer values but they don't match my calculations. It seems like the expression isn't being applied correctly or there's something else
interfering.

Questions:

  1. Is my expression syntax correct?
  2. Do I need to restart Traccar server after creating computed attributes?
  3. Is there a better way to handle odometer offsets for devices installed on used vehicles?

Any help would be appreciated!

Thanks

Anton Tananaev9 days ago

What are the corresponding total distance?

msolomos9 days ago

The current totalDistance values from the API are:

  • Device ID 6 (IPO7483): 41372157.34740512 meters (≈ 41,372 km)
  • Device ID 5 (IPN8745): 36632043.55864166 meters (≈ 36,632 km)

My offset calculations:

  • IPO7483: Real odometer 84,810 km - GPS totalDistance 41,372 km = 43,438 km offset
  • IPN8745: Real odometer 115,257 km - GPS totalDistance 36,632 km = 78,625 km offset

So my corrected expression should be:
deviceId == 6 ? totalDistance + 43438000 : deviceId == 5 ? totalDistance + 78625000 : totalDistance

Is this the correct approach for adding odometer offsets?

Anton Tananaev9 days ago

I'm a bit confused. Isn't it the expected values?

msolomos9 days ago

Sorry for the confusion! You're absolutely right. Let me clarify with the current actual values:

Current API data:

  • Device ID 6 (IPO7483): totalDistance = 41,372,157m → Should show 84,810 km (41,372 + 43,438)
  • Device ID 5 (IPN8745): totalDistance = 36,632,043m → Should show 115,257 km (36,632 + 78,625)

But computed attribute returns:

  • Device ID 6: 27,863 km ❌
  • Device ID 5: 22,640 km ❌

The expected results (84,810 km and 115,257 km) are what the vehicles' real odometers should show after adding the GPS offset.

My expression:
deviceId == 6 ? totalDistance + 43438000 : deviceId == 5 ? totalDistance + 78625000 : totalDistance

The computed values don't match the expected totalDistance + offset calculation.

Anton Tananaev9 days ago

When you change the expression does the value change? Say if you just return a fixed value.

msolomos9 days ago

No, the values didn't change at all. I updated the computed attribute expression to:

deviceId == 6 ? 99999000 : deviceId == 5 ? 88888000 : totalDistance

Expected:

  • Device ID 6: 99,999,000
  • Device ID 5: 88,888,000

Actual results (unchanged):

  • Device ID 6: computedOdometer: 27871445
  • Device ID 5: computedOdometer: 22640086

The computed attribute doesn't seem to be active or working at all. The odometer values in the API response are the same as before the expression change.

Questions:

  1. Do I need to restart Traccar server after modifying computed attributes?
  2. Is there a way to verify that computed attributes are actually being applied?
  3. Could there be a permissions issue or configuration preventing computed attributes from working?
Anton Tananaev9 days ago

You're making some assumptions that your device id check works. I would recommend trying a hardcoded value without any logic.

msolomos9 days ago

You're absolutely right. Let me test with the simplest possible expression first.

I'll change the computed attribute to just:

99999000

This should return 99,999 km for ALL devices if computed attributes are working at all.

Testing now...

msolomos9 days ago

it seems that the following expression is giving me the desired odometer.

car1.PNG

however, with the following curl command I don't get same data.
it is the deviceID = 6

● Bash(curl -H "Authorization: Bearer
      XXXXXX"
      http://192.168.2.251:8082/api/positions)
  ⎿  [
       {
         "id": 1451188,
         "attributes": {
           "priority": 0,
           "sat": 11,
           "event": 239,
           "ignition": false,
           "motion": false,
           "rssi": 3,
           "io200": 0,
           "io69": 1,
           "pdop": 1.1,
           "hdop": 0.8,
           "power": 13.158,
           "battery": 4.117,
           "io68": 0,
           "operator": 20210,
           "odometer": 27896647,
           "distance": 0,
           "totalDistance": 41404594.97353495,
           "hours": 2778626670
         },
         "deviceId": 6,
         "protocol": "teltonika",
         "serverTime": "2025-11-20T12:36:27.865+00:00",
         "deviceTime": "2025-11-20T12:36:24.000+00:00",
         "fixTime": "2025-11-20T12:36:24.000+00:00",
         "outdated": false,
         "valid": true,
         "latitude": 38.1751416,
         "longitude": 20.4889666,
         "altitude": 37,
         "speed": 0,
         "course": 49,
         "address": null,
         "accuracy": 0,
         "network": null,
         "geofenceIds": null
       },
       {
         "id": 1451229,
         "attributes": {
           "priority": 0,
           "sat": 11,
           "event": 240,
           "ignition": true,
           "motion": false,
           "rssi": 2,
           "io200": 0,
           "io69": 1,
           "pdop": 1.2000000000000002,
           "hdop": 0.9,
           "power": 14.053,
           "battery": 4.0840000000000005,
           "io68": 0,
           "operator": 20210,
           "odometer": 22726950,
           "distance": 5.8711763834035064,
           "totalDistance": 36718352.60875312,
           "hours": 2922770550
         },
         "deviceId": 5,
         "protocol": "teltonika",
         "serverTime": "2025-11-20T13:06:40.276+00:00",
         "deviceTime": "2025-11-20T13:06:34.000+00:00",
         "fixTime": "2025-11-20T13:06:34.000+00:00",
         "outdated": false,
         "valid": true,
         "latitude": 38.1644333,
         "longitude": 20.495945,
         "altitude": -5,
         "speed": 0,
         "course": 41,
         "address": null,
         "accuracy": 0,
         "network": null,
         "geofenceIds": null
       }
     ]
       % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                      Dload  Upload   Total   Spent    Left  Speed
100  1326  100  1326    0     0  54505      0 --:--:-- --:--:-- --:--:-- 55250
Anton Tananaev9 days ago

I don't see a trip odometer in your attributes at all.

msolomos8 days ago

I think I’ve been approaching my question the wrong way for the last two days, so let me clarify it properly.

Is there any way to adjust or correct the stored Traccar data so that the system shows the actual odometer reading of the vehicle (as displayed on the car’s dashboard)?
In other words: can I safely align Traccar’s odometer value with the real car mileage?

Also, I would really appreciate a clarification on the difference between odometer and totalDistance in Traccar.
From my understanding:

totalDistance is the raw cumulative distance reported by the device (in meters), continuously increasing.

odometer is a calculated or adjusted value that can include offsets or custom logic.

Is this correct?

Thanks in advance, and sorry for the confusion — I’m just trying to make sure the mileage I see in Traccar matches the real car values.

Regards,
Gerasimos

Anton Tananaev8 days ago

totalDistance - calculated on the server based on locations
odometer - reported by your device

Walter Spada7 days ago

Send a command to the device with the correct odometer value. (unless it takes it from OBD2)
I have to do it sometimes because of the cumulative drift some devices have while under a roof makes a lot of distance.
Since they are diferent vehicles, you can change de device identifier from the "old" vehicle to... "something" and add a new device with the actual identifier for the new vehicle. This way you can keep history and have no confusion on usage.