Tag history - return last time in state

I have a tag recording drum speed. I would like to make a label to show the last time the drum was at 0 rpm. How can I achieve this with the Tag history?

My end goal is to use dateDiff() to show how long the drum has been stopped, or how long the drum has been running.

Example:

Drum RPM: 60
Running for 90 min

OR

Drum RPM: 0
Stopped for 36 min

I don’t think you will be able to pull up the last time it was at 0 as easy as you would think, from the historian. I don’t know of a way to search for a specific value other than looking for an on/off on a bool value. Also you typically provide it with a time range to pull up history so if the last time it was at 0 is outside of your range, it won’t give you a value.

What I would do is use a tag event, value changed script on the tag that shows your rpm value. I would do something like:

	if not initialChange:
		if previousValue.value == 0:
			stopT = previousValue.timestamp
			startT = currentValue.timestamp
			stoppedT = system.date.minutesBetween(prevT,curT)
			val = [stoppedT]
			path = ["your tag path"] # use a memory tag to store the duration of your last stop.
			system.tag.writeBlocking(path,val)

This would give you the duration of your last stop. If you want it to give a running count of how long it is stopped, then I would do something like:

	if not initialChange:
		if previousValue.value == 0:
			startT = currentValue.timestamp
			val = [startT]
			path = ["your tag path"] # use a memory tag to store the duration of your last stop.
			system.tag.writeBlocking(path,val)
		elif currentValue.value == 0:
			stopT = currentValue.timestamp
			val = [stopT]
			path = ["your tag Path"]
			system.tag.writeBlocking(path,val)

Then you can use an expression to figure out the difference between the two. If the stop time is after the start time then you would have your expression get the difference between the stop time and now().

1 Like