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

msolomos2 hours 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 Tananaev2 hours ago

What are the corresponding total distance?

msolomos2 hours 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 Tananaev2 hours ago

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

msolomos2 hours 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 Tananaev2 hours ago

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

msolomosan hour 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 Tananaevan hour ago

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

msolomosan hour 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...