# Transaction group help, equipment state duration capture

**URL:** <https://forum.inductiveautomation.com/t/transaction-group-help-equipment-state-duration-capture/60081>\
**Category:** Ignition\
**Created:** [May 26, 2022, 4:34pm UTC](https://forum.inductiveautomation.com/t/transaction-group-help-equipment-state-duration-capture/60081 "2022-05-26T16:34:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 26, 2022, 4:34pm UTC](https://forum.inductiveautomation.com/t/transaction-group-help-equipment-state-duration-capture/60081/1 "2022-05-26T16:34:07Z")

</div>

What is the easy way to capture the duration of machine states in a transaction group?

Instead of calculating the duration in the query, I want to have duration as a column I think.  
( I might miss some edges cases, not worried about them )

Do I script some tags as counters that reset on state change for each machine?  
Must be a better way I think.

update: hours meter function in the transaction group item put the duration of the previous state into the group for me, and I added a tag to capture the previous state as well, thanks for the help

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 26, 2022, 4:44pm UTC](https://forum.inductiveautomation.com/t/transaction-group-help-equipment-state-duration-capture/60081/2 "2022-05-26T16:44:19Z")

</div>

Does it have to be in a transaction group? Assuming you have a tag that keeps track of the machine state, a tag change event on the tag would give you the opportunity to log what the new value is and when it changes.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 26, 2022, 5:04pm UTC](https://forum.inductiveautomation.com/t/transaction-group-help-equipment-state-duration-capture/60081/3 "2022-05-26T17:04:50Z")

</div>

Can you access the previous timestamp of a tag in an expression item of the transaction group and say like timestamp - old timestamp?

> [@bkarabinchak.psi](#):
>
> Assuming you have a tag that keeps track of the machine state, a tag change event on the tag would give you the opportunity to log what the new value is and when it changes.

I am not sure how I can have the old time and the new time available to me to do the calculation.

oh I see it

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [May 26, 2022, 5:13pm UTC](https://forum.inductiveautomation.com/t/transaction-group-help-equipment-state-duration-capture/60081/4 "2022-05-26T17:13:06Z")

</div>

In tag event scripts, you have `previousValue` and `currentValue` available and are fully qualified values. You can access the previous timestamp by doing `previousValue.timestamp` and the same with the currentValue.

You can also look into event meters in transaction groups  
[Hour and Event Meters - Transaction Group Items (inductiveuniversity.com)](https://inductiveuniversity.com/videos/hour-and-event-meters/8.1)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 26, 2022, 5:23pm UTC](https://forum.inductiveautomation.com/t/transaction-group-help-equipment-state-duration-capture/60081/5 "2022-05-26T17:23:45Z")

</div>

> [@dkhayes117](#):
>
> You can access the previous timestamp by doing `previousValue.timestamp`

Just a word of warning. This timestamp may not be what you think it is. For instance perhaps the tag value is updated due to a quality change, this time stamp may no longer reflect the time which the value last changed.

IMHO, you're better off tracking the time of the last value change in a memory tag.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 26, 2022, 5:28pm UTC](https://forum.inductiveautomation.com/t/transaction-group-help-equipment-state-duration-capture/60081/6 "2022-05-26T17:28:02Z")

</div>

What about the hour meter feature in the transaction group?

Is that usable?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 26, 2022, 5:29pm UTC](https://forum.inductiveautomation.com/t/transaction-group-help-equipment-state-duration-capture/60081/7 "2022-05-26T17:29:37Z")

</div>

I wouldn’t see why not, if that’s the functionality that you’re looking for.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 26, 2022, 5:52pm UTC](https://forum.inductiveautomation.com/t/transaction-group-help-equipment-state-duration-capture/60081/8 "2022-05-26T17:52:12Z")

</div>

The hour meter puts the duration of the previous state into the transaction group.

So it is kind of useful.

Is there an easy way to put the previous state into another item in the same transaction group?  
Then I would have the current state, previous state, and the duration of previous state so my queries will be very organized.

I can make a tag if not.

In the opc item path, can I designate the previous value?  
Looks like I need to make a tag that holds the previous value and then I should be set.

Thanks for the help!
