Oh ok then, there are a couple of things you should do.
In this case I do recommend creating a global project. No for inherence, instead for Gateway Scripting Project. Configure the name of the project in Gateway Setting in Config web page like:
After that, in global project, create a project script and give it a name and create a function. That function should receive a parameter that is the tagPath from which tag you wish to calculate the Average. Also this function should return either true of false, useful for the alarm: This may give an idea.
def calcAvg(tagPath):
now = system.date.now()
currentValue = system.tag.read(tagPath).value
historyDataset = system.tag.queryTagHistory(paths=[tagPath], startDate= system.date.addMinutes(now,-5) , endDate=now, returnSize=1, aggregationMode="Average", returnFormat='Wide')
if historyDataset.rowCount == 1:
avg = historyDataset.getValueAt(0,1)
if avg == None:
avg = currentValue
else:
avg = currentValue
if avg == currentValue:
return True
else:
return False
Please improve this script using readBlocking and queryTagCalculation functions. You may also need to change the script to fit your needs.
Then create a boolean tag in your UDT definition of expression source.
The expression should look like:
runScript('alarmAverage.calcAvg',300000,'[default]value')
Where the first parameter is the reference to the script path, the seconds parameter is the refresh rate in millis (5minutes in this example) and at the end the tagPath to calculate the historical Average.
If you’re clever, you should be able to pass a tagPath in the 3rd parameter based on a UDT definition: (maybe using tag() expression or by creating another tag that holds the path reference)
Finally, since this will be a bool tag that will be true of false based on the script, create an alarm on it in equal mode to 1, details for this are trivial.