Alarm if value is the same as it was x minutes ago

I’d like to setup an alarm that will alert the team if a tag value is the same as it was 15 minutes ago. The process involves an integer value that should constantly be adjusting. I’d like to evaluate every few seconds constantly looking back at recent history.

Utilizing perspective if it makes a difference. My first thought was to:

  1. Setup a new tag which references the key tag from 15 minutes ago
  2. Setup an expression tag to find the difference between the current value and the value from step 1.
  3. Setup an alarm on this delta tag from step 2.

Unfortunately I’m stuck on the first step as the datasource on the query tag doesn’t allow me to select the built in history. Whenever I used history in the past it would be part of a script tied to a button with code like the following:

dataset = system.tag.queryTagHistory(paths=[path], startDate=startTime, endDate=endTime, returnSize=1, aggregationMode=“LastValue”, returnFormat=‘Wide’)
historyValue = dataset.getValueAt(0,1)

Is there anyway to write a script for an expression tag OR write a script that runs periodically and writes to a memory tag?

Is there a better approach to getting these alarms?

1 Like

Do you care if the value is the same as it was 15 min ago or if it is just not been changed in 15 min? You can use gateway event scripts, like a scheduled or timer script to trigger an alarm.

Take a look at the expression hasChangd. hasChanged - Ignition User Manual 8.1 - Ignition Documentation

That will be true if is has changed since the last poll and then setup an alarm if it is false. Set the time delay on the alarm to 900 seconds and you should only get the alarm if it has not changed at all in 15 minutes.

Good point, I just care if the value changed. I’ll dig into the gateway event scripts since it seems like it would be very useful.

You can use the fact that OPC doesn’t change a tag’s timestamp unless the value has changed.

3 s alarm delay

On the Alarm/OK label I’ve created an expression binding to my statusBit tag:

if(
	{[default]statusBit} &&
	(now(500) - {[default]statusBit.Timestamp} > 3000),
	"Alarm",
	"OK"
)

It checks every 500 ms if the status bit has been on for more than 3000 ms.

I’ve created a similar binding on the border color:

if(
	{[default]statusBit} &&
	(now(1000) - {[default]statusBit.Timestamp} > 3000),
	"--error",
	"--success"
)

The --error and --success are from the built-in theme colors.

Someone may chip in an point out some reason why this might be unreliable