Retrieve time stamp last time a tag (integer) equaled a value

V8.1-Perspective

What is the easiest way to display the time and date, the last time a tag (integer) equaled a certain value?

I’ve watched EDU videos and I’m still stumped.

How and where have you stored the tag data?

What are EDU videos?

I have stored the values in my storage provider, a MSSQL DB.

Sorry, the university videos or videos from the manual.

How ... have you stored the tag data?

Are you using the Ignition Historian, transaction groups or tag events?

Historian

OK. Let's see your tag's history configuration.

Column 1 Column 2 Column 3 Column 4
History Enabled true
Storage Provider IGNITION_HIST
Deadband Style Auto
Deadband Mode Absolute
Historical Deadband 0.01
Sample Mode OnChange
Min Time Between Samples 10
Min Time Units SEC
Max Time Between Samples 1
Max Time Units HOUR

A few notes:

  1. You should probably change the Deadband Style to Discrete.
  2. If the tag value is an Integer then it can not have a change of 0.01 so esentially you have this set for no deadband. Not necessarily an issue, but just wanted to note.
  3. Min Time Between Samples causes records not to be recorded for at least 10 seconds, so any changes that occur will be lost. If what you are trying to achieve is to insure you have a record every 10 seconds, then that would be the Max Time Between Samples setting.

The easiest method would be to set up a Tag History Binding with the Aggregation Mode set to Last Value.

Playing around with AI, so haven’t vetted it:

tagPath = "[default]Area1/Motor1/Speed"
start = system.date.addHours(system.date.now(), -1)
end = system.date.now()

data = system.tag.queryTagHistory(
    paths=[tagPath],
    startDate=start,
    endDate=end,
    returnSize=-1
)

# Filter occurrences where value == desired value
valueToFind = 1200
matches = [row for row in data if row['value'] == valueToFind]

This aggregate mode simply says, if there are multiple values within the sample period, take the last / most recent value.

For something like this, you probably don't want to aggregate or sample it at all, you want the raw data points (that is, what @robertm has already with returnSize=-1)