Timer for Boolean Tags

I am trying to come up with the cleanest way to set a bool tag true for x amount of time then set it back to false once that time is made.

Ex. - Click button, set BOOL true, after 30 seconds change value of BOOL to False.

In perspective you could:

import time

MyTag ==1
time.sleep(30)
MyTag == 0

You’d need to create a bi-directional tag binding on a key value under the custom properties of the button and then trigger the above script on a button click.

That blows up if you click multiple times or from miltiple clients. If you are using any form of sleep, you are screwing up. Have your button set a timestamp in a memory tag. Have a gateway timer script check regularly to update the boolean.

Just because Perspective lets you use sleep() doesn’t mean it is a good idea.

4 Likes

Sounds like the perfect job for a PLC.

4 Likes

You can also set an alarm on the tag delayed for the duration that you want to allow it to be on.

On alarm active, you can then write itself to false again. I use this for non-critical items.

Anything important needs a PLC involved.