Down time timer

I have a UDT that has a Boolean tag for when a piece of equipment goes down. I want to have a tag that also tracks how long it is down retentively and then zero it at end of shift. Looking for some ideas on how to do this. I tried several things that are not working correctly and seem to be much more complex then I think it should be.

Do you store tag history for the state tag? This is the way I’ve approached this problem in the past. Then you can query for state changes throughout the day and get the total amount of time the equipment is in each state.

1 Like

I agree on using tag history.

1 Like

I think there is no timer like that in ignition. I have a similiar request. Using Gateway Events Timer script, check the Boolean tag per second, if True, the timer tag add 1. And a Gateway Schedule script, reset the timer tag to zero at midnight.

I’d use a tag change script instead, and do a timestamp comparison…

Well, yes, I have hundreds of these devices, so I opted for the gateway script so I don’t have to configure the script for each device tag.
UDT is a better choise, but I have some historical issues.

There’s a tag change script gateway event that you can use. There’s no need to configure a value change script on each tag.

pascal - Do you have an example of how you would use a tag change script. I have an expression tag I am using now, that does not work due to how I am trying to add the previous to the current. It also seems overly complex.
if({[.]Shift} = 0, 0, if({[.]Down} = True, if(isNull({[.]DownTime}), 0, {[.]DownTime} + secondsBetween({[.]TempDownTime}, now())), {[.]DownTime}))

Something like that will trigger when a tag becomes true. It reads the current timer from a tag called active_time in the same folder as the tag that changed, compute the difference in seconds between the previous timestamp and the current timestamp, add it to the previous active_time value and write it back to the tag:

if not initialChange and newValue.value:
	timer_path = "{}/active_time".format(event.tagPath.parentPath)
	current_timer = system.tag.readBlocking([timer_path])[0].value
	new_timer = (newValue.timestamp.getTime() - previousValue.timestamp.getTime()) / 1000
	system.tag.writeBlocking([timer_path], [current_timer + new_timer])

You can monitor as many tags as you want with it, just add them to the tag list. As long as they have a tag called active_time in the same folder, it will work.

PS: You might need to rework it a bit to better handle the initialChange.

This works well for getting the total downtime throughout the day. Would it be possible to make this work to show it as it is ticking off the time by seconds? I want to be able to show it in real time as they are down.

You could do this where you display it.
First, a clarification: the code in my previous message counts active time, not down time. Adapt as you see fit, but for the rest of this post I’ll use an active_time tag that times… active time.
For example you’d bind a label to active_time, which would get you the time it’s been active for this day (assuming you reset it at midnight).
If the machine is currently down, then there’s nothing to change.
If the machine is currently running, then you’ll need to add the time between when the tag was last updated to now.
So, an expression like this would do the job:

if ({the_tag_you_monitor},
    {active_time},
    {active_time} + secondsBetween({active_time.timestamp}, now())
)

I haven’t tested it, take it as conceptual code