How do I Get a Gateway Script to Run Every Hour?

Hello! I’m trying to get the following code to run every hour…I’m fairly inexperienced with coding and need some solid help:

if hour==01 and minute==45:
seed=system.opc.readValue(server,path).value
system.tag.write("[default]testTag", seed)
elif hour==22 and minute==45:
current=system.tag.read(path).value
current=system.opc.readValue(server,path).value
past=system.tag.read(“testTag”).value
diff=current-past
system.tag.write(“Difference”,diff)

This code works, and it writes when I need it to…but for some troubleshooting purposes, I would like to get it to write every hour. Any help would be great!

There may be some hints for you in the Enterprise Administration Module lesson on Configuring Controllers and Agents part Agent Task Scheduling. While I am just learning, I think that the business of “CRONTAB”-style ( As in from Unix or Linux type system ) time is best explained in that lesson. Just a reminder, the EAM is an Optional Module, therefore “Your mileage from this may vary” abbreviated YMMV. I hope that helps.

You could setup a gateway timer script to run every 24 hours.

Well, the issues is the way I have it set up currently (I think). Currently, I have the Gateway script set up to run at two specified times a day, as you can see from the script even though it’s a bit jumbled. The gateway script is set to check every hour, but the way I have it set now–and I’m not sure if it works–is to have the:

if hour==(0-23)
elif hour==(0-23)

I’m not entirely sure that will work at all ha.

Also, I didn’t copy some of the variable definitions to keep things a bit cleaner.

read timer scripts https://www.inductiveuniversity.com/videos/timer-scripts/7.9
hopefully it solves your problem.

Take a look at this post.

If you put your script in as preformatted text by using ``` before and after the script it will be a little more readable for everyone.

if hour==01 and minute==45:
    seed=system.opc.readValue(server,path).value
    system.tag.write("[default]testTag", seed)
elif hour==22 and minute==45:
    current=system.tag.read(path).value
    current=system.opc.readValue(server,path).value
    past=system.tag.read(“testTag”).value
    diff=current-past
    system.tag.write(“Difference”,diff)

I’m not sure where exactly you’re getting the hour and minute from the script you posted, however, if the Gateway Script is configured to run every hour, then all you need to do is change your script so that instead of filtering for 2 distinct times in a day you filter for two distinct times in an hour, and change the script configuration to run every minute.

if minute==15:
    seed=system.opc.readValue(server,path).value
    system.tag.write("[default]testTag", seed)
elif minute==45:
    current=system.tag.read(path).value
    current=system.opc.readValue(server,path).value
    past=system.tag.read(“testTag”).value
    diff=current-past
    system.tag.write(“Difference”,diff)

Also, not certain what exactly you are testing but you could also just run the code from the script console to test and then you can do it as often as needed.

1 Like

Are you trying to run this script as a gateway script every hour, or are you wanting to run a script on the gateway every hour? For the latter, I would create an expression tag that triggers at the respective times, and put the script as a tag change event script.

1 Like