Skip to main content
PI System
Asset Framework
PI Vision
ProcessBook
Analysis

Calculating Time Differences Between Tag Events in PI System – Binary & Numeric Tags with Visual Alerts

Learn how to compare the timing of state changes in binary tags to value changes in a related numeric tag within the OSIsoft PI System, and configure visual warnings if differences exceed a threshold. Solutions are covered for both client-side (ProcessBook/PI Vision) and server-side (AF Analysis) approaches.

Roshan Soni

6 min read

Calculating Time Differences Between Tag Events in OSIsoft PI: Analyzing Binary and Numeric Tag Changes with Visual Warnings

OSIsoft PI System offers powerful capabilities for monitoring process data in real time, but users often need to compare the timing of events across multiple tags. A common requirement—such as the one posed by a recent user—is to calculate the time difference between state changes in two binary tags (e.g., values changing between "Yes" and "No") and a value change in a related numeric tag, and then generate a warning if the difference exceeds a defined threshold. In this post, I'll discuss multiple approaches to achieve this in both client and server contexts, offering practical tips and considerations for visualization and alerting.

Problem Overview

Given:

  • Two binary tags (Tag1, Tag2) with values "Yes" or "No".
  • One numeric tag (Tag3).

Goal: Detect when either Tag1 or Tag2 changes state (from "Yes" to "No" or vice versa), compare the timestamp of this transition with the next value change in Tag3, and flag a warning if the time difference exceeds a set threshold (e.g., 5 minutes).

Desired Visualization: A visual warning, such as a flashing or color-changing symbol (multi-state symbol), in PI ProcessBook or PI Vision.


Client-Side Approach: ProcessBook / PI Vision

If you're primarily interested in visual analysis and warning for displayed data ranges (e.g., when viewing trends or process graphics), a client-side solution can be suitable. Here's a high-level workflow:

  1. Trend Identification:

    • Plot Tag1, Tag2, and Tag3 on the same time axis in ProcessBook or PI Vision.
    • Visually identify timestamps where the binary tags change state (these often appear as vertical lines on binary tag trends).
    • Note the corresponding value change in Tag3.
  2. Manual Analysis or Ad-hoc VB Scripting (ProcessBook Only):

    • Use ProcessBook's built-in Visual Basic (VB) scripting to scan event lists for each tag, detecting state changes.
    • Compare the timestamps, calculate the time differences, and set the state/color of a multi-state symbol if the threshold is exceeded.
  3. Multi-State Symbol for Warning:

    • Create a multi-state symbol whose state reflects the time difference (e.g., normal color if within threshold, flashing or red if exceeded).
    • Tie the symbol's state to a calculated value (could be an interval, or a flag determined by the VB script).

Limitations:

  • Only works within the loaded/displayed time window.
  • Only active for the current user/session.

Server-Side Approach: Asset Framework (AF) Analysis

Implementing this logic on the server side—via PI Asset Framework with Analysis—makes it scalable and always-on. Steps:

  1. Define Attribute References:

    • Create an AF Element with attributes pointing to Tag1, Tag2, and Tag3.
  2. Use AF Analytics for Event Detection:

    • Define an analysis to detect transitions in the binary tags, leveraging the PrevVal() or Delta() functions to find state changes.
    • Use the Event trigger to initiate the analysis on a tag change.
  3. Calculate Time Difference:

    • When a transition is detected, query the timestamp of the last value change in Tag3.
    • Calculate the time difference (using the DateTime functions/attributes in AF).
  4. Generate Alarm Flag Attribute:

    • Output a Boolean or status attribute indicating if a warning threshold is exceeded.
    • This attribute can be referenced in PI Vision for a multi-state symbol display, enabling dynamic visualization for all users.

Benefits:

  • Centralized, always running; applies to all data and users.
  • Can be extended to take further actions (notifications, emails, etc.).

Example: Implementing in AF Analysis

Suppose we have:

  • Binary attribute: StatusA (e.g., Yes/No), StatusB
  • Numeric attribute: ProcessValue

AF Analysis pseudocode:

If (StatusA <> PrevVal('StatusA', '*-1min') or StatusB <> PrevVal('StatusB', '*-1min')) then
    EventTime = now()
    PVChangeTime = Timestamp('ProcessValue')
    DeltaTime = EventTime - PVChangeTime
    Warning = DeltaTime > Threshold
End If

Output Warning as an AF attribute, and connect it to a PI Vision multi-state symbol.


Key Considerations

  • Performance: If you have frequent value changes, be careful with the analysis setup to avoid excessive processing.
  • Edge Cases: Decide how to handle simultaneous or rapid-fire events.
  • Visualization: Multi-state symbol in PI Vision is the modern approach; ProcessBook is legacy but still supports scripting for advanced behavior.

Conclusion

Comparing event timing across tags is a frequent need in PI. Whether you use client-side tools like ProcessBook for on-demand visualization or leverage the power of Asset Framework Analyses for continuous, system-wide monitoring, the PI System provides flexible tools for warning and alerting on timed event mismatches. For most new deployments, PI AF and PI Vision offer the most scalable, maintainable, and user-friendly solution for such requirements.


References:


Need help implementing this or optimizing your PI Analyses? Leave a comment or reach out to a PI System specialist.

Tags

#PI Vision
#PI AF
#Analysis
#ProcessBook
#Tag Event
#Multi-state Symbol
#Event Comparison
#Time Difference

About Roshan Soni

Expert in PI System implementation, industrial automation, and data management. Passionate about helping organizations maximize the value of their process data through innovative solutions and best practices.

Sign in to comment

Join the conversation by signing in to your account.

Comments (0)

No comments yet

Be the first to share your thoughts on this article.

Related Articles

Enhancing PI ProcessBook Trends with Banding and Zones: User Needs, Workarounds, and the Road Ahead

A look at the user demand for trend banding/zoning in OSIsoft PI ProcessBook, current VBA workarounds, UI challenges, and how future PI Vision releases aim to address these visualization needs.

Roshan Soni

Migrating PIAdvCalcFilVal Uptime Calculations from PI DataLink to PI OLEDB

Learn how to translate PI DataLink's PIAdvCalcFilVal advanced calculations—like counting uptime based on conditions—into efficient PI OLEDB SQL queries. Explore three practical approaches using PIAVG, PIINTERP, and PICOunt tables, and get tips for validation and accuracy.

Roshan Soni

Understanding PI Web API WebID Encoding: Can You Generate WebIDs Client-Side?

Curious about how PI Web API generates WebIDs and whether you can encode them client-side using GUIDs or paths? This article explores the encoding mechanisms, current documentation, and best practices for handling WebIDs in your applications.

Roshan Soni