I have one analog tag which has only two values:0 and 1.
I want to calculate the duration of the step.
Want to calculate the duration of tag when value is 1 and remains 1 and store in different tag.
It's not pretty but you can try this:
IF 'IOTAG' = 1 THEN PrevEvent('IOTAG','*+1s') - (NextEvent('IOTAG',(FindEq('IOTAG','*','*-20d',0)))) ELSE 0
This will give the time in seconds that the value has been 1.
ps check the syntax of the ' because I'm writing this on my phone ;-)
You can also try the following:
LastStop output to attribute "Last Stop" (Date Time)
LastStart output to attribute "Last Start" (Date Time)
Output output to attribute "Timer" (Double, UOM: Seconds)
LastStop: If('Attribute1'=0)then ParseTime("*") else NoOutput()
LastStart: FindEQ('Attribute1','Last stop','*',1)
Output: if('Attribute1'=1) then TimeEQ('Attribute1','Last start','*',1) else 0
(note that pictures represent example where the value is above 50)
If you just want the total time when your tag is 1 just use:
Hey Andre! You were faster in this one! This is a good answer
I've used this calculation in similar cases, so I had the sample already
I have implemented your solution, but sometimes I'm not getting accurate start timestamp.
Please find screenshots as attached
The way this calculation works is that it separates the different 1 into new "events". If you bakcfill the data you will get the total time it's been 1 between 17-mar-15 03:17 and 17-mar-15 03:22 and a new "event" for the next time it goes high.
If you only want the time it's been 1 the last 24 hours you only need to specify:
The counter is made to reset when you value goes back to 0. So while you're doing evaluate you only calculate on the last "event".
Do you have access to Asset Based Analytics?
If yes, you could build and tests you calculation with it.
Anyway, this calculation can be also performed user the TimeEq or TimeGT function, in both products: Performance Equation or PI Analytics.
From the help file:
TimeEqFind the total time, within a range, when a point is equal to a given value.FormatTimeEq(tag, starttime, endtime, value) ... Returns The time period within the given range, for which the point was exactly equal to the given value. Examples
TimeEq('tag1', 't', '*',40.0)
TimeEq('digitaltag', '-1d', '*',TagVal('digitaltag', '14-Dec-97'))
TimeEq('digitaltag', '14-Dec-97', '*', "On")
Find the total time, within a range, when a point is equal to a given value.
TimeEq(tag, starttime, endtime, value)
The following links can provide you further information:
KB00464 - PI Performance Equation (PE) Tips and Tricks
KB00868 - PI Analytics: Which tool is best for the job
PI Performance Equations Help File
Normally this file exists under %pihome%\help\PEReference.chm
Retrieving data ...