# Machine Towerlight (Green,Red,Yellow) light ON State Time Duration Measurement

**URL:** <https://forum.inductiveautomation.com/t/machine-towerlight-green-red-yellow-light-on-state-time-duration-measurement/67471>\
**Category:** Ignition\
**Tags:** ignition81, scripting, perspective\
**Created:** [December 11, 2022, 4:31pm UTC](https://forum.inductiveautomation.com/t/machine-towerlight-green-red-yellow-light-on-state-time-duration-measurement/67471 "2022-12-11T16:31:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shaheryar\_Ahmad](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@Shaheryar\_Ahmad](https://forum.inductiveautomation.com/u/Shaheryar_Ahmad)\
**Post date:** [December 11, 2022, 4:31pm UTC](https://forum.inductiveautomation.com/t/machine-towerlight-green-red-yellow-light-on-state-time-duration-measurement/67471/1 "2022-12-11T16:31:45Z")

</div>

Hi Everyone,

Need your guide and suggestion.

Actually, I want to record the ON state duration of our packing machines towerlight status (Green, Red, Yellow). Like when the batch started (success count \> 200), how much time (in minutes) the machine has spent on the Green Light (running state), on the Red Light (fault state) and on the Yellow light (standby/stopped by the operator state).

As, this duration will help me in the OEE calculation.

Previously, I tried the tag event script (on value change) where a while loop runs and increment a 'Running\_Duration' tag for every minutes passed. This works well when I applied this for Green light boolean state, but when I do this for other two lights. The script keeps running and not stopping. After studying from the forum found that loops are not a good idea to run in the tag event script.

So kindly guide me to accomplish this task 🙂

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 11, 2022, 5:30pm UTC](https://forum.inductiveautomation.com/t/machine-towerlight-green-red-yellow-light-on-state-time-duration-measurement/67471/2 "2022-12-11T17:30:09Z")

</div>

You have this question open in multiple topics, and with answers. It is against this [forum's rules](https://forum.inductiveautomation.com/faq) to do that. At least, not without linking to the other topics.

> [@How to get working Hours base on Boolean status](https://forum.inductiveautomation.com/t/how-to-get-working-hours-base-on-boolean-status/50364/3):
>
> Use a transaction group that has an on-change trigger for the boolean or integer of interest. Have the transaction group check the trigger as a pace that meets your accuracy requirements. Then query the database, using a LEAD() window function to look forward from an event to grab the timestamp of the next one. Use an outer query to compute the durations grouped by event value, discarding the grouped rows that aren't interesting. The insertions into the database can also be scripted if the S…

---

<div class="post-metadata">

**Author:** ![Shaheryar\_Ahmad](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@Shaheryar\_Ahmad](https://forum.inductiveautomation.com/u/Shaheryar_Ahmad)\
**Post date:** [December 11, 2022, 5:54pm UTC](https://forum.inductiveautomation.com/t/machine-towerlight-green-red-yellow-light-on-state-time-duration-measurement/67471/3 "2022-12-11T17:54:02Z")

</div>

This question is different from my previous post.

Here I am asking for people's suggestions and there experience if they have gone through same scenarios or done something like this.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 11, 2022, 9:52pm UTC](https://forum.inductiveautomation.com/t/machine-towerlight-green-red-yellow-light-on-state-time-duration-measurement/67471/4 "2022-12-11T21:52:35Z")

</div>

It seems like it would be simpler to put a timer in the PLC program, and then track the timer's accumulated value in ignition with an OPC tag.
