I am trying to use system.tag.queryTagHistory() to get a tag value 5 minutes ago, and the value now, so that I can calculate rate of change.
I feel like I have tried everything under the sun and cant get those values no matter how hard I try
This is what I currently have, but who knows how close it is… system.tag.queryTagHistory(paths=[tagPath], rangeMinutes=-5, returnSize=2, aggregationMode='LastValue')
Or, even easier, if there is a way to just query the rate of change of the last 5 minutes, I tried using Variance for that but it just returns the current value
Thanks for any help, I always seem to have issues with the right parameters for tagHistory…
For range values I use MinMax for aggregation. the return will be 2 rows (if a change in value) and subtract row1 - row0. If the return rowcount is < 2 then handle no data accordingly.
Is it any different if you use system.tag.queryTagCalculations() instead? I’ve never had any luck getting the calculations to do what I want using queryTagHistory but queryTagCalculations normally works for me. Try:
data = system.tag.queryTagCalculations(paths=path,calculations=['MinMax'],rangeMinutes=5)
print data.getColumnAsList(0)
print data.getColumnAsList(1)
data = system.dataset.toPyDataSet(data)
for x in data:
print x[1]
I’d be willing to bet thats it. I just tried it again using a tag that is on change and got back:
[MyTagName]
[50]
50
But just tried it out on another tag that is on a 10 second rate but hasn’t been running and got the same results. If the value doesn’t change MinMax only returns 1 value.