Creating Triggers

Types of Triggers

You can create the following types of triggers for a calculation:
  • Polled or scheduled: Used to trigger a calculation based on a scheduled time interval. For example, you can calculate the average value of tag data collected every hour.

    The polled type trigger functions the same as the other collectors. Although Historian internally optimizes calculation execution times, the data for polled tags is timestamped on the data collection interval. For example, if the calculation engine is unable to process the polled triggers as scheduled, the calculations will be executed later, but with data interpolated back to the scheduled time. If there are too many triggers to be processed, some triggers will be dropped and no samples are logged for that calculation time.

    For information on creating a polled trigger, refer to Create a Polled Trigger.

  • Unsolicited or event-based: Used to trigger a calculation based on an event. For example, you can calculate the average value of tag data when the data exceeds a certain value.

    When you set an event-based trigger, you must also set up a dependency list of one or more tags. Event-based triggers will keep calculations as up to date as possible. They are also useful when you want to do on-demand calculations. You can use a trigger tag that is written to by an external program or operation.

    If you want to perform raw sample replication you would use an event-based trigger. To retrieve data from a tag, use the formula:
    Result=CurrentValue("Tag1")+CurrentValue("Tag2")

    If you are using recovery mode, all referenced tags in an unsolicited calculation must be listed as trigger tags because recovery will be performed only for the configured trigger tags.

    Event-based triggers have a dependency list of trigger tags. The trigger fires whenever there is a data change for the trigger tag (for example, changes in the quality and value of a trigger tag). The value of a trigger tag can change when the tag exceeds the collector compression (if you enabled collector compression).

    The calculation is processed each time any tag in the dependency list changes. If you have multiple tags in the list and they change even one millisecond apart, then you will have multiple events, and the calculation formula will be processed for each.

    However, the following actions do not trigger a calculation:
    • Deletion of a tag that is in the dependency list.
    • Re-addition of a tag in the dependency list.

    The calculation is triggered at the same time as the timestamp of the sample in the trigger tag. The values of all other tags in the formula are interpolated forward to this time so that the timestamps of all input tags are the same. Even if these are sequential events, they have the same timestamp. The calculation time becomes the timestamp for the sample stored in the destination tag.

    Event-based triggers have a collection interval. The Calculation collector notifies the archiver not to send notification of changes to trigger tags any faster than the collection interval setting.

    For information on creating an unsolicited trigger, refer to Create an Unsolicited Trigger.

Create a Polled Trigger

Procedure

  1. Access Historian Administrator.
  2. Select Tags.
  3. In the Tags section, select the tag to which you want to apply the trigger.
  4. In the Collection section, select Polled from the Collection Type.
  5. Set the Collection Interval and Collection Offset values. For example, if you want to set a trigger every day, set these values to 24 hours and 8 hours, respectively. Depending on the trigger that you want to set, enter the appropriate VBScript code in the Calculation pane. For examples, refer to Examples of Scheduling Polled Triggers.
  6. Select Update.

Examples of Scheduling Polled Triggers

You can schedule calculations using polled triggers, as shown in the following examples.

Scheduling a Trigger every Monday

Since Monday is the second day of a week, enter the following VBScript code in the Calculation pane:
Dim curDate curDate=CurrentTime
IF (Weekday(curDate))=2 THEN
Result=50 <Place your calculation here>
END IF

Notice that the CurrentTime built-in function is used in this example instead of Now.

Scheduling a Trigger on the First Day of Every Month

Enter the following VBScript code in the Calculation pane:
Dim curDate curDate=CurrentTime
IF (day(curDate))=1 THEN
Result=50 <Place your calculation here>
END IF

Notice that the CurrentTime built-in function is used in this example instead of Now.

Scheduling a Trigger on the Last Day of Every Month

Enter the following VBScript code in the Calculation pane:
Dim curDate curDate=CurrentTime
IF (day(curDate))=1 THEN
Result=50 <Place your calculation here>
END IF

Notice that the CurrentTime built-in function is used in this example instead of Now.

Example 5: Creating a Controlled Sequence of Polled Tags Using a Collection Offset

A controlled sequence is a calculation that is based on the result of another calculation. The following is an example of how to configure a controlled sequence of polled tags by using the collection offset. The collection offset is greater than 0 in this example.

A tag named SumOfData has a Collection Interval of 60 seconds and the Collection Offset of 0 milliseconds.

SumofData performs the first calculation:
Result = CurrentValue("DataTag1") + CurrentValue("DataTag2")

Another tag, named CorrectedUnits, uses a Collection Interval of 60 seconds, but a Collection Offset of 1000 milliseconds.

CorrectedUnits fires and performs another calculation based on the output of the first calculation:
Result = CurrentValue("SumOfData") *.0001

Create an Unsolicited Trigger

About this task

This topic describes how to create an unsolicited trigger for a calculation, and how to set up a dependency list:

Before you begin

If you want to browse for tags while adding a trigger tag, ensure that the Calculation collector is running.

Procedure

  1. Access Historian Administrator.
  2. Select Tags, and then select the tag to which you want to apply the trigger.
  3. In the Collection section, select Unsolicited from the Collection Type, and specify an interval.
  4. Select Calculation.
  5. Select Add to add a trigger.
    The Insert Function window appears.
  6. In the Trigger Tag field, enter the name of the trigger tag that you want to use in the calculation.
    The wizard automatically populates the Trigger Tag field and updates the Function Preview field, as shown in the following figure:

  7. Select Insert.
    The trigger is added to the Calculation Triggers section.

    In addition, the trigger list appears when using the Insert Function window to build a calculation formula for an event based tag.

  8. Select Update.

Examples of Scheduling Unsolicited Triggers

Example1: Using One Trigger Tag in a Formula

The following is an example of an event-based calculation with one trigger tag:

Result=CurrentValue("Tag2") + CurrentValue("Tag3")

You can configure Tag1, which is not in the formula, to be the calculation trigger for this example. Tag2 and Tag3 are not trigger tags. Trigger tags do not have to reside in the formula. There is no relation between formula tags and trigger tags. However, if you are planning to use recovery mode, you want all formula tags to be triggers.

Example 2: Using Multiple Trigger Tags in a Formula

The following is an example of an event-based calculation with multiple trigger tags:

Result=CurrentValue("Tag1") + CurrentValue("Tag2")

Configure Tag1 and Tag2 to be the calculation triggers for this example.

Example 3: Creating a Controlled Sequence of Unsolicited Tags Using Trigger Tags

A controlled sequence is a calculation that is based on the result of another calculation. The following is an example of how to create a controlled sequence of unsolicited tags using trigger tags. In this example, you create a calculation tag that is based on the result of another calculation tag.

For CalcTag1, the calculation is as follows:

Result = CurrentValue("TagA") + CurrentValue("TagB")

TagA and TagB are the calculation triggers for CalcTag1:

For CalcTag2, the calculation is as follows:

Result = CurrentValue("CalcTag1") * CurrentValue("TagC")

CalcTag1 is the calculation trigger for CalcTag2.