Event rule use case: display 'connected' devices (based on proximity) in the vehicle list
There might be a scenario where two devices may be close to each other for a long period of time, for example, a truck and a trailer both have their own tracking devices. And as a user, you may want to see which truck is connected to which trailer.
How to setup:
1. Rendezvous plugin
Login to Site Admin (Legacy)> Plugins > Get More Plugins, Download and install the Rendezvous plugin.
2. Custom variable
Add a custom variable with the name of your choice (see Custom-Variables for how to add a custom variable). In this example, the variable is named AttachedTo.
3. Custom variable in the vehicle list
Add the custom variable to the vehicle list, please go to Manage-columns-add-variables-in-the-vehicles-panel for more information on how to do that.
4. Event rule
-
Create a new event rule
- name it accordingly
- set which tags it shall be applied to
- set when the rule shall be active
- Under Expressions, add a Script Expression and add the following code:
var st = context.state || { rvz_status: false, rvz_timestamp: null, rvz_name: null};
var searchtag = 'Trailers'; //Change to the name of the tag containing the device(s) you want to look for
var searchtagobj = session.directory.getTag(searchtag);
var searchtagid = searchtagobj.id;
var r = rendezvous.findAny(searchtagid,'Enter',10); //Within 10 meters
if(r != null) {
st.rvz_name = r.name;
st.rvz_status = true;
st.rvz_timestamp = new Date();
context.setVariable("UnitName", r.name);
context.setState(st);
return true;
}
else {
var newdate = new Date();
var timestamp = new Date(st.rvz_timestamp);
var time_diff = newdate.getTime() - timestamp.getTime();
if(st.rvz_status == true && time_diff > 300000) { //In milliseconds
st.rvz_name = null;
st.rvz_status = false;
st.rvz_timestamp = null;
context.setVariable("UnitName", "");
}
else {
context.setVariable("UnitName", st.rvs_name);
}
context.setState(st);
return false;
} - Under Notifications, configure as seen in the screenshot
- Save
5. Result
Now when a device is close to another device and the criteria in the script match, you will have a result like this: