# 10 second timer tag

**URL:** <https://forum.inductiveautomation.com/t/10-second-timer-tag/74506>\
**Category:** Ignition\
**Created:** [June 2, 2023, 6:27pm UTC](https://forum.inductiveautomation.com/t/10-second-timer-tag/74506 "2023-06-02T18:27:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![denji26](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/denji26/32/5805_2.png) [@denji26](https://forum.inductiveautomation.com/u/denji26)\
**Post date:** [June 2, 2023, 6:27pm UTC](https://forum.inductiveautomation.com/t/10-second-timer-tag/74506/1 "2023-06-02T18:27:05Z")

</div>

I have a boolean tag that when false, I want to run another script that executes periodically that verifies that the first tag should actually be false and if not sets it true.

I was originally using **dateExtract(now(),'second')%10=0 && {[.]bool1/Value}=False,** which mostly works, except that until the first 10 second multiple is reached, the trigger could occur anywhere from 0 to 10 seconds, and afterwards would indeed be every 10 seconds.

My second attempt was  
**toInt(dateDiff({[.]enableCancel/Value.Timestamp}, now(),'second'))%10=0 && {[.]bool1/Value}=False**

I like this idea better since it executes every 10 seconds since the event started, except this triggers immediately as the initial dateDiff is 0.

Any suggestions? I would like to keep to tag(s) and not use a gateway timer script.

---

<div class="post-metadata">

**Author:** ![denji26](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/denji26/32/5805_2.png) [@denji26](https://forum.inductiveautomation.com/u/denji26)\
**Post date:** [June 2, 2023, 6:33pm UTC](https://forum.inductiveautomation.com/t/10-second-timer-tag/74506/2 "2023-06-02T18:33:45Z")

</div>

Ok I just added a check for dateDiff to not be 0, so lol yeah.

---

<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:** [June 2, 2023, 6:34pm UTC](https://forum.inductiveautomation.com/t/10-second-timer-tag/74506/3 "2023-06-02T18:34:56Z")

</div>

I'm not sure why you wouldn't want to use a gateway timer script, but you can make a 10 second _flasher_ like this

```auto
toMillis(now(10000)) % 20000 > 10000

```

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [June 2, 2023, 8:28pm UTC](https://forum.inductiveautomation.com/t/10-second-timer-tag/74506/4 "2023-06-02T20:28:55Z")

</div>

I have a similar question to OP... I have a tag right now (Memory tag of type String) that holds a message to display to the user. The reason why it's in a tag is because I read/write to it from the UI and from tag change scripts, so I needed something globally scoped. It probably isn't the best way to accomplish this, but it works.

I would like to reset the tag after 10 seconds or so, so that users don't get confused whether a message they're seeing is current or stale.

I would also really try to avoid using a `time.sleep` or some similar mechanism, but I can't come up with a way to accomplish this.

I was thinking to use a tag group that reads every 10 seconds indefinitely, but it doesn't give me what I want (namely, the 10 second timer to start when the message tag gets populated, not just a cyclic 10 seconds).

Do you have an idea of how to accomplish this?

---

<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:** [June 2, 2023, 8:36pm UTC](https://forum.inductiveautomation.com/t/10-second-timer-tag/74506/5 "2023-06-02T20:36:45Z")

</div>

Use a second tag that looks at the timestamp of the message tag and compare that to `now()` if the len of the message is greater than zero.

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [June 27, 2023, 8:13pm UTC](https://forum.inductiveautomation.com/t/10-second-timer-tag/74506/6 "2023-06-27T20:13:02Z")

</div>

Getting back into this project and wanted to make sure I understand you... You're saying that two tags is all I'll need (say, `statusMsg` and `statusMsgTs`)?

I have a setup like this right now, with `statusMsg` being a String memory tag and `statusMsgTs` being a Boolean Expression tag. On the expression, I have something like this:

```auto
if(
    secondsBetween(now(0), {[.]statusMsg.Timestamp}) > 10 
        && len({[.]statusMsg}) > 0, 
    true, 
    false
)

```

What isn't super clear is the third step that would clear the tag. The most obvious method would be to have a gateway tag change script that would reset the `statusMsgTs` back to `false` and clear the `statusMsg` tag. Is there something else you had in mind?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 27, 2023, 8:37pm UTC](https://forum.inductiveautomation.com/t/10-second-timer-tag/74506/7 "2023-06-27T20:37:25Z")

</div>

Make your expression tag hold either the status string or the empty string, then point your display to the expression tag.

```auto
if(
    secondsBetween(now(), {[.]statusMsg.Timestamp}) > 10,
    '', 
    {[.]statusMsg}
)

```

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [June 27, 2023, 9:01pm UTC](https://forum.inductiveautomation.com/t/10-second-timer-tag/74506/8 "2023-06-27T21:01:32Z")

</div>

Perfect, that is what I was looking for. The only thing I added was to wrap the `secondsBetween` call in `abs`, as I was initially confused why the tag wasn't clearing. This can also be done by swapping the order of the parameters in that expression function, but I might reuse this setup elsewhere, so it will be good to have generalizable (future and past times).

Thank you again.
