Skip to main content
PI System
Automation
AFSDK
PI Notifications

Automating PI Notification Time Rule Changes in Bulk with AFSDK

Learn how to automate the process of changing PI Notification time rules in bulk using AFSDK and C#. Useful for resolving the 'EN_AnalysisNotConfigured' error after server restarts.

Roshan Soni

4 min read

Automating PI Notification Time Rule Changes in Bulk with AFSDK

Managing notifications at scale in PI System environments can occasionally present unique challenges, especially after unexpected server restarts. One such challenge involves the infamous "EN_AnalysisNotConfigured" error that might prevent notifications from starting.

When handling hundreds or even thousands of PI Notifications, manual intervention is not only impractical, but also prone to error. Fortunately, the PI AFSDK allows engineers to efficiently automate administrative tasks—including changing notification time rules across many notifications in bulk.

The Issue: Bulk Notifications Stuck in Error

After a PI Notification Server restart, you may encounter notifications refusing to start, showing the error:

Error: Could not start the notification: ANException: EN_AnalysisNotConfigured

A proven workaround is to toggle the notification's time rule from "Natural" to "Periodic" (e.g., every 5 minutes), start and then stop the notification, and switch back to "Natural". Doing this manually for dozens or hundreds of notifications would take excessive time and effort.

The Solution: Automate with AFSDK and C#

By leveraging the AFSDK, you can programmatically:

  • Identify affected notifications
  • Change their time rules
  • Programmatically start/stop notifications to reset their state
  • Switch back to the desired time rule

Here’s some sample code that illustrates the process:

using OSIsoft.AF;
using OSIsoft.AF.Asset;
using OSIsoft.AF.Notification;
using OSIsoft.AF.Analysis;

// Connect to PI AF Server
PISystem piSystem = new PISystems()["YourPISystem"];
AFDatabase afDB = piSystem.Databases["YourAFDatabase"];

// Reference time rule plugins
AFTimerRulePlugin periodic = piSystem.TimeRulePlugIns["Periodic"];
AFTimerRulePlugin natural = piSystem.TimeRulePlugIns["Natural"];

// Query all notifications (adjust the search as needed)
var notificationList = afDB.Notifications;
foreach (AFNotification notf in notificationList)
{
    // Check for error status (customize your filter if needed)
    if (notf.Status == AFStatus.Error)
    {
        // Switch to Periodic
        notf.Analysis.TimeRulePlugIn = periodic;
        notf.Analysis.TimeRule.ConfigString = "Frequency=300"; // 300 seconds = 5 mins
        notf.CheckIn();

        // Start/Stop notification
        var anNotification = notf.Analysis.AnalysisNotification;
        anNotification.StartNotification();
        anNotification.StopNotification();

        // Switch back to Natural
        notf.Analysis.TimeRulePlugIn = natural;
        notf.CheckIn();
    }
}

Note: Be sure to test this code on a small set of notifications first, and always backup your configuration before performing bulk operations.

Why Does This Work?

Toggling the time rule resets the notification's scheduling metadata, which can help clear configuration issues that arose from a system restart or internal error. By leveraging AFSDK’s programmatic interfaces, you can swiftly recover from issues affecting notifications at scale.

More Resources


Applying automation to manage PI notifications is a best practice for reliability and efficiency, especially in large environments. By scripting these changes with AFSDK and C#, you save time and maintain operational continuity, with the added flexibility to build in additional logic or logging as your system evolves.

Tags

#PI Notifications
#Programming
#Best Practices
#C#
#PI AFSDK
#Time Rule
#Notification Automation
#EN_AnalysisNotConfigured

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