# System.Tag.Toggle?

**URL:** <https://forum.inductiveautomation.com/t/system-tag-toggle/34412>\
**Category:** Ignition\
**Created:** [May 4, 2020, 4:56pm UTC](https://forum.inductiveautomation.com/t/system-tag-toggle/34412 "2020-05-04T16:56:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaspinall](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jaspinall](https://forum.inductiveautomation.com/u/jaspinall)\
**Post date:** [May 4, 2020, 4:56pm UTC](https://forum.inductiveautomation.com/t/system-tag-toggle/34412/1 "2020-05-04T16:56:14Z")

</div>

Hi All,

Hoping someone could advise on whether there is any sort of ‘system.tag.toggle’ function that exists, similar to system.tag.write ? Basically, i want to write a tag to ‘1’ and then back to ‘0’ a second or two after via the script editor on the button.

Below is how I am currently accomplishing it, but i don’t believe this is best practice. If anyone could advise a better solution it would be appreciated.

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

Many Thanks

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [May 4, 2020, 5:35pm UTC](https://forum.inductiveautomation.com/t/system-tag-toggle/34412/2 "2020-05-04T17:35:21Z")

</div>

Try this (this is ‘real’ toggle):

```auto
system.tag.write("MYTAG_1", not system.tag.read("MYTAG_1").value)

```

---

<div class="post-metadata">

**Author:** ![jaspinall](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jaspinall](https://forum.inductiveautomation.com/u/jaspinall)\
**Post date:** [May 4, 2020, 5:49pm UTC](https://forum.inductiveautomation.com/t/system-tag-toggle/34412/3 "2020-05-04T17:49:56Z")

</div>

Hi @zxcslo - that is a really useful negate function, however, we need to write from 0 to 1, and then from 1 to 0, all in one button click. Sort of like what a momentary pushbutton would do. I might explore the ‘invoke later’ function.

---

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [May 4, 2020, 6:11pm UTC](https://forum.inductiveautomation.com/t/system-tag-toggle/34412/4 "2020-05-04T18:11:25Z")

</div>

InvokeLater will execute the function after the defined time.

You can probably do something like :

```auto
import time
system.tag.write('[Testing]Trial.value', 1)
# sleep(timeInSecond)
time.sleep(1)
system.tag.write('[Testing]Trial.value', 0)

```

if this is used more often :  
create a function and just pass the tagPath to the function.

---

<div class="post-metadata">

**Author:** ![jaspinall](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jaspinall](https://forum.inductiveautomation.com/u/jaspinall)\
**Post date:** [May 4, 2020, 6:19pm UTC](https://forum.inductiveautomation.com/t/system-tag-toggle/34412/5 "2020-05-04T18:19:27Z")

</div>

Thanks for sharing this! We want about a 3 second delay before resetting it, so InvokeLater might be the solution. I have saved this example code for future use though.

Cheers.

---

<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:** [May 4, 2020, 6:20pm UTC](https://forum.inductiveautomation.com/t/system-tag-toggle/34412/6 "2020-05-04T18:20:50Z")

</div>

Yes, you'll want to use invokeLater--not sleep--for the second write, as in this example:

> [@Delay system.tag.write in component scripting](http://forum.inductiveautomation.com/t/delay-system-tag-write-in-component-scripting/18272/2):
>
> Wrap it in system.util.invokeLater in the actionPerformed event. Replace “[Client]testFloat” in code below with the actual path to your tag (right-click on tag in Tag Browser and choose Copy Tag Path): # Define a function to call after a delay def writeLater(): import system system.tag.write("[Client]testFloat", 0) # Tell the system to invoke the "writeLater" function after 3 seconds (3000 ms) system.util.invokeLater(writeLater, 3000)

---

<div class="post-metadata">

**Author:** ![jaspinall](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jaspinall](https://forum.inductiveautomation.com/u/jaspinall)\
**Post date:** [May 4, 2020, 6:22pm UTC](https://forum.inductiveautomation.com/t/system-tag-toggle/34412/7 "2020-05-04T18:22:56Z")

</div>

Super. Thanks for sharing this.
