IMD SolutionComputing LibraryShop main store

How-to

How to log a tag only when another tag is true in Historian

Edge computing and IIoT Published 8 min read

Short answer

Create an event tag whose Snapshot action fires when Tag B becomes 1 to store one Tag A value per activation. For every value while Tag B stays 1, keep cyclic storage and filter at retrieval. With Historian rated at 150,000 values per second sustained, a two-tag system is limited by acquisition, not storage.

On this page
  1. How do I log Tag A only when Tag B equals 1?
  2. Why don't the Delta and Forced options do this?
  3. How do I set up an event tag with a snapshot action?
  4. Why does the snapshot store only one value while Tag B stays at 1?
  5. Why can't Historian log my fast-changing tag quickly enough?
  6. How do I insert a string value like a barcode from InTouch?
  7. Should I move this logging to plain SQL Server tables?
  8. Questions asked

You can log Tag A only when Tag B equals 1, but not with a storage mode. Split the requirement first: one Tag A value each time Tag B becomes 1 is an event, built as an event tag with a Snapshot action; every Tag A value for as long as Tag B stays 1 is continuous logging, kept in cyclic or delta storage with the Tag B condition applied as a retrieval filter. The storage engine in Historian 2023 R2 takes far more than two tags can deliver, so a system that falls behind is limited in the acquisition path, not in storage. String records such as barcodes written from InTouch belong in StringHistory, not plain SQL tables.

How do I log Tag A only when Tag B equals 1? #

Create an event tag whose Snapshot action fires when Tag B becomes 1 to store one Tag A value per activation, and for every value while Tag B remains 1 leave storage cyclic and filter at retrieval, because no storage mode expresses a cross-tag condition.

Read the requirement as edge or level before touching configuration. "Tag B becomes 1" is an edge: it happens once per activation. "Tag B equals 1" held over time is a level. Delta and Forced, the two options the tag's storage configuration offers, decide when one tag's own values are stored, and neither can read another tag, so the cross-tag rule has to live in an event definition or in the retrieval query.

Required output Condition on Tag B Build it with
One Tag A value per activation becomes 1 Event tag with a Snapshot action
Every Tag A value through the active period remains 1 Cyclic storage on Tag A, condition applied at retrieval
One string record, such as a barcode an InTouch condition fires INSERT StringHistory from the script

Pick the row that matches the record you actually need, then follow its path in the sections below.

Why don't the Delta and Forced options do this? #

Delta and Forced are storage modes on a single tag — Delta stores when the tag's own value changes past a deadband, Forced stores on demand — and neither can read another tag, so the Tag B rule must live in an event definition or in the retrieval query.

A storage mode answers one question: when does this tag's own value get written? Delta fires on a change past the configured deadband; Forced stores outside the change and time criteria, on demand. The rule "Tag B equals 1" reads a different tag's value, so it cannot be expressed in either place. Two mechanisms can hold it: an event definition that fires an action when its condition becomes true, or a filter in the query that reads history back.

If you take the continuous route, how AVEVA Historian stores one-second cyclic tags as deltas shows what the delta engine actually writes for a cyclic tag, and that stored stream is what your retrieval filter selects from.

Leave Delta and Forced to pace one tag's own storage, and put the Tag B condition in the event or in the query.

How do I set up an event tag with a snapshot action? #

Historize both tags, define the event on Tag B with a Snapshot action that captures Tag A, and treat the evaluation interval as detection latency — the snapshot reads stored history, so an unhistorized tag gives the action nothing to capture.

  1. Historize both tags. The Snapshot action captures Tag A from stored values, and event evaluation reads Tag B's stored transitions. On the system described here the values arrive through ABCIP, and that interface's update rate bounds what the event can ever see.
  2. Create the event definition with Tag B = 1 as its trigger expression.
  3. Set the action to Snapshot and point it at Tag A.
  4. Set the event's evaluation interval as a latency budget, not as an acquisition rate; the next section works the numbers.
  5. Retrieve the results: on the Historian tab, in the Tag Management group, click Tag Values, then click Event Snapshot Values.
  6. Prove it: force one Tag B transition and confirm exactly one Tag A row appears there with the expected timestamp and good quality. If Tag A reads correctly under Tag Values, Live Values, but no snapshot row appears, the condition or action binding is wrong; if Tag A's stored history is missing rows, fix acquisition before touching the event.

Why does the snapshot store only one value while Tag B stays at 1? #

The Snapshot action is edge-triggered: it fires when Tag B turns ON and stores nothing further while it stays ON, so a 30-second active period yields one row where cyclic logging at 25 ms would yield 1,200.

The action evaluates "condition became ON," which is an edge. A level — "condition is ON" — is the other requirement, and it needs the continuous route, not a faster event.

The evaluation interval is detection latency over stored history, not a sampling rate. Worked example: Tag B's history stores a transition at 250 ms resolution, and the event evaluates every 60 s. The transition is still found, because event evaluation reads history, but the result can arrive up to 60 s late, and 60,000 ms ÷ 250 ms = 240 stored Tag B samples accumulate between evaluations. A live controller poll once every 60 s fails differently: it can miss a transition entirely, because nothing was stored between polls.

Transitions present in Tag B's history but actions late: shorten the evaluation interval. Transitions missing from history: fix the acquisition path, because no event setting recreates an unsampled pulse. Requirement truly "while Tag B is 1": switch to cyclic storage and filter at retrieval.

Why can't Historian log my fast-changing tag quickly enough? #

Historian sustains a documented 150,000 values per second with short bursts to 300,000, so two tags — even updating every 25 ms — load it under 0.1 percent; the limit is upstream in the PLC interface, the OPC server, or the communication driver.

Those figures are throughput references for the storage engine, not a promise that any controller connection can deliver data at that speed. Buffer count is the knob that matters when measured ingestion approaches the reference. On small tag counts, sustained updates faster than 25 ms have been demonstrated on modest hardware, so a two-tag count never identifies the storage engine as the bottleneck; in practice the PLC's interface, the OPC server, or the communication driver limits first.

Worked example: Tag A stored cyclically every 25 ms gives 1,000 ms ÷ 25 ms = 40 values per second, and Tag B stored on delta while toggling every 50 ms gives 1,000 ms ÷ 50 ms = 20 stored changes per second. Combined load: 40 + 20 = 60 values per second, which is 60 ÷ 150,000 = 0.0004, or 0.04 percent of the sustained reference. At that load the storage engine is effectively idle, so transitions that never appeared were never delivered. Trace the path:

  1. Read Tag B's stored history with timestamps and quality, not from a screen refresh, which reflects the display's own update rate.
  2. Compare those timestamps against the values the communication driver reports from the controller.
  3. If transitions disappear before the driver sees them, the controller interface or the driver's acquisition configuration is the limit; spreading acquisition across additional instances of the interface or driver raises that ceiling.
  4. Only when the driver delivers the transitions and stored history still lags, read the ingestion diagnostics and raise the buffer count.

With two tags, expect step 3 to be the finding.

How do I insert a string value like a barcode from InTouch? #

Use INSERT StringHistory for string values: on Historian 2023 R2 the History form with vValue fails on strings with Msg 8114, while StringHistory with wwVersion 'REALTIME' appends the current value and lets the historian apply the timestamp.

The reported case writes tag 'SKUBarcode_PC' with value '320033434' from an InTouch condition script. The plain History insert fails on this release:

INSERT INSQL.Runtime.dbo.History (DateTime, TagName, vValue, QualityDetail, wwVersion)
VALUES (GETDATE(), 'SKUBarcode_PC', '320033434', 192, 'LATEST')

It returns Msg 8114, Level 16, State 11, "Error converting data type nvarchar to (null)": the History form does not take a string in vValue here. The string form works:

INSERT StringHistory (TagName, Value, OPCQuality, wwVersion)
VALUES ('SKUBarcode_PC', '320033434', 192, 'REALTIME')

The tag name and value are the example ones; substitute your own. wwVersion 'REALTIME' lets the historian apply the arrival timestamp, the efficient form when every insert appends a new current value; when a row must carry a specific time, the same insert takes DateTime and Value explicitly instead.

Transact-SQL inserts and updates run under the security SQL Server already enforces, and deleting a stored value is not available through this interface. If the statement fails on permissions rather than conversion, fixing a Historian vValue write permission error on string tags covers that path.

Test the result: after the insert, open Tag Values, Live Values and confirm the value with a fresh timestamp and good quality, then query the history range to confirm the row persists.

Should I move this logging to plain SQL Server tables? #

Keep tag history out of plain SQL Server tables: the historian's extension tables store the same values far more compactly — plan roughly 50 times the space for properly indexed SQL tables — and plain-table insert rates degrade as tables grow.

Time-series values land in the extension tables, which is why retrieval-time filtering over stored history beats copying gated values into relational tables. Event tags are the one legacy exception: their results go to conventional SQL Server tables, which keeps them practical at tens of tags and breaks them down at thousands. At that scale, store the tags normally and apply the Tag B condition in the query instead.

Relational tables are the right home when each record is a transaction — a production order, a barcode scan, a batch result — rather than a sample of a signal. For that shape, logging production data from a panel PC to SQL Server is the pattern to follow, with retention and archive policies planned from day one.

The decision: signals stay in the historian with event or retrieval filtering, transactions go to SQL Server, and string snapshots go through StringHistory either way.

Questions asked

Do both tags need history enabled for the event tag to capture anything?

Yes. The Snapshot action reads Tag A's stored values and event evaluation reads Tag B's stored transitions, so both tags must be historized. Set Tag B's storage resolution finer than its shortest on-state, or a pulse shorter than that interval is never stored and no event setting can recover it.

Is 192 the right OPCQuality for a StringHistory insert?

Yes, 192 marks the inserted value as good quality, matching the documented insert examples. Historian stores a quality field with every value, and retrieval can exclude rows whose quality is not good, so inserting a bad-quality code makes the row easy to lose in queries.

What does wwVersion REALTIME do differently from LATEST?

REALTIME lets Historian timestamp the value on arrival, the efficient form when every insert appends a new current value. LATEST with GETDATE() supplies the timestamp inside the statement. When a row must carry a specific past time, use the DateTime form of the StringHistory insert instead.

Can I delete a value I inserted by mistake?

No. Transact-SQL inserts and updates run under the security SQL Server already enforces, but deleting a stored value is not available through that interface, just as it is not through a CSV import. Correct a bad row by writing a new value at the same timestamp instead of trying to remove it.

Should I raise the buffer count to keep up with a fast Tag B?

Not before tracing acquisition. Buffer count tuning serves the storage engine, which sustains 150,000 values per second; two tags cannot approach that. If transitions vanish before the communication driver reports them, spread acquisition across additional interface or driver instances, which raises the acquisition ceiling.

Keep reading

  • Explainer

    AVEVA Historian to PI replication version requirements

    Replication from AVEVA Historian to AVEVA PI needs the 2023 release of Historian or later and PI Web API v1.16.0 or later on the destination. The two version numbers never need to match, and there is no direct requirement on the PI Archive version. Historian-to-Historian replication instead requires the destination to be the same version or newer than the source.

    Edge computing and IIoT

  • Troubleshooting

    Query tag history from a remote tag provider

    Yes: Tag Historian is one module with two jobs — storage and retrieval — so the gateway where system.tag.queryTagHistory runs must license it too. Install and license the module on the querying gateway; from 8.1 a read-only license covers a gateway that only consumes history. Prove the fix by matching row counts between the two gateways.

    Edge computing and IIoT

  • Explainer

    AVEVA Historian Connector redundancy options explained

    AVEVA Historian Connector v3.1 does not manage failover between redundant Historians. For collection redundancy, run two Connectors, each writing to its own Historian, with configurations you keep identical by procedure; use Historian partner and client failover only to cover temporary access loss.

    Edge computing and IIoT