Tag Query help system.tag.queryTagHistory

Hi all,

Hoping to get some assistance using the system.tag.queryTagHistory function.

I'm trying to query various tags to get a single 24hr minimum value, I have tried using the expression below but can't seem to get a valid expression.

endTime = system.date.now()
startTime = system.date.addMinutes(endTime, -1440)
dataSet = system.tag.queryTagHistory(paths=['my tag provider here'], startDate=startTime, endDate=endTime, returnSize=1, aggregationMode="Minimum", returnFormat='Wide')

I have attempted to put then under a binding expression as well as creating a new query tag with the text into the query, neither have yielded a value.

I plan to add these data points into an existing table that has lots of other data points.

Any tips please? Thanks in advance,
Sam.

paths=['my tag provider here']

Are you actually giving a list of tag paths and not just the provider name?
Are you sure you are logging at least once a day. (What are the tag settings for Max Time Between Samples?

Please see Wiki - how to post code on this forum.

Yeah so here is the actual data I'm putting in; [TagAUBH]GF/AUBH/BRB/BAK00/Supervisor/Data/V3ToV1Voltage

It is logging at a rate of 1 second & I can trend the data.

When I do a simple tag history query it works fine, trouble is that returns the value in a dataset that I can't seem to link to a single data point for my table so I think my solution is to get a query working that will return a single value.

This isn't an expression, it's a script. If you are trying to use this as an expression it will not work.

If you're not, be careful with terminology, as the Expression language is not the same a scripting and this can lead to confusion.

endTime = system.date.now()
startTime = system.date.addMinutes(endTime, -1440)
dataSet = system.tag.queryTagHistory(paths=['my tag provider here'], startDate=startTime, endDate=endTime, returnSize=1, aggregationMode="Minimum", returnFormat='Wide')

system.tag.queryTagHistory() returns a dataset, so to get the value out of the dataset you need to use functions on the dataset to retrieve them. If you are expecting only 1 value to be returned, then that code would look something like this:

dataset.getValueAt(0,1)

Or

dataset.getValueAt(0,'[TagAUBH]GF/AUBH/BRB/BAK00/Supervisor/Data/V3ToV1Voltage')

You may also want to set noInterpolation = True to insure that you are not returning a purely interpolated value.

3 Likes

Thanks for the information, it is appreciated.

I think my main issue now is that even when using the tag history binding table it returns as a dataset so if I'm looking for a 24hr minimum I will get a 1x2 dataset (Tstamp & value). What's the easiest way to pick the second column (value) data and move into a integer so it can be linked into my standard table?
If there was a way to do that under the transform function of the tag history binding section that would be really handy.


Add Transform | Expression.
{value}[0, 1]

1 Like

Brilliant thanks all & apologies for the basic questions!