Timer script in tag

Hello i need to write an expression tag where if a specific tag is above a threshold value for > than 5 seconds it will turn to 1. What is the best way to incorporate the time element? is it to have a runscript in the tag itself?

Is this for alarming purposes or for triggering something else?
You could configure an alarm on the tag with a 5 second ActiveDelay

No not for alarm purpose. Basically i have a plc tag which if about a certain value for a period of time we consider it a quality issue.

Other way to handle this without using the alarm properties of a tag is to have a separate memory tag of type datetime, and a boolean expression tag.

Using a Gateway Tag Change Event pointed at the tag you want to monitor, push the current timestamp into the memory tag only if the monitored tag's previous value was not above the limit, and the current value is above the limit. If the value is not above the limit, put a null into the tag.

In the expression tag, have it determine if the memory tag is a valid date (not null) and then compare the elapsed time between that datetime and the current timestamp and return True if the time difference is more than your time limit (5 seconds). Something along the lines of:

if(
	!isNull{path.to.timestamp.tag}),
	dateDiff(now(1000), {path.to.timestamp.tag}, 'second') > 5,
	false
)

This really is alarm behavior. Consider using an alarm and just not call it an alarm. Perhaps send it to a special alarm pipeline for quality notifications.

3 Likes