Specific alarms

Andreas Kern4 years ago

Hello community,

i use teltonika devices and connected BLE temperature sensors to it.
Values are transmitted right to server in parameters temp1 temp2 temp3 temp4

I created following computed attribute to get an alarm when max or min alarm borders are crossed.

temp1 or temp2 or temp3 or temp4 >= 7 ? "temperature" : (temp1 or temp2 or temp3 or temp4 <= 0 ? "temperature" : null)
The message text is:

CROSSED TEMPERATURE BORDER!!!

generated by code snipped:

($position.getString("alarm").equals("temperature"))CROSSED TEMPERATURE BORDER!!!

This also works fine and alarms are created. But this is very unspecific.
My goal is to create different alarms for every sensor.
Alarm when max or min value is crossed and alarms when min or max values are 2 degrees before min or max.

Is it possible without editing the source code or does it only work if new alarm types in backend are generated?

I also would be satisfied if i could display current sensor name and value of temperature in the alarm message.
For e.g.

TEMP1 = 9 °C CROSSED TEMPERATURE BORDER!!!

I experimented with some expressions in template file but did not get a satisfied result.

If there has anybody an idea i would be very thankful!

Best regards Andreas

Anton Tananaev4 years ago

You should have access to the position data, so you can extract values from there.

Andreas Kern4 years ago

I had a look in the data base and i found out how to get access to position data and also to device attributes data.

Instead adding alarm types in source code i tried to edit the alarm template but i get stuck in comparing two values.
The problem is, that

$position.attributes.temp1

is from type Number
and

$device.attributes.temp1Max

is from type String.

In the computed attribute it is no problem to compare the string to a value.
But in .vm file it does not work.
Here is a snipped of my alarm.vm

{elseif}($position.getString("alarm").equals("temperature") and ($position.attributes.temp1 >= $device.attributes.temp1Max))TEMPERATUR GRENZE VON $device.attributes.temp1Max°C ÜBERSCHRITTEN!!! Temperatur ist: $position.attributes.temp1 °C #

When i change $device.attributes.temp1Max for testing into 7

{elseif}($position.getString("alarm").equals("temperature") and ($position.attributes.temp1 >= 7))TEMPERATUR GRENZE VON $device.attributes.temp1Max°C ÜBERSCHRITTEN!!! Temperatur ist: $position.attributes.temp1 °C # the message is generated.

Snipped of generated message

TEMPERATUR GRENZE VON 7°C ÜBERSCHRITTEN!!! Temperatur ist: 21.000024 °C

Is there a way to turn $device.attributes.temp1Max string into a value?

Anton Tananaev4 years ago

Why can't you set it to be a number instead of a string?

Andreas Kern4 years ago

Hello Anton,

$device.attributes.temp1Max is a device attribute and there is no option to tell traccar to handle it like number as it is possible for computed attributes.

This is the editing formular for device attributes:

Description text

Anton Tananaev4 years ago

Then you should be able to parse it.

Andreas Kern4 years ago

I tried it ,

but did no find the right syntax yet. And did not find a solution by googling.
There for my programming knowledge is much to small!

Can you give me an advise or do i have to open a ticket for professional service?

Anton Tananaev4 years ago

I don't know the answer off the top of my head.

Andreas Kern4 years ago

Thank you nevertheless!

what also would work is, if it would be possible to define type of attribute by storing or editing with a drop downfield (number, string, bool) like it is possible to create computed attributes.

If you got a solution how to parse attribute in vm file i would be glad to tell me even when it costs me a donation.

Anton Tananaev4 years ago

There's always paid support option if you are interested.

Andreas Kern4 years ago

I think i have got it:

To parse a string attribute to integer i set a variable at top of code.
#set($Temp1Max = 0)
later in code i used followed expression
$Temp1Max.parseInt($device.attributes.temp1Max)

My short alarm.vm

looks like this now

#set($Temp1Max = 0)
ALARM von $device.name: #{if}($position.getString("alarm").equals("sos"))SOS#{elseif}($position.getString("alarm").equals("removing"))GERÄT WURDE ENTFERNT#{elseif}($position.getString("alarm").equals("lowBattery"))GERINGER BATTERIESTAND#{elseif}($position.getString("alarm").equals("tow"))ABSCHLEPPEN#{elseif}($position.getString("alarm").equals("jamming"))GSM STÖRSENDER ERKANNT#{elseif}($position.getString("alarm").equals("hardBraking"))GEFAHRENBREMSUNG ERKANNT#{elseif}($position.getString("alarm").equals("hardCornering"))STARKE KURVENFAHRT ERKANNT#{elseif}($position.getString("alarm").equals("hardAcceleration"))STARKES BESCHLEUNIGEN ERKANNT#{elseif}($position.getString("alarm").equals("idle"))LANGER LEERLAUF ERKANNT#{elseif}($position.getString("alarm").equals("accident"))UNFALL ERKANNT#{elseif}($position.getString("alarm").equals("temperature") and ($position.attributes.temp1 >= $Temp1Max.parseInt($device.attributes.temp1Max) )) TEMPERATUR GRENZE VON $device.attributes.temp1Max°C ÜBERSCHRITTEN!!! Temperatur ist: $position.attributes.temp1°C #{else}SONSTIGER ALARM#{end} 
Alarm wurde ausgelöst am: $dateTool.format("dd.MM.YYYY HH:mm:ss", $event.serverTime, $locale, $timezone)

Perhaps this helps someone else to modify his templates

Thank you for your inspiration, Anton!!!