Find if machine ran in last hour Tag Historian

Hello all,

I am trying to find if a machine ran in the last hour. So even if it is off now but it has ran in the last hour I am looking at getting Boolean true. I am looking at the historian of my Boolean status bit with the following piece of code but I am getting random values. Sometimes it returns 1 as it supposed sometimes it returns 0. I just want to now if in the last 60 minutes that tag was true. Could you please help? Thanks!

tagPath = "[history_provider]tag_path"
startDate =, -60)
endDate =
dataset = system.tag.queryTagHistory(paths=[tagPath], startDate = startDate, endDate = endDate, returnSize=1, aggregationMode="Maximum", returnFormat='Wide')	
data= dataset.getValueAt(0,1)

It look like you’re always processing row 0, while you should actually check if there’s a “True” value in that dataset.

You should also try to figure out what happens when the machine didn’t change state in that hour, and was always on or off. It’s likely you get a zero-size ds back.


I am just getting to now tag.queryTagHistory. I got what you mean now. I tought if I return 1 row it will just get me the maximum for the last hour which seems not to be the case. Thanks!