# How to reset Tag value every day

**URL:** <https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922>\
**Category:** Ignition\
**Created:** [February 27, 2019, 1:20pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922 "2019-02-27T13:20:19Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![adominguez](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@adominguez](https://forum.inductiveautomation.com/u/adominguez)\
**Post date:** [February 27, 2019, 1:20pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/1 "2019-02-27T13:20:20Z")

</div>

Does anybody by chance know how I could reset a tag’s value to a coded default value day after day?

Also I want to see how much energy I’ve been using dialy, from a totalizer energy RTU

Greetings

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [February 27, 2019, 4:25pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/2 "2019-02-27T16:25:48Z")

</div>

Assuming you want this to happen at midnight, you could create an expression tag `dayOfMonth` with this expression:

```auto
getDayOfMonth(now())

```

Then create a project gateway tag change script that runs when `dayOfMonth` changes and writes the default value to the tag you want to reset daily.

Change the trigger tag expression and script conditions as needed if you want the reset to happen at some other time of day.

---

<div class="post-metadata">

**Author:** ![adominguez](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@adominguez](https://forum.inductiveautomation.com/u/adominguez)\
**Post date:** [February 28, 2019, 6:24pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/3 "2019-02-28T18:24:38Z")

</div>

witman, I did accurately the things you write, but there isn’t a new assignment  
in the gateway script I put when the tag value has changed,

```auto
E_dia=0

```

but although was compiled, there’s no variable assignment. please help.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [February 28, 2019, 6:30pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/4 "2019-02-28T18:30:17Z")

</div>

Post your tag change script

---

<div class="post-metadata">

**Author:** ![adominguez](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@adominguez](https://forum.inductiveautomation.com/u/adominguez)\
**Post date:** [February 28, 2019, 6:41pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/5 "2019-02-28T18:41:03Z")

</div>

I put this

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/2/2cad4bb348abb9c837ef1673dc1ee0ae4c998561.png)

and then

 ![Captura_2](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/dc0b94d937262b707e315c44f137044a1792cd03.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 28, 2019, 6:43pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/6 "2019-02-28T18:43:35Z")

</div>

That script assigns the value zero to the script local variable `E_dia`. Which then ceases to exist at the end of the script.  
You must use [system.tag.write()](https://docs.inductiveautomation.com/display/DOC79/system.tag.write) to assign a value to a persistent tag.

---

<div class="post-metadata">

**Author:** ![adominguez](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@adominguez](https://forum.inductiveautomation.com/u/adominguez)\
**Post date:** [February 28, 2019, 9:05pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/8 "2019-02-28T21:05:33Z")

</div>

I continue with this issue. The gateway doesn’t trigger anymore, although I have enabled the tag change

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c8e41fd7d359ebedc6a1a031ea0bb791e258e63f.png)

then I go to Tag browser and E\_acum did’t change anymore

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/b1422c294fc00c498add17cd455160846b4c23fd.png)

the script is with no errors (i probe in the script console) and the trigger tag is changing each second. Also the tag path is correct.

what’s the problem then??

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [February 28, 2019, 9:13pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/9 "2019-02-28T21:13:59Z")

</div>

Check on your gateway web page under Status-\>Gateway Scripts–\>Tag Change:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6b857de03cf04b5abc12dd77ea42964c171a1393.png)  
It will show last time each script ran and whether it succeeded or failed. Failure messages will show in log below.

You can also add your own logs there by adding code like this to your script:

```python
# Get logger with name 'GatewayEventScripts.TagChange' (you can name it nearly anything you want).
logger = system.util.getLogger('GatewayEventScripts.TagChange')
# Log your message. You can include variables in log too.
logger.info('your log message with calc value: %i' %(calcValue))

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 28, 2019, 9:51pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/10 "2019-02-28T21:51:46Z")

</div>

`system.tag.write("tagpath", value)` needs to have a qualified tag path when you’re running on the gateway - meaning, `system.tag.write("[default]tagpath", value)` almost certainly.

---

<div class="post-metadata">

**Author:** ![adominguez](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@adominguez](https://forum.inductiveautomation.com/u/adominguez)\
**Post date:** [March 1, 2019, 6:19pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/11 "2019-03-01T18:19:37Z")

</div>

No way guys, in the script the tag change value, there’s no error,

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/e910fd0eda69f67fb4a73cf586c3152045760e47.png)

Even If I only put print(“a”), the variable doesn’t appear in the console. Sounds that the trigger doesn’t run.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/2/23183e03e90e3c71301fa72373405f1c07453fef.png)

and 10\_segundos is setted

```auto
dateFormat(now(), "ss")/10

```

an integer that changes every 10 seconds.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 1, 2019, 6:38pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/12 "2019-03-01T18:38:26Z")

</div>

The script runs fine in the script console because it’s not running on the gateway, meaning it doesn’t need to have a tag provider specified. Qualify the tag path, and the script should work.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 1, 2019, 6:59pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/13 "2019-03-01T18:59:47Z")

</div>

That’s a gateway tag change script in a project – tag provider is implied.

---

<div class="post-metadata">

**Author:** ![adominguez](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@adominguez](https://forum.inductiveautomation.com/u/adominguez)\
**Post date:** [March 1, 2019, 7:14pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/14 "2019-03-01T19:14:34Z")

</div>

So? guys, if I only put print(“a”) the ouput console is not printing. My opinion is that the trigger is not running.

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [March 1, 2019, 7:21pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/15 "2019-03-01T19:21:56Z")

</div>

A gateway script won’t print to a designer/client output console. It will go to the gateway logs I believe(don’t quote me on this part).

What does the page witman mentioned above say? Is it showing that it executed?

---

<div class="post-metadata">

**Author:** ![adominguez](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@adominguez](https://forum.inductiveautomation.com/u/adominguez)\
**Post date:** [March 8, 2019, 2:22pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/16 "2019-03-08T14:22:29Z")

</div>

Yes, it is showing that, but version 7.8 only says that is executed but doesn’t show a response (this time the script is called “Energia\_dia”)

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c4eaef50f5846ebb564f0f8130f306801020364c.png)

then I go again to te referred tags and… no changes. I also called the tag in the last post

```auto
system.tag.write("[default]E_dia",0)

```

does anybody knows what’s the hell going on?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 8, 2019, 2:26pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/17 "2019-03-08T14:26:58Z")

</div>

> [@adominguez](#):
>
> guys, if I only put print(“a”) the ouput console is not printing.

It's never going to print to your designer's console. It's a _ **gateway** _ script. Any print operation is only going to show up in your gateway's wrapper log. A logger operation will show in the gateway web interface logs.

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [March 8, 2019, 6:23pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/18 "2019-03-08T18:23:21Z")

</div>

I thought v7.8 showed any script errors below on that page too, but maybe that came in v7.9.

Is your tag set read only?  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/638fe7025a2a1e1ff649fe90a80bf5ad88bba913.png)

> [@pturmel](#):
>
> A logger operation will show in the gateway web interface logs.

Add the logger code in [my post above](http://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/9) to your script to get something showing in your gateway logs. Once something is showing, modify it as desired to give you useful debugging information.

Are you sure your tag provider is "default"? Or have you changed it to something else? Check here: [http://YourIgnitionServerAddress:8088/main/web/config/tags.realtime?3](http://YourIgnitionServerAddress:8088/main/web/config/tags.realtime?3). You should see something like this and you'll need to use the same name as shown (example below is not the default name--if you're running one project on multiple servers, you don't want to use default):  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/2/299323a5d14deac2191593e968ed6340f695dd3c.png)

---

<div class="post-metadata">

**Author:** ![adominguez](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@adominguez](https://forum.inductiveautomation.com/u/adominguez)\
**Post date:** [March 13, 2019, 2:52pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/19 "2019-03-13T14:52:54Z")

</div>

Thanks pturnel, witman an all !

I’ve tried other manner: add a Timer Script that run each minute with this code:

```auto
import datetime 

now = datetime.datetime.now()

if now.day != system.tag.read("[default]Last_day").value:
                system.tag.write("[default]Last_day", now.day)
                system.tag.write("[default]E_dia", int(0))
                system.tag.write("[default]E_ant_dia","[default]E_acum")

```

It runs at the gateway. the right tag name have to be qualified, in my case [default].

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/047cd9fd2318d9d737d931c787fd30e936ec13ea.png)

7.8 version haven’t a console response, but I test the script by tag changes.

Regards to all

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [March 13, 2019, 4:55pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-tag-value-every-day/22922/20 "2019-03-13T16:55:09Z")

</div>

You can make things a little more efficient by using [system.tag.writeAll](https://docs.inductiveautomation.com/display/DOC79/system.tag.writeAll) anytime you’re writing more than one tag. If you want the value of E\_acum written to E\_ant\_dia, you’ll need to read it too (ignore this if you want the value of E\_ant\_dia to be the string “[default]E\_acum”). Script below reads E\_acum value to later write it to E\_ant\_dia and uses single calls to read and write multiple tags at once for better efficiency:

```python
import datetime 

# Get current date.
now = datetime.datetime.now()

# Read last day and e acum.
readTags = ['[default]%s' %s for s in ['Last_day', 'E_acum']]
lastDay, eAcum = [x.value for x in system.tag.readAll(readTags)]

# If it's a new day, write new values to tags.
if now.day != lastDay:
	writeTags = ['[default]%s' %s for s in ['Last_day', 'E_dia', 'E_ant_dia']]
	writeValues = [now.day, int(0), eAcum]
	system.tag.writeAll(writeTags, writeValues)

```
