# Zeroing variable daily - not midnight

**URL:** <https://forum.inductiveautomation.com/t/zeroing-variable-daily-not-midnight/48989>\
**Category:** Ignition\
**Created:** [July 20, 2021, 2:14pm UTC](https://forum.inductiveautomation.com/t/zeroing-variable-daily-not-midnight/48989 "2021-07-20T14:14:00Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Water2Steam](https://avatars.discourse-cdn.com/v4/letter/w/a9adbd/32.png) [@Water2Steam](https://forum.inductiveautomation.com/u/Water2Steam)\
**Post date:** [July 20, 2021, 2:14pm UTC](https://forum.inductiveautomation.com/t/zeroing-variable-daily-not-midnight/48989/1 "2021-07-20T14:14:00Z")

</div>

Actually a bunch of questions, I’m new to Ignition, and even my PLC skills sometimes are a little rusty, but a new job has me trying to come up to speed fast. We’re doing a little in Perspective, but my questions, for now, are all in Vision; predecessors to me created a some highly developed windows over the last 10 years. MySQL on the database side. There is still one person in our department who’s very good with automation, but had done less with Ignition tasks that needed scripts or advanced Ignition topics. I’ll start with the question in the title, and may need to start separate threads for the places it branches.

I’m bringing in a raw number from a counter, and doing a little math to make it a daily count. We want to reset the variable for a numeric Label/Text Field daily; maybe 2:00 or 4:00am. A similar counter looks like it was doing the math in the PLC, while Ignition had several additional tags for prior days & handling zeroing. The counter in question here doesn’t need to come through a PLC

Is there a preferred way to do this? Is it best in a script, expression, or a tag script? What is the best way to fire it? Just thinking a couple years down the road, I don’t want things unnecessarily firing every second if it’s an excess load on the software or database.

Thank you!

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [July 20, 2021, 2:33pm UTC](https://forum.inductiveautomation.com/t/zeroing-variable-daily-not-midnight/48989/2 "2021-07-20T14:33:19Z")

</div>

> [@Water2Steam](#):
>
> , I’m new to Ignition,

Welcome!

> [@Water2Steam](#):
>
> reset the variable for a numeric Label/Text Field daily

So how does this field get its variable?

But usually things like that are best run in a gateway script, because else it might trigger multiple times or not at all depending how many clients are open!

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [July 20, 2021, 2:44pm UTC](https://forum.inductiveautomation.com/t/zeroing-variable-daily-not-midnight/48989/3 "2021-07-20T14:44:34Z")

</div>

If you’re on Ignition 8.1.6 or later, check out [scheduled scripts](https://docs.inductiveautomation.com/display/DOC81/Gateway+Event+Scripts#GatewayEventScripts-GatewayScheduledScripts).

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [July 20, 2021, 2:47pm UTC](https://forum.inductiveautomation.com/t/zeroing-variable-daily-not-midnight/48989/4 "2021-07-20T14:47:15Z")

</div>

If you are not in 8.1.6, I think the common accepted way to do this is to create an expression tag of boolean type that is True at the time you want to run your script, and then make a Gateway Event → Tag Change Script and put the logic you want to do there (or preferably in a function but call it there).

---

<div class="post-metadata">

**Author:** ![Water2Steam](https://avatars.discourse-cdn.com/v4/letter/w/a9adbd/32.png) [@Water2Steam](https://forum.inductiveautomation.com/u/Water2Steam)\
**Post date:** [July 20, 2021, 3:20pm UTC](https://forum.inductiveautomation.com/t/zeroing-variable-daily-not-midnight/48989/5 "2021-07-20T15:20:51Z")

</div>

Thanks all! Version 8.0.15.

The counter is from a value on a tag. That too begs the question of what should fire the script, or expression if the better approach. On a test screen, I had success writing the count script on a Numeric Text Field with the raw data from the tag, and firing it from property change. The output then on a separate field. That seemed to make sense for counting, but that method seems like would be constantly firing if I was bringing in time.

---

<div class="post-metadata">

**Author:** ![Water2Steam](https://avatars.discourse-cdn.com/v4/letter/w/a9adbd/32.png) [@Water2Steam](https://forum.inductiveautomation.com/u/Water2Steam)\
**Post date:** [July 20, 2021, 3:22pm UTC](https://forum.inductiveautomation.com/t/zeroing-variable-daily-not-midnight/48989/6 "2021-07-20T15:22:36Z")

</div>

> [@bkarabinchak.psi](#):
>
> If you are not in 8.1.6, I think the common accepted way to do this is to create an expression tag of boolean type that is True at the time you want to run your script, and then make a Gateway Event → Tag Change Script and put the logic you want to do there (or preferably in a function but call it there).

I'll have to look; somebody probably already created a similar expression on it in the past.

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [July 20, 2021, 3:35pm UTC](https://forum.inductiveautomation.com/t/zeroing-variable-daily-not-midnight/48989/7 "2021-07-20T15:35:04Z")

</div>

If you’re pre-8.1.6 and have the report module installed, you can also setup a scheduled report that doesn’t actually report anything and just calls a script as it’s action.

---

<div class="post-metadata">

**Author:** ![Water2Steam](https://avatars.discourse-cdn.com/v4/letter/w/a9adbd/32.png) [@Water2Steam](https://forum.inductiveautomation.com/u/Water2Steam)\
**Post date:** [July 21, 2021, 3:31pm UTC](https://forum.inductiveautomation.com/t/zeroing-variable-daily-not-midnight/48989/8 "2021-07-21T15:31:12Z")

</div>

I couldn’t find a previously created hour tag (and a minute tag for testing purposes), so I created that as an integer.

The boolean expression sounds like a clean way to do it! For some reason though I find scripting to objects easier than tags yet. With a Numeric Field binding its value from the hour Tag, I have a Property Change script on that with an if statement to check the hour; then 0ing the appropriate values. For testing purposes I have it at 0 minute, instead of an hour. It looks like it is working well. Aside from the invisible field to clutter things later, is there anything wrong with this approach?

Thanks!

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [August 4, 2021, 6:33am UTC](https://forum.inductiveautomation.com/t/zeroing-variable-daily-not-midnight/48989/9 "2021-08-04T06:33:48Z")

</div>

binding a timebased function that only is supposed to run once on a component/numeric field binding is not good. It would trigger multiple times if multiple poeple are online on that page or (maybe worse) not at all if noone is running the client on that page. You should do this on the gateway/tags

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [August 4, 2021, 1:25pm UTC](https://forum.inductiveautomation.com/t/zeroing-variable-daily-not-midnight/48989/10 "2021-08-04T13:25:21Z")

</div>

Another option is to eliminate the need for resetting. See this post:

> [@Tag history difference over interval](https://forum.inductiveautomation.com/t/tag-history-difference-over-interval/48366/2):
>
> With the help of @JordanCClark (thanks, didn’t know about zip), I ended up with the below script. It will take a history tag (integer, float, double) and find the difference over hour intervals between a start and end date. Any value over 0 will be counted. You can rollover at any time, although your process may deem it necessary to only rollover if you aren’t running. You can then use this is a bar chart, for example, to show counts per hour over time. If the tag doesn’t exist, it should j…

---

<div class="post-metadata">

**Author:** ![Water2Steam](https://avatars.discourse-cdn.com/v4/letter/w/a9adbd/32.png) [@Water2Steam](https://forum.inductiveautomation.com/u/Water2Steam)\
**Post date:** [August 4, 2021, 9:41pm UTC](https://forum.inductiveautomation.com/t/zeroing-variable-daily-not-midnight/48989/11 "2021-08-04T21:41:44Z")

</div>

> [@victordcq](#):
>
> It would trigger multiple times if multiple poeple are online on that page or (maybe worse) not at all if noone is running the client on that page. You should do this on the gateway/tags

I should have read that better the first time you wrote it! The script was fine against multiple triggers, but worthless for missed triggers.

Thank you!

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [August 4, 2021, 10:23pm UTC](https://forum.inductiveautomation.com/t/zeroing-variable-daily-not-midnight/48989/12 "2021-08-04T22:23:15Z")

</div>

> [@Water2Steam](#):
>
> The script was fine against multiple triggers, but worthless for missed triggers.

The script I referenced will work for missed 'triggers' as you are just looking at a counter value. You could miss 100 or more and it will pick that up.

---

<div class="post-metadata">

**Author:** ![Water2Steam](https://avatars.discourse-cdn.com/v4/letter/w/a9adbd/32.png) [@Water2Steam](https://forum.inductiveautomation.com/u/Water2Steam)\
**Post date:** [September 9, 2021, 7:22pm UTC](https://forum.inductiveautomation.com/t/zeroing-variable-daily-not-midnight/48989/13 "2021-09-09T19:22:15Z")

</div>

Over a month later, I realized I didn’t reply here. I was referring to my earlier script not working, not the one you referenced.

Still it’s been so reliable since I re-wrote it onto tags, that I hadn’t tried any other ways. I sure appreciate the option though; I might need it next time.
