Counter per shift

Is it possible to create a counter per shift where I have a tag that gives me a global accumulation eg. Bottles_per_production_day=45,032 but I want the bottles per shift
Shift 1 (5am-1pm)= 15,350 bottles
Shift 2 (1pm-9pm)= 16,480 bottles
Shift 3 (9pm-5am)= 13,202 bottles

and when another day passes it would reset to 0 each of the shifts to be able to start the accumulation again.
Is this possible?

You can create an expression tag to determine the current shift number based on the current time, example expression:

if(getHour24(now()) < 5,
  if(getHour24(now()) < 13,
    if(getHour24(now()) < 21,

Then make a trigger script on it to set the next counter to 0 when the shift changes. And use this value to determine what counter to increase (the details depend on what you use to count).

1 Like

One possibility would be to log the value of the tag at the end of the the shift. You can then either use a query to do the math, or use a script.

You could also, as an alternative, log it every hour and get hourly counts (managers seem to love that kind of stuff :wink:)

1 Like

This is the way that we are trying to do it. Thing is we want to log it every shift but also show it in real-time on the dashboard.

Consider using an odometer-style counter that never resets. Log its value to the database at any desired pace, or faster. Then subtract one value from any previous value for the production over that interval. Subtract the current value from any previous value for the live count since that sample.


But is it possible to make a counter per shift of an already existing tag to be able to show in real time the accumulation per shifts? In my case I have a tag that gives me the water usage in hectoliters for a specific order. I already put this to save in the database using transaction groups and I included my shifts and order number in the table. Would it be possible to achieve this by some sort of scripting or query tag?

We are just trying to get real time data while at the same time trying to store that specific value. In this case it would be the water consumption on a specified shift with a specified order/batch number.

You could run a query that sums the quantities for batches that finished within a particular shift, and add the live qty for the current shift. It gets tricky accounting for batches that start in one shift and end in a later shift.