Obtain tag value 1 minute ago

Hello i need to get the tag value 1 minute ago and sustract with the actual value, i am using the maker edition

Some questions:

  • How often is the tag updating?
    • How often do you need to update your 1 minute ago difference?
  • Are you tracking this tag with the historian?
  • Do you want the value in a tag or just want to display it on a screen?
  • How often is the tag updating?
    1 sec but it is so slow so it works for me 1 minute

    • How often do you need to update your 1 minute ago difference?
      for ever, actually i need to plot the sustracted value
  • Are you tracking this tag with the historian?
    yes, i am already plotting the tag

  • Do you want the value in a tag or just want to display it on a screen?
    i want the value to display and historan

The easiest thing to do might be to run a gateway timer script that does something like this.

readPath = 'PATH_TO_INITIAL_TAG'
storagePath = 'PATH_TO_INTERMEDIATE_TAG'
differencePath = 'PATH_TO_TAG_DIFFERENCE'

currentValue, oldValue = system.tag.readBlocking([readPath,storagePath])
calculatedDifference = currentValue.value - oldValue.value
system.tag.writeBlocking([storagePath,differencePath],[currentValue.value,calculatedDifference])

This will work on whatever period you set the timer script to run. It will break down somewhat if the gateway is stopped for a period of time. It'll take the difference from just before the gateway was stopped to the time of the first run which won't be the same duration you've selected, possibly muddying your data.

Another option would be to try system.tag.queryTagHistory.