How to get initial value from queryTagHistory

When using system.tag.queryTagHistory, I have NULL as value until there is a change for that tag.
How can I get the initial value of each tag at start time?

In the picture, before Mode changes to MODE_AUTOMATIC it was probably at MODE_MANUAL, but I cannot see it.

It should be as simple as ‘return the closest value recorded before start time’.
Or is there a function to get the a value at a specific time in history, instead of using a date range?

Did you try setting the includeBoundingValues flag to True?

Yes I did… I looked at the documentation and was expecting includeBoundingValuesto solve that issue.

There is Tag History Bindings in Perspective, it seems to work as expected if I ask for one data point per tag with a narrow date range. But I don’t know how to do the same in script.

What is a “narrow” date range for your application?

How was this binding configured and what did the script look like that you used to try and replicate it?

When testing if I can get the last value in history for a specific time, I used a Tag History Binding in Perspective with a time range of zero (same Start Date and End Date) and 1 as Point Count.

About the script calling system.tag.queryTagHistory with NULL value until there is a tag change; the default range is 1 hours customisable by the user.

system.tag.queryTagHistory(paths=PathList, startDate=StartTime, endDate=EndTime, returnSize = -1, returnFormat='Wide', includeBoundingValues= True, ignoreBadQuality=True, noInterpolation=True)