# Monitor Duration On of a Tag

**URL:** <https://forum.inductiveautomation.com/t/monitor-duration-on-of-a-tag/57104>\
**Category:** Ignition\
**Created:** [March 11, 2022, 1:29pm UTC](https://forum.inductiveautomation.com/t/monitor-duration-on-of-a-tag/57104 "2022-03-11T13:29:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrcharl](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@byrcharl](https://forum.inductiveautomation.com/u/byrcharl)\
**Post date:** [March 11, 2022, 1:29pm UTC](https://forum.inductiveautomation.com/t/monitor-duration-on-of-a-tag/57104/1 "2022-03-11T13:29:14Z")

</div>

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 :

```auto
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.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [March 11, 2022, 1:56pm UTC](https://forum.inductiveautomation.com/t/monitor-duration-on-of-a-tag/57104/2 "2022-03-11T13:56:19Z")

</div>

Why not use tag history?

---

<div class="post-metadata">

**Author:** ![byrcharl](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@byrcharl](https://forum.inductiveautomation.com/u/byrcharl)\
**Post date:** [March 11, 2022, 2:07pm UTC](https://forum.inductiveautomation.com/t/monitor-duration-on-of-a-tag/57104/3 "2022-03-11T14:07:31Z")

</div>

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

```auto
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))

```
