Trigger script when tag change

Hi,

I tried to use script on LED display. What I want is to trigger script when tag value = 20.

So I have tank level tag. I have LED display to indicate stock level of full 100 liters drum for tanks, 5 at the moment. Every time full drum is replaced I want to deduct 1 unit from number 5 “stock level”.
In my case I want trigger the script when drum level reach 20 as this is minimum tank level when drums are replaced.

if “E-Coat/Test”.value ==20:
value = event.source.value
print value
newvalue = value - 1
print newvalue
event.source.value = newvalue

Thanks for you help
Pawel

You have to be very careful with the scope your script is running in.

You can add a script to a GUI component, but that means the code will run on the client. So if there are no clients open, the script won’t run. If there are two clients open, the script will run twice…

If you want to do such a trick, you need to do it on the gateway scope. Either add a “tag changed” event to the tag configuration, or use the gateway scripts that work on tag trigger.

But even in that case, you need to be very careful. F.e. what will happen when the connection is lost when the count passes 20? It’s generally better to do the counting in the PLC, preferably with an interface in Ignition to correct or reset the value.