//created on: Jun 4, 2014 package com.sample.rules //list any import classes here. import com.sample.facts.SensorReading; import java.util.ArrayList; //declare any global variables here global java.lang.StringBuilder alertMessage // add declaration to change the Fact into an Event declare SensorReading @role(event) end /* Alert when average temperature is above 25 over a time period of 5 minutes */ rule "TemperatureAlarm1" when //conditions $averageTemp : Number(intValue > 25) from accumulate(SensorReading($temp : temperature) over window:time(5m) from entry-point "Temperature Reading", average($temp)) then //actions System.out.println("Fired rule: " + kcontext.getRule().getName() + "!!"); alertMessage.append("Threshold temperature breached!!"+ "\nTurn on the Air Conditioner"+ "\nAverage temperature over 5 minutes is above 25 (" + $averageTemp.intValue() + ")\n"); end