# Set Tag Value and Change it after x- Seconds

**URL:** <https://forum.inductiveautomation.com/t/set-tag-value-and-change-it-after-x-seconds/84115>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting\
**Created:** [January 11, 2024, 3:10pm UTC](https://forum.inductiveautomation.com/t/set-tag-value-and-change-it-after-x-seconds/84115 "2024-01-11T15:10:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luca\_Hofmann](https://avatars.discourse-cdn.com/v4/letter/l/85e7bf/32.png) [@Luca\_Hofmann](https://forum.inductiveautomation.com/u/Luca_Hofmann)\
**Post date:** [January 11, 2024, 3:10pm UTC](https://forum.inductiveautomation.com/t/set-tag-value-and-change-it-after-x-seconds/84115/1 "2024-01-11T15:10:57Z")

</div>

Hello,  
easy question i guess, but is there a better way for doing the following:

I have a OPC Tag that represents a sensor value (Range is from 0.00 - 2.00).  
I have an alarm configured on the tag so if the tags value is above 1.00 i send an email over notification pipelines.

Now i wanna prevent sending another email within the next 7 hours, even if the Tags value goes below 1.00 and then above again.

## So my Idea was the following:

Create a Tag "stopper" with dataType Boolean and set it to false  
If my alarm gets active, i check if stopper is false, if so i send the email and after that i set the stopper to True. Now i want the stopper to switch back to false 7 hours later.

So far i came up with this:  
Value Changed Script on the stopper tag

i check if currentValue.value is True  
send it to sleep via time.sleep for 7 hours  
write back to itself and change value to False

Seems to work, but i guess thats not the best apporach?  
If so, what kind of trouble could i run into and whats a better approach?

I appreciate your help.  
Luca

---

<div class="post-metadata">

**Author:** ![Luca\_Hofmann](https://avatars.discourse-cdn.com/v4/letter/l/85e7bf/32.png) [@Luca\_Hofmann](https://forum.inductiveautomation.com/u/Luca_Hofmann)\
**Post date:** [January 11, 2024, 3:17pm UTC](https://forum.inductiveautomation.com/t/set-tag-value-and-change-it-after-x-seconds/84115/2 "2024-01-11T15:17:44Z")

</div>

Ah i think this has been discussed already:

> [@Reset Tag Value after a Number of Seconds](https://forum.inductiveautomation.com/t/reset-tag-value-after-a-number-of-seconds/17098):
>
> 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

Anyway i appreciate any tipp and help.

---

<div class="post-metadata">

**Author:** ![peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@peter](https://forum.inductiveautomation.com/u/peter)\
**Post date:** [January 11, 2024, 3:20pm UTC](https://forum.inductiveautomation.com/t/set-tag-value-and-change-it-after-x-seconds/84115/3 "2024-01-11T15:20:17Z")

</div>

I get what you are trying to do, but I'd structure it slightly differently.

Instead of a boolean, I'd use a tag that can store a date/time value. That way you can eliminate the timer altogether. The sequence of events would then be:

1. Value crosses alarm threshold and triggers script
2. Script reads saved date/time, and calculates the time difference between then and now.
3. If the difference is less than 7 hours, exit
4. If the difference is greater than 7 hours then:  
a. Send your notification  
b. Write the current time to the saved date/time tag.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [January 11, 2024, 3:24pm UTC](https://forum.inductiveautomation.com/t/set-tag-value-and-change-it-after-x-seconds/84115/4 "2024-01-11T15:24:49Z")

</div>

> [@Luca\_Hofmann](#):
>
> i check if currentValue.value is True  
> send it to sleep via time.sleep for 7 hours  
> write back to itself and change value to False

If by this you mean, use `time.sleep()` inside of a Tag Change Script. _DON'T_ that's a big no-no especially if you're using many such things. Tag Change scripts have a limited thread pool that they run on.

In fact in general, if you want to use `time.sleep()` anywhere in Ignition, you are almost certainly doing something the wrong way.

Instead, when the tag drops below your threshold set another tag to the current time. Inside the script, verify that the last email was sent outside of your time delay prior to sending the email.

---

<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:** [January 11, 2024, 3:28pm UTC](https://forum.inductiveautomation.com/t/set-tag-value-and-change-it-after-x-seconds/84115/5 "2024-01-11T15:28:22Z")

</div>

> [@peter](#):
>
> tag that can store a date/time ....

💯
