Set Tag Value and Change it after x- Seconds

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

Ah i think this has been discussed already:

Anyway i appreciate any tipp and help.

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.
5 Likes

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.

2 Likes

:100: