Event rule use case: display 'connected' assets (based on proximity) in the asset list
There might be a scenario where two assets may be close to each other for a long period of time, for example, a truck and a trailer both have their tracker. And as a user, you may want to see which truck is connected to which trailer.
How to set up:
1. Rendezvous plugin
Log in 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. Event rule
-
Create a new event rule
name it accordingly
set which Groups it shall be applied to
set when the rule shall be active
-
Under Expressions, add a Script Expression (make sure to have the privilege _EditScriptExpression activated, please follow this guide if it is not visible) 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 Group 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; }
3. Under Notifications, configure as seen in the screenshot. Please type [UnitName] in the 'Source' field.
4. Save
4. Custom variable in the asset list
Add the custom variable 'AttachedTo' to the asset list. Please go to Manage-columns-add-variables-in-the-assets-panel for more information on how to do that.
5. Result
Now, when an asset is close to another asset and the criteria in the script match, you will have a result like this:
Note: You can test this rule by creating simulators and naming them Trucks and Trailers, and including the Trucks/Trailers (that you want to see under the 'AttachedTo' column) in the Group. Please remember to change the name of the Group in the code (where you have the comment //Change to the name of the Group containing the device(s) you want to look for) to the Group you created.