# Reset Tag Value after a Number of Seconds

**URL:** <https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098>\
**Category:** Ignition\
**Created:** [February 22, 2018, 6:05pm UTC](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098 "2018-02-22T18:05:52Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![lshirley](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lshirley/32/6627_2.png) [@lshirley](https://forum.inductiveautomation.com/u/lshirley)\
**Post date:** [February 22, 2018, 6:05pm UTC](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098/1 "2018-02-22T18:05:52Z")

</div>

Hello,

Does anybody by chance know how I could reset a tag’s value to a coded default value after a set number of seconds?

Any help is greatly appreciated…

Thanks in advance.

-Lenny

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [February 22, 2018, 6:18pm UTC](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098/2 "2018-02-22T18:18:47Z")

</div>

Make another tag of type Date to store the time of your existing tags last transition. In your existing tag, add an OnValueChange event script that sets your new date tag to system.date.now() whenever  
`previousValue.value != currentValue.value`  
Then make a third tag, an expression tag, that evaluates to the time between the above date tag and now(). Give it an OnValueChange event script that checks if the currentValue.value is greater than your predefined number of seconds. If it is, then reset your existing tag to the default.

See this post for something similar: [Timer function that works gloabally(gateway)](http://forum.inductiveautomation.com/t/timer-function-that-works-gloabally-gateway/16849/4?u=bfuson)

---

<div class="post-metadata">

**Author:** ![lshirley](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lshirley/32/6627_2.png) [@lshirley](https://forum.inductiveautomation.com/u/lshirley)\
**Post date:** [February 22, 2018, 6:38pm UTC](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098/3 "2018-02-22T18:38:50Z")

</div>

Thanks! That worked out great…

-Lenny

---

<div class="post-metadata">

**Author:** ![hamlinjr](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hamlinjr/32/8228_2.png) [@hamlinjr](https://forum.inductiveautomation.com/u/hamlinjr)\
**Post date:** [February 22, 2018, 9:53pm UTC](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098/4 "2018-02-22T21:53:56Z")

</div>

Another possible option using just the one existing tag could be something like this in the tag’s Value Changed event script.

```auto
import time

defaultValue = YOUR DEFAULT VALUE HERE
delaySeconds = YOUR TIME DELAY HERE

if currentValue.value != defaultValue:
    time.sleep(delaySeconds)
    system.tag.write(tagPath, defaultValue)
else: pass

```

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [February 22, 2018, 11:00pm UTC](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098/5 "2018-02-22T23:00:15Z")

</div>

This does work and looks a lot better, though doesn’t it block the event thread?

---

<div class="post-metadata">

**Author:** ![hamlinjr](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hamlinjr/32/8228_2.png) [@hamlinjr](https://forum.inductiveautomation.com/u/hamlinjr)\
**Post date:** [February 22, 2018, 11:30pm UTC](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098/6 "2018-02-22T23:30:49Z")

</div>

You’re right, it does. I’ve used this on a few tags here that need to self change state and have never seen any issue from it, but I’m only sleeping 1 or 2 seconds on mine.

Now I have a fun project to see what havoc I can cause tomorrow when I sleep a test tag for longer!

---

<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 23, 2018, 2:30am UTC](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098/7 "2018-02-23T02:30:52Z")

</div>

python’s time.sleep and Java’s Thread.sleep are truly dangerous in GUI environments. They should never, ever, be called from any GUI event routine. They _can_ be called from independent threads, but it is almost always better to schedule a deferred function, using an ExecutorService if necessary. Or use a timer component or client timer event.

---

<div class="post-metadata">

**Author:** ![hamlinjr](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hamlinjr/32/8228_2.png) [@hamlinjr](https://forum.inductiveautomation.com/u/hamlinjr)\
**Post date:** [March 16, 2018, 9:45pm UTC](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098/8 "2018-03-16T21:45:57Z")

</div>

Thank you @pturmel you set me on the path to enlightenment… 🙂

Working on a different issue, Ethan with IA support crafted me a superior script which still allowed me to keep everything in one tag:

```auto
import time
def resetTag():
    time.sleep(3)
    system.tag.write(tagPath, 0)

defaultValue = SOMETHING

if currentValue.value != defaultValue:
    system.util.invokeAsynchronous(resetTag)
else: pass

```

---

<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 16, 2018, 11:53pm UTC](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098/9 "2018-03-16T23:53:46Z")

</div>

It’s unfortunate that there’s no alternative to invokeLater in gateway scope. I may just have to add something to [later.py](https://www.automation-pros.com/ignition/later.py) to address this.

---

<div class="post-metadata">

**Author:** ![prithvidesai](https://avatars.discourse-cdn.com/v4/letter/p/dfb087/32.png) [@prithvidesai](https://forum.inductiveautomation.com/u/prithvidesai)\
**Post date:** [March 19, 2018, 5:47pm UTC](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098/10 "2018-03-19T17:47:45Z")

</div>

Try below script on reset tag \> Tag Events\> Value Changed event:

```
s = 0
delay = 0

while delay < 3:
	
	if s == 0:
		date = system.date.now()
		s = system.date.getSecond(date)
	else:
		date = system.date.now()
		t = system.date.getSecond(date)
		delay = delay + abs(t - s)
system.tag.write("Folder_Path/Scada_Reset",0)
```

---

<div class="post-metadata">

**Author:** ![mmunin](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@mmunin](https://forum.inductiveautomation.com/u/mmunin)\
**Post date:** [July 21, 2020, 9:47pm UTC](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098/11 "2020-07-21T21:47:38Z")

</div>

Could you explain this later.py file? Is this something I can import that will let me execute asynchronously from the gateway scope?

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [September 4, 2020, 3:08pm UTC](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098/12 "2020-09-04T15:08:22Z")

</div>

This will also work. system.util.invokeLater(writeLater,_“Put the time delay Here”_)

```auto
#Clear Values From Entry Fields
		def writeLater():
			event.source.parent.getComponent('Status').selectedValue = -1
		system.util.invokeLater(writeLater, *2000*)

```

---

<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:** [September 4, 2020, 3:13pm UTC](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098/13 "2020-09-04T15:13:04Z")

</div>

`system.util.invokeLater()` doesn’t exist in gateway scope. Look in `later.py` for a work-around.

---

<div class="post-metadata">

**Author:** ![eichler-eng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/eichler-eng/32/21259_2.png) [@eichler-eng](https://forum.inductiveautomation.com/u/eichler-eng)\
**Post date:** [October 26, 2021, 3:45am UTC](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098/14 "2021-10-26T03:45:44Z")

</div>

Thanks. This helped me rig up a basic simulation of a real world panel with N.C. and N.O. buttons.
