How to constrain this data to only show the value for current day/ reset every 12 hours

I have this label which I want to use to display a pick counter from a palletizer, and currently it just displays a "lifetime" total/ count and I would like for it to instead only show the count for "today" or "the last 12 hours starting at midnight"

Where is the data coming from? Database or PLC?

I believe that though the palletizer is connected to the plc, it is coming from a separate database. Would there be a way for me to verify this one way or another as a total novice? alternatively is there a solution for both and I could just try each one and see which works?

Since it acts as an odometer, just move the lifetime value to a memory tag whenever you need to start from zero. Then it's the difference of the memory tag and the lifetime tag.

1 Like

How would I do that? Or any resources that could explain doing that in sorta "layman's terms"?

As far as moving the value do you have an explanation towards doing that? The tag I'm currently referencing is already a memory tag, is it easy to create a new memory tag in ignition that references it? How do I make it only reference the last ~12 hours of info/ preferably restart at midnight?

It is information for a palletizer and though I believe the same info does come through a plc, this tag references the data through a separate database and uses a memory tag.

It gets more complex when you want only the past 12 hours with a midnight demarcation.

If this is already coming from the database, and Ignition is performing the query, we may be able to make another query to get the information you need.

Or just any way to display the mem tags value but reset it to only show the count for that day. Is it possible to make another tag that references the memory tag (like it "counts up" as the existing memory tag counts up) but that resets itself either every 24 hours or at midnight or every 12 hours or when another tag goes off even?

Just again, I have a couple years experience with PLCs but I have been doing ignition less than two weeks

As an example:

Make two tags:
One memory tag to hold your start count (e.g. StartCount)
One boolean expression tag with the expression:

case(dateFormat(now(), 'HH:mm:ss'),
     "00:00:00", True,
     "12:00:00", True,
     False
   ) 

Add a script on the boolean tag to move the odometer value to the start count.

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	if currentValue.value:
		tagIn  = ['[default]path/to/the/odometer']
		tagOut = ['[default]path/to/the/StartCount']
		odometer = system.tag.readBlocking(tagIn)[0].value
		system.tag.writeBlocking(tagOut, odometer)
3 Likes

Some light reading. :wink:

2 Likes

Sorry marked this as solution because it seemed like it was, however implementing this has instead caused the value to sorta display a "freeze" of what it was at the start of the day. As in, the "odometer" tag reads 55625 while the new tag reads 5560, which was the tags value at the start of the day. So I suppose the easiest way to resolve this would be to have an expression or tag that displays a value equal to the "old" odometer tag minus the "new" tag? Or is there an easier way to do this.

Correct, you'll want a third, integer expression tag with:

{[default]path/to/the/odometer}-{[default]path/to/the/StartCount}

Note that if something happens to the gateway during that crucial period of first minute of noon or midnight, the update script may not fire and you'll still have the previous day's count as your baseline until the next reset time. If that's not acceptable, then you'll need to do something more complex like your own tag history query.

1 Like

Okay nice, that's what I ended up doing and I Believe it is working as intended now. My best band aid mitigation for that crucial moment being missed is I changed the set times to 4 am (1 hour before they start for the day and the count is necessary) and one for 5 am (right before they start) this way if all goes correctly it'll set at 4 and set again to the exact same value at 5, or if it misses the earlier or later set it will hopefully be covered by the other. Not exactly elegant but should suffice for now.