Using Trigger Tags
Trigger Types
Assign a trigger, or collection type, to your calculation tag in the same manner as any other tag. The trigger can be scheduled (polled) or unsolicited (event-based). When you set an event-based trigger, you must also set up a dependency list of one or more tags.
- Polled type
- Use when you want to schedule the exact time or interval for a calculation to trigger.
Polled collection example:
If you want to collect summary (or rollup) information, such as an hourly average of data at a scheduled interval, you would use polled calculations.
- Unsolicited type
- Use when you want calculations to be performed on an event-basis. Event-based calculations 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.
Unsolicited collection example:
If you want to perform raw sample replication you would use the unsolicited collection type. To retrieve data from tag, instead of two, 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.
Polled Trigger
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 logged for that calculation time.
Examples of Scheduling Polled Triggers
You can schedule calculations using polled triggers, as shown in the following examples.
Example 1: Scheduling a Trigger to Fire Once a Day
- Select the tagname to which you want to apply the trigger.
- In the Collection tab, select Polled from the Collection Type drop-down list.
- Set the Collection Interval to 24 hours.
- Set the Collection Offset to 8 hours.
- Click Update.
Example 2: Scheduling a Trigger to Fire on a Specific Day
- Select the tagname to which you want to apply the trigger.
- In the Collection tab, select Polled from the Collection Type drop-down list, and configure the time of day by setting the Collection Interval to 24 hours and the Collection Offset to 17 hours.
- Click Update.
- Click the Calculation tab.
- Monday is the second day of the week, so enter the following VBScript in the Calculation pane:
Dim curDate curDate=CurrentTime IF (Weekday(curDate))=2 THEN Result=50 <Place your calculation here> END IF
- Click Update.
Notice that the
CurrentTime
built-in function is used in this example instead ofNow
.
Example 3: Scheduling a Trigger to Fire on the First Day of Every Month
The following is an example of how to schedule a calculation to occur on the first day of every month:
Dim curDate curDate=CurrentTime
IF (day(curDate))=1 THEN
Result=50 <Place your calculation here>
END IF
Example 4: Scheduling a Trigger to Fire on the Last Day of Every Month
The following is an example of how to schedule a calculation to occur on the last day of every month:
Dim curDate curDate=CurrentTime+1
IF (day(curDate))=1 THEN
Result=50 <Place your calculation here>
END IF
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
Unsolicited Trigger
Event-based triggers have a dependency list of trigger tags. The trigger fires whenever there is a data change for the trigger tag. Quality changes of the trigger tag will cause a new raw sample and therefore the trigger will fire. Value changes of the trigger tag occur 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.
- Deletion of a tag that is in the dependency list.
- Re-addition of a tag in the dependency list.
The calculation time of an event-based calculation is the timestamp of the sample in the trigger tag that caused the firing. 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 though 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.
Assigning a Trigger Tag to an Unsolicited Calculation Tag
To assign an unsolicited trigger to a calculation tag and set up a dependency list:
Examples of 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
.