Fuel Theft Alarm

GpsGate Server can help you to detect possible fuel theft, loss or leakage by using a script in your Event Rules. You can set up alerts when a significant loss of fuel is detected in your vehicles.


    1. A GPS device capable of fuel level reading (check here for compatible devices by searching by the keyword fuel).
    2. Latest Plugins installed in the server
    3. Privilege _EditScriptExpression enabled in Privileges and Features of the application you want to implement this feature.
    4. The Fuel device signal (input) mapped to the variable Fuel level in the Device Mapper

How it works

The script saves 8 consecutive fuel level measures and calculates the mean for the first 4 values and also the mean of the last 4 values.

If the difference is larger than the threshold specified, it would indicate abnormal fuel consumption.

By default the script has a threshold of 3 (the difference between both means in liters). This value can be modified according to the fuel level signal inputs you receive from your device (liters/gallons). If you receive the fuel level input in voltage check this guide to convert that to liters.

  • Note: These calculations rely on the values sent from the device. This method cannot assure 100% that you are actually getting fuel theft. There could be another cause for the alarm being triggered: fuel leakage, bad readings from the fuel sensor, wrong threshold value, etc. The most accurate the values you receive, the more efficient the script will be.


Create your Event Rule

In your application go to Admin > Event Rules and create a new rule.

Select your settings and in 4. Expressions select Script Expression

Then click on Edit

Paste the following script in the editor:

  • Note: when using copy-paste from this blog to the script editor, make sure the characters <i> get replaced by [i]
var threshold = 3;
var fuel = fields.get("Fuel level",0);
     if(!context.state || context.state == ''){ //first time
         var fuelarray = [fuel]; //add fuel values
     else{ //not first time
       var updatedArray = context.state;
       if (context.state.length > 7){//calculate mean
         var mean1 = 0, mean2 = 0;
         for (var i = 0; i < 4; i++){
           mean1 += context.state<i>;
         mean1 = mean1 / 4;
         for (var i = 4; i < 8; i++){
           mean2 += context.state<i>;
         mean2 = mean2 / 4;
         if(mean1 - mean2 > threshold){
           if(fuel != 0){
           return true;
         if(fuel != 0){
       else{//add values
         if(fuel != 0){
           updatedArray[context.state.length] = fuel;
   return false;

The result should be like in the image. Notice that in the right of the screen you can add variables to test the script in case you want to introduce modifications.

In the step 5. Notifications you can add, for example, an Icon to see on screen when the script returns “True”.


To test the script, you can either test directly on the Event Rule script as shown in the image above or you can use SimOne.

When submitting Fuel Level values to your application, if the fuel consumption surpasses the threshold, you should get an alert as shown in the picture:

You can combine this Script Event with any other Expression in your rule, for example if Ignition signal is Off.

As a notification method, you might use SMS. With SMS, you'll know immediately when the event occurs.

  • Note: you can add the Map Link variable to your SMS notification to know exactly where the event happened and visualize it in the map with your default map application.