Periodic expression tag

I would like to create an expression tag (tag_A) that records values from another tag(tag_B) every 15 minutes of the hour.

I have created another expression tag based on this expression that reads real time constantly updated
tag_Timezone: dateFormat(now(), “MMM d, h:mm:ss a”)

Is there a way to go with scripting towards this?

The goal is to record values every 15 min of the hr 24/7 so a graph can be implemented. Any ideas?

If your trying to graph them, do you have access to a database? It would be easier to store values into a table in the database every 15 minutes to graph it later.

It could be done with scripting to tags but I could also see it getting complicated fast. How complicated would also depend on your tags. Are they individual tags for data points or are you creating a dataset in the tag? If they are individual tags, you would have a lot of tags go cover every 15 minutes in a week. You would also need a script to pick the right tag to write to.

If you are storing the results in a dataset then you can create a dataset with your new value when it is stored at the 15 minute mark and run a script that calls system.dataset.appendDataset to merge your existing results with your new value/time dataset. You could run this in a timer script. If you want specific run times you would need to have the timer script run often enough to catch it when you need it to and do an if statement at the start that only allows it to run at the time you want it to run.

If your trying to graph it I would still say you are better off storing the data in a database so you can pull it up later. This also allows you flexibility if you decide you need to look at a longer duration later or if you need to look up past weeks.

I do have access in the database. So do you suggest that the readings are being taken in the database and Im tag pathing the results to the graph as an embedded view?

Another idea is to simply set 4 tag expressions with possibly a timer script to set high every 15,30,45,60 minutes and tag path those tags on the data of a tag series graph? Although I am not entirely sure how I could set the x-axis implementing the updated time every hr?

The tag Im reading from the plc gives me the actual result I d need to implement on the Y-axis so I would basically have to print this result every 15 minutes on my graph.

Would this be possible in your point of view?

I will look up all the rest of the information you provided and I’ll get back to this post.

Thank you very much indeed.

My suggestion would be to do an insert into the database with the values you want and a timestamp every 15 minutes. You could do this easily using a named query and a timer script. The other option is to use the historian but if you wanted it at specific times you would need to use a timer script to trigger the data to be written to the historian at those times. You can do it with a tag change script and a expression tag but then your adding an extra tag you don’t need. That’s why I would do it with the timer script.

It is possible to do it the way your wanting but if your talking 4 tags that’s only 1 hour of data. Those 4 tags would still need to be inserted into a dataset in order to graph them. When you insert them you can create your time stamps. The dataset would have to be stored as a tag if you want it to hold 24 hours of data. You would then have to have a script that takes that data set and combines in with a new dataset with your new values to allow it to be a continuous trend. Then you would still need to also create a method to either remove entries that are older than you want or to erase the entire dataset at a set time. Erasing the entire dataset is the easiest way. To erase specific entries you would need to loop through the dataset to clear just the entries you no longer need. Where you mentioned recording it 24/7 storing data in a tag is a very bad option. It will cause the internal Ignition database to grow and eventually cause you issues. If you want to maintain a running history you really should write the values you need into a database.

That was very informative thank you.

To be more specific, the tag I want to display on the graph is an integer written on the plc showing a throughout result of a conveyor system. I ve just been updated that the throughput tag is being reset every day at 15:00 pm from the database.
So what if the scenario changes without storing the data but simply reading the throughput tag on a graph towards time every hour to show the live throughput? Would that be a simpler way?

If the chart is on the screen all the time you could set up a script on your screen that would update your chart but you would still have to build a dataset for the chart to work. If you tried to use the easy chart in realtime mode I believe it would still need data coming from the historian.

Realtime Mode. In this mode, the user is given the opportunity to pick the amount of time in the past to display. For example, the last 5 minutes or the last 2 hours. The chart will poll at a rate according to the Poll Rate parameter.

With any of the other charts you will have a Data property that is looking for a dataset. You would have to build this dataset and hold it somewhere. If you hold the data in a tag that grows but never clear it can cause issues with the gateway. If you hold it on the screen if it grows to big it can cause issues with the client. The other downside to holding it on the screen is if you navigate away from the screen and come back it, all your previous data will be lost.

If you just want to display the number you can do that with one of the different indicators in Ignition without storing the data. But if you want to chart the data it will have to be stored somewhere in order for it to show up on the chart.

Y’all might be making this more difficult than it needs to be. Consider using a transaction group to record your tag_B on schedule {start @ 12am repeat every 15 minutes}. Create a named query that selects the past hour from that table, using your database’s lag() function to give you deltas from one record to the next. Chart that named query (classic chart in Vision, timeseries chart in perspective).

5 Likes

The named query would be something like this:

SELECT t_stamp, CASE WHEN tagB < priorB THEN tagB ELSE tagB-priorB END AS deltaB
FROM (
  SELECT t_stamp, tagB, LAG(tagB) OVER (ORDER BY t_stamp) AS priorB
  FROM myThroughputTable
  WHERE t_stamp > (CURRENT_TIMESTAMP - INTERVAL '2' HOUR)
) subq
WHERE t_stamp > (CURRENT_TIMESTAMP - INTERVAL '1' HOUR)
ORDER BY t_stamp

The inner query gives the lag function some extra data to work with so there won’t be a null priorB for the first row in the desired hour. The case expression deals with your daily reset, passing the first value post-reset as the delta for the 15-minute period.

2 Likes

BTW, if you really need a short-term record of one or more tags or other values in a dataset (tag or property), take a look at the recorder() expression function in my (free!) Simulation Aids module. It wouldn’t suit this particular use, though, as you can’t make its periods align to any particular start timestamp.

1 Like

I’ve been trying to point toward having the data put into the database. I didn’t mention transaction groups just because I wasn’t sure if he had them. With one point, it would be an easy insert query too if transaction groups aren’t available. I agree with pturmel that the easiest way to do this is through a database.

In the end I’ve created a named query that is looking on the Tag from the database. That worked perfectly.How could I define the polling rate in order to test how quick my data are updating?

Could I use the self .refreshBinding( "props.data" ) expression on my graphs data binding for instance?