hasChanged functionality

I have a situation where I need to figure out if a value has changed within 24 hours. I have tried using the hasChanged method within an expression tag, however, it’s not 100% working as I intended.

For an example, I had a tag that had a value of zero when the hasChanged event ran. That tag was then updated throughout the day, but went back to zero by the time my expression tag executed the hasChanged event again (so the previous and new value were the same).

That being said, the hasChanged method returns a value of false, however, the value actually HAD changed within the 24 hour period.

Does anyone have any suggestions on how to get this working, or is there a better solution? What i am looking for is a way to figure out if a value stayed the same for a 24 hour period, meaning if the value NEVER changes at all within those 24 hours.


The hasChanged() expression function would work but you can’t just scan it once a day and expect it to know everything that happened to a value between scans.

If your worried about a value you changing though, I would log it in the historian. Then you can see how often/when it changed and what it changed to.

If your not using the historian to log values and want a rolling 24 hours, I would use a tag event script on value change. This method is also assuming you don’t care what it changed to or how many times it changed in 24 hours. You can then check for a change in value by comparing your previousValue.value and currentValue.value. If they are different then write your currentValue.timestamp to a memory tag. Doing it though the tag event script you can do other filtering based on quality changes to meet your needs. The reason I would write the timestamp to the memory tag is then you can use an expression tag to see if the date/time is less than 24 hours from now.

If you were looking for changes throughout a fixed 24 hour period instead of a rolling one, you could increment a memory tag so you would know how many times it changed. You still wouldn’t have the values it changed to unless you use a historian.

Both of these would let you know if you had a change in a 24 hour period but I still go back to what I said about the historian. If the value is important enough to care if it changed, I would have to assume knowing how it changed would be important to. If you don’t log the value then you won’t have a full picture of the changes. It isn’t hard to pull data back out of the historian but you have to put it there first to be able to use it.

1 Like

If you’re storing history on the tag(s), you could also do a timer script that checks the tag(s) you want every 24 hours and compares the difference between the minimum and maximum values the tag(s) reached in that period using system.tag.queryTagHistory().

dataset = system.tag.queryTagHistory(paths=['Your/Path/Here'],aggregationMode='MinMax',rangeHours=24)
difference = abs(dataset.getValueAt(0,1) - dataset.getValueAt(1,1))
if difference > 0:
1 Like

Thanks for the suggestion!

I didn’t think about using the querytaghistory function, that’s an excellent idea, thank you!