Gateway Timer Event Script Help

I have a script that I would like to run at a predefined time (2am every morning). Looking through documentation, this sounds like I would want to use a Gateway Timer Event Script with a fixed rate. I can’t seem to find a good example for how to set this up. Would someone be able to help provide me an example of how to set this up? Where do I define the fixed rate? How do I define initial start? Does this need to be defined in the script somehow?

Timer Settings

You are better off using a Gateway Tag Event Script.

Set up an expression tag to trigger at your desired time

getHour24(now()) = 2

Then subscribe the tag to the Tag Change Event.

Be sure to add a filter to the script so it only runs once.

if not initialChange and newValue:
    #your script here

Blegh. No. Gateway timers have numerous advantages. Slightly different context in this post, but most of these are relevant:

@pturmel I appreciate the feedback. Based on your feedback, are you able to help with the my original questions? I wasn’t able to find the answers to my questions in the post you added. Thanks!

How soon/precise does it need to be after 2am? Pick a delay value that will check often enough. Use a datetime memory tag to hold the time of last full execution. The event script would then be something like this:

lastTS = system.tag.read("[default]path/to/timestamp/tag").value
currentTS = system.date.now()
today2am = system.date.setTime(currentTS, 2, 0, 0)

if currentTS.after(today2am) and lastTS.before(today2am):
	system.tag.write("[default]path/to/timestamp/tag", currentTS)
	#
	# Do the rest of your 2am script here
	#

Note that you don’t have to check initialChange with this algorithm, and it will automatically “catch up” if the server is disrupted/down when it would otherwise run.

3 Likes

hmmm…hadn’t thought of that.

Today can be checked as successful as I have been schooled by @pturmel :rofl: :rofl: