How can I include total distance, today's distance, today's engine hours, and trip distance in Traccar short message template?

Hamzaa year ago

Greetings Traccar community,

I am currently customizing the short message template in Traccar, and I would like to extend its functionality to include additional information. I have a template that displays basic details such as device name, event, speed, time, location, and status. However, I am seeking guidance on incorporating the following information into the template:

  • Total distance traveled
  • Today's distance
  • Today's engine hours
  • Trip distance

Here is the current template I am working with:

#set($subject = "$device.name: ignition ON")
#if($speedUnit == 'kmh')
#set($speedValue = $position.speed * 1.852)
#set($speedString = $numberTool.format("0.0 km/h", $speedValue))
#elseif($speedUnit == 'mph')
#set($speedValue = $position.speed * 1.15078)
#set($speedString = $numberTool.format("0.0 mph", $speedValue))
#else
#set($speedString = $numberTool.format("0.0 kn", $position.speed))
#end



Device: $device.name

Event: ignition ON

Speed: $speedString

Time: $dateTool.format("hh:mm a EEE d MMM yyyy", $event.eventTime, $locale, $timezone)

Address: $position.address

Status..!
GPS: 1
ACC: $position.attributes.ignition
Motion: $position.attributes.motion

BY [COMPANY NAME]

I kindly request assistance on how to modify this template to include the mentioned details. Your guidance will be greatly appreciated.

Thank you for your time and support!

Best regards,
Hamza

Nikolay a year ago

Hm, interesting.

Where did you get speedUnit from?

if speedUnit exist why do you convert speed? Its should be already converted.

And next question is, what is expected speed value when Ignition On event occurred?

Anton Tananaeva year ago

You can only include the data that's present in the event or position.

Hamzaa year ago

okay

Hamzaa year ago

Hello Traccar community,

Here is the current template I am using:

#set($subject = "$device.name: ignition ON")
#if($speedUnit == 'kmh')
#set($speedValue = $position.speed * 1.852)
#set($speedString = $numberTool.format("0.0 km/h", $speedValue))
#elseif($speedUnit == 'mph')
#set($speedValue = $position.speed * 1.15078)
#set($speedString = $numberTool.format("0.0 mph", $speedValue))
#else
#set($speedString = $numberTool.format("0.0 kn", $position.speed))
#end

Device: $device.name

Event: ignition ON

Speed: $speedString

Time: $dateTool.format("hh:mm a EEE d MMM yyyy", $event.eventTime, $locale, $timezone)

Address: $position.address

Google Map Url: https://www.google.com/maps/search/?api=1&query=$position.latitude,$position.longitude

Status..!
Motion: $position.attributes.motion
Odometer = $position.attributes.totalDistance

BY [COMPANY NAME]

In this template, the $position.attributes.totalDistance variable provides the odometer value, but it includes decimal points. I would like to display the odometer value in km.
I understand that the short message template only includes the data that is present in the event or position. However, is there any workaround or alternative approach to achieve this formatting requirement?

If anyone has any suggestions or insights on how to display the odometer value without decimal points in the Traccar short message template, I would greatly appreciate your guidance.

I tried using the following modification, but it didn't work:

#set($odometerValue = $position.attributes.totalDistance)
#set($roundedOdometer = $math.round($odometerValue))
Odometer: $numberTool.format("#,##0.00 km", $roundedOdometer)
#set($odometerValue = $position.attributes.totalDistance / 1000)
#set($odometerString = $numberTool.format("#,##0.00 km", $odometerValue))
Odometer: $odometerString