How do I prevent a tag change script from executing when a project is saved?

I have tag change scripts that are emitting MQTT messages when their values change (not quality, not timestamp). When I save the project holding the Gateway Tag Change Scripts, it seems to trigger this script for evey tag path that is being triggered. This is dealbreaking behavior, I have to make this not happen. Does anyone know how to prevent this behavior? The value of these tags are not changing when I save the script. I think the system does something like preloads its tag value cache to None or Null or whatever and then goes through an update phase, but I can't prove it.

Typically, this is prevented by adding

if not initialChange:
    ...
1 Like

Thanks, I was trying

if executionCount <= 1:
    pass

which was not working. I totally missed that line above it in the documentation!

1 Like

It is important that you actually handle the initialChange case for something like this, as that initial change CAN be a new value. There is a small window during scripting restart where a real change can be dropped into the void, along with the obviously larger time windows involving project enable/disable and actual gateway restarts.

For really critical systems, you need to maintain your own persistence mechanism (database, external files, whatever) tracking the origins, values, and timestamps that you have actually passed on to the next system.

1 Like

I am using this system for emitting requests for external information or action -- in this particular case I'd rather nothing was sent than something was erroneously sent. There shouldn't be a circumstance where when the project is reloaded that I want anything to be emitted.