Measuring Deltas
Scenario:
Capturing delta on the timestamp for the duration of state of an OPC tag
Subscribe to the OPC tag and set it as a trigger in an event flow.


Then capture the timestamp values by toggling on "Include Metadata" on the OPC Input.

For "saving" the previous timestamp, you can either use Condition logic or Pipeline State variable.
Using Condition:
In a Condition, you can use the expressions:
Expression:
{{this.currentValue}}._tagTimestamp - {{this.lastValue}}._tagTimestamp;

This caches to disk in /appData directory in the intelligencehub-cache.db file.
Using Pipeline:
Pipeline gives you more flexibility and the following uses State variables to save the previous timestamp and calculates the timestamp difference in a Transform:

State variables write to the intelligencehub-state.db file in /appData directory.
Transform code:
// Retrieve the previous timestamp from the pipeline state. If it doesn't exist, default to 0.
let previous_ts = state.pipeline.get("previous_ts", 0);
// Get the current timestamp from the event's tag timestamp.
let current_ts = event.value._tagTimestamp;
// Calculate the time difference between the current and previous timestamps.
let return_ts = current_ts - previous_ts;
// Set the calculated time difference in the current stage's value.
stage.setValue(return_ts);
// Update the pipeline state with the current timestamp for future calculations.
state.pipeline.set("previous_ts", current_ts);