There are two special functions that scripted automation (nothing to do with the helper libraries) checks to see if they exist in your script when it loads (scriptLoaded) and unloads (scriptUnloaded). You can use the latter to clean up after your script, such as cancelling timers. There is an example in the documentation (and another for scriptLoaded), but I have an update coming with a little more detail.
In case you haven’t seen this yet, you may want to take a look through this example, since it is very similar to what you have implemented in your DSL rule…