Previous Values

I’m very new to the system…

I need to get the differnce between the current value and previous value.

thank you

1 Like

Are you using Perspective or Vision?

Using a property change script in Perspective:

    # make sure the indentation is correct if copying this code

    # This component has a custom property I created with a key of "difference" which stores 
    # the difference between the new value and the old value.
	if previousValue and previousValue.value:
		self.custom.difference = currentValue.value - previousValue.value

Vision

What would be prefered?

1 Like
# make sure the indentation is correct if copying this code

# This component has a custom property I created with a key of "difference" which stores 
# the difference between the new value and the old value.
if event.propertyName == 'intValue':
	event.source.difference = event.newValue - event.oldValue
1 Like

This needs a little more context to give a useful answer:

  • current/previous value of what exactly? I presume a tag?
  • how and where do you want to see this difference? E.g. Do you want another tag to hold this value?

It depends what you're doing. What's your application? You need to use vision if you want to interact with the client's filesystem, but I would tend to recommend perspective otherwise as it's newer and is where most development effort is being spent

Yes a tag.
A new tag would probably make the most sense.

Currently it is mainly for a simple dashboarding application where monitoring takes places.So no real action needs to take place other some simple navigation and may be some reporting.

So I think for now i’ll start with perspective and go from there.

Sorry for the delay, but if you want to track the difference between a tag’s value and its previous value in a tag, I would actually store the previous value in another tag, and then use an expression tag to calc the difference.

  1. Create a new tag in the same directory called ‘Previous Value’ (as an example)
  2. In the current value tag’s config, configure a Tag Event Script on the Value Changed event :
if not initialChange:
    prevTagPath = "[.]Previous Value"
    system.tag.writeAsync([prevTagPath], [previousValue.value])
  1. Create a new expression tag with the expression:
{[.]Previous Value} - {[.]Current Value}

Difference in previous value time and current value time? If the value is same more than 30 minutes should come a message that machine is downtime? how it is possible?

How to bind this for visible property?

Note that this is off topic of the original post, and should be in its own thread.
But to anser your question:

I would make an expression tag with something like:

minutesBetween({[.]path/to/tag.Timestamp}, now()) >= 30

then bind the visibility to the expression tag.

if the current value and previous value is same more than 30 minutes . It should give a message that machine is downtime in a visible property binding for icon.

If the value is the same the timestamp won't change.

i am not asking about timestamp , i just asking the time difference if between 30 minutes the value is same it should say some message .

But to make that happen, something needs to check regularly, because the lack of change itself produces no events you could use. You need some other event, like a polling now() expression, to cause your logic to evaluate.

1 Like