Monitor Duration On of a Tag

Im in need of help. I am wanting to monitor a bool tag for duration on and display the last “Shifts” Worth of accumulated time. I have a idea of how to do it but what im running into issues if the server connection is lost it will reset the tags instead of the shift reset.

Way i have it setup :

if({[.]LT_AST_IND1},if(IsGood({[.]LT_AST_IND1}),{[.]ATS_TIME_IND1.value},0)+1,if(IsGood({[.]ATS_TIME_IND1.value}),{[.]ATS_TIME_IND1.value},0))

I have a expression tag counting up everytime the bool becomes true. What i have found is if i run tag history on the bool tag there is a aggerate mode that is for duration on but its in mSec. I just cant get it to display the info on say a label. Any help appreciated.

Why not use tag history?

1 Like

What im currently looking at . What i need is a set time every day. Say from 730am pst to 6pm pst every day.

import system

# Build a list of String tag paths
paths = [
            "[default]AFE2/Assistance Beacons/INDUCTS/LT_AST_IND1",
            "[default]AFE2/Assistance Beacons/INDUCTS/LT_AST_IND2"
        ]
 
# Determine the calculation to use
calc = ["DurationOn"]
 
# Define the date range
end = system.date.now()
start = system.date.parse("2022-03-10 4:00:00")
 
# Run the query, returning the results as an Ignition dataset
data = system.tag.queryTagCalculations(paths, calc, start, end)
 
# From here you would need to do something useful with the data variable. You could extract the values
#   and write them to a tag, pass them to a dataset property on a component, or any number of other things.
print "The calculated value for the first tag is " + str(data.getValueAt(0,1)/60)
print "The calculated value for the second tag is " + str(data.getValueAt(1,1))