Multiple events per event rule and device

With Script Expressions you can manually start/end an event using the following methods:

context.startEvent(namespace)
context.endEvent(namespace)
context.endAllEvents()

Example

In the following example we use context.setVariable(name, value [, namespace]) that sets an event expression variable. Use third namespace parameter in context.setVariable to map the variable value to the corresponding event.

You can see more examples using context.state here.

var speed = trackPoint.velocity.groundSpeed * 3.6;
if(speed > 20){
  context.startEvent('s1');
  context.setVariable('Severity', 'Fast', 's1');
}
else {
  context.endEvent('s1');
}

if(speed > 50){
  context.startEvent('s2');
  context.setVariable('Severity', 'Even Faster', 's2');
}
else {
  context.endEvent('s2');
}

if(speed > 100){
  context.startEvent('s3');
  context.setVariable('Severity', 'Supet Fast', 's3');
}
else {
  context.endEvent('s3');
}

return false;