Create fatigue alerts with scripting

We show you how scripting is used to measure that drivers follow regulations about driving hours and rest periods.

This article is another example of how to create advanced solutions using script expressions. For more information about script expressions, see this article.

We will create a fatigue event rule that will check that your drivers are not driving for too long periods, and that they are resting sufficiently. We use the European Union rules for this example, but it is easy to modify the script for your country’s rules.


The fatigue script is available as an exported event rule. Follow these steps to install it:

  1. Log in to SiteAdmin.
  2. Go to the Plugins tab.
  3. Under My Plugins tab, make sure all plugins are up to date
  4. Download this XML file. Import in VehicleTracker. See this article for help.


These are the regulations that the script is monitoring:

  1. Daily driving period shall not exceed 9 hours, with an exemption of twice per week when it can be extended to 10 hours.
  2. Total weekly driving time may not exceed 56 hours and the total fortnightly driving time may not exceed 90 hours.
  3. Daily rest period shall be at least 11 hours, with an exception of going down to 9 hours maximum three times a week. Daily rest can be split into 3 hours rest followed by 9 hour rest to make a total of 12 hours daily rest.

The script

Download the script here. Unpack the ZIP file and import the included XML file in VehicleTracker to automatically create an event rule with the fatigue script.

The first line of the script contains the “driving” definition. You need to change this to suit your needs. It should be an expression that is true when the vehicle/driver is considered to be driving. The opposite (when it is false) means that the driver is resting. In this example “driving” is when the “Engine on” signal is true.

var driving = fields.get('Engine on', false) == true;

The bottom part (the part below the “——Do not edit below this line——” comment) should remain untouched unless you really know what you are doing. Changes to the bottom part of the script are not supported.
You can however change more settings by using custom fields. See the Customization section of this blog for more information.


The script includes custom fields that you can change to modify the rules to your own needs.
See this article for information how you setup custom fields.                                                                                                                                                                                                                                                                                                   

Variable Description
minContinuousRest The least amount of rest needed before actually counting it as resting. The value should be in number of minutes. Default: 180 (3 hours)        
minDailyRest The minimum rest per day (per 24 hours). The value should be in number of minutes. Default: 660 (11 hours)        
minDailyRestExemption Exemption to the minDailyRest rule, that can be violated maxRestExemptions times. The value should be in number of minutes. Default: 540 (9 hours)        
maxRestExemptions Number of times minDailyRest can be violated. This is reset every Monday. Default: 3        
maxDailyDriving The maximum driving time per day (per 24 hours). The value should be in number of minutes. Default: 540 (9 hours)        
maxDailyDrivingExemption Exemption to the maxDailyDriving rule, that can be violated maxDrivingExemptionstimes. The value should be in number of minutes. Default: 600 (10 hours)        
maxDrivingExemptions Number of times maxDailyDriving can be violated. This is reset every drivingExemptionResetTime. Default: 2        
drivingExemptionResetTime See maxDrivingExemptions. The value should be in number of minutes. Default: 10080 (every week)        
maxWeeklyDriving The maximum driving time per week. The value should be in number of minutes. Default: 3360 (56 hours)        
maxFortnightlyDriving The maximum driving time fortnightly. The value should be in number of minutes. Default: 5400 (90 hours)        


When a driver break any of the rules mentioned above (see Features), an event will be triggered. How you use these events is up to you. Maybe you just want a notification in the GUI, or maybe something more powerful like a report.
The script produces a few variables that you can use in your notifiers and reports.
More general help about notifiers can be found here. Specific information about event rule reports can be found here.                                                                                                                                                                                                                                   

Variable Description
Reason Contains the rule that was broken. (minDailyRest, drivingExemptions, maxDailyDriving, maxWeeklyDriving, maxFortnightlyDriving)
DailyRest The amount of rest today (in minutes).
RestExemptionsLeft Number of exemptions left regarding the resting rules.
DailyDriving The amount of driving today (in minutes).
WeeklyDriving The amount of driving this week (in minutes).
FortnightlyDriving The amount of fortnightly driving (in minutes);
DrivingExemptionsLeft Number of exemptions left regarding the driving rules.