Hi,
We’re trying to create a tag, which is just some historical average over some time period. For example, SiteTotal
is the current instantaneous value (with appropriate tag history enabled), but SiteTotal_1havg
is just the last 1-hour average.
We’re able to write a python script to return the correct value, which basically looks like:
def queryTagHistoryAverageLast1Hourx():
dataSet = system.tag.queryTagHistory(
paths=['[default]test/SiteTotal'],
startDate=system.date.addHours(system.date.now(), -1),
endDate=ystem.date.now(),
returnSize=1,
aggregationMode='Average',
returnFormat='Wide')
return dataSet.getData()[1][0]
This script appears to work fine in the designer script console:
TagHistory.queryTagHistoryAverageLast1Hourx()
>>>
1534.1507555167063
But using this same function in an expression tag like follows, just gives “Error_ExpressionEval”:
runScript('TagHistory.queryTagHistoryAverageLast1Hourx', 0)
The full json export is:
{
"valueSource": "expr",
"expression": "runScript(\u0027TagHistory.queryTagHistoryAverageLast1Hourx\u0027, 0)",
"dataType": "Int4",
"name": "SiteTotal_1havg",
"executionMode": "FixedRate",
"executionRate": 1000,
"tagType": "AtomicTag"
}
I can’t see why this wouldn’t work, I can add some debug to my python script to return the tag result and that works fine. Eg:
def queryTagHistoryAverageLast1Hourx():
return system.tag.readBlocking(['[default]test/SiteTotal'])[0].getValue()
I’m unsure what other configuration may be necessary to fix this (Gateway Settings → Gateway Scripting Project is configured to the current and only project). Version 8.1.5.
How can I get an expression tag to run my script which uses the queryTagHistory?
Thanks