Geofence and Command

  1. Geofence and Command

Use case 1

When the vehicle is outside the "Village" geofence, the color of the object icon changes depending on the speed: if the speed is 0 - yellow, if the speed is from 1 to 90 - green, if the speed is more than 90 - red. When vehicle enters the "Village" geofence, the icon color turns gray and a command "send location every 3 minutes" is sent to the device. When leaving the "Village" geofence, a command "send location once every 20 seconds" is sent to the device.


.module Declare
Integer cmdsent;
.module onMessage
if (isInZone(5097)) { // geofence "Village"
  if ((cmdsent==null) || (cmdsent==0)) {
    sendCommand( getGlobalStr("REPORT_IN") ,"rep 3 min");  setIconColor("CCCCCC");  cmdsent =1; }
} else { 
  if ((cmdsent==null) || (cmdsent==1)) {
    sendCommand( getGlobalStr("REPORT_OUT") ,"rep 3 min");  cmdsent =0;  }
  iconColorByVal(V, "< 1 FFFF00", "< 90 00FF00", ">= 90 FF0000");
}

Use case 2

When a vehicle enters the "Village" geofence, a http command is sent via the IFTTT service "turn on the lights" in the garage. After 10 minutes, a command "turn off the light" is sent. (Sonoff device is used to turn on/off lights).


.module Declare
Integer stayinzone;
Integer cmdsent;
.module onMessage
stayinzone = timeStayInZone(5097);  // geofence "Village"
if (stayinzone>0) {
  if ((cmdsent==null) || (cmdsent==0)) {
    sendCommand( getGlobalStr("LIGHT_ON") ,"light on");  cmdsent =1; 
  } else if ((cmdsent ==1) && (stayinzone>10)) {
    sendCommand(getGlobalStr("LIGHT_OFF") ,"light off");  cmdsent =2; 
  }
} else {  cmdsent = 0; }

It's good practice to define commands in global variables rather than in the script.

Back Directory

top