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

**URL:** <https://forum.inductiveautomation.com/t/how-do-i-get-a-gateway-script-to-run-every-hour/25909>\
**Category:** Ignition\
**Created:** [June 18, 2019, 2:39pm UTC](https://forum.inductiveautomation.com/t/how-do-i-get-a-gateway-script-to-run-every-hour/25909 "2019-06-18T14:39:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwkidd](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@cwkidd](https://forum.inductiveautomation.com/u/cwkidd)\
**Post date:** [June 18, 2019, 2:39pm UTC](https://forum.inductiveautomation.com/t/how-do-i-get-a-gateway-script-to-run-every-hour/25909/1 "2019-06-18T14:39:54Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jlivingston](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@jlivingston](https://forum.inductiveautomation.com/u/jlivingston)\
**Post date:** [June 18, 2019, 2:49pm UTC](https://forum.inductiveautomation.com/t/how-do-i-get-a-gateway-script-to-run-every-hour/25909/2 "2019-06-18T14:49:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [June 18, 2019, 3:24pm UTC](https://forum.inductiveautomation.com/t/how-do-i-get-a-gateway-script-to-run-every-hour/25909/4 "2019-06-18T15:24:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cwkidd](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@cwkidd](https://forum.inductiveautomation.com/u/cwkidd)\
**Post date:** [June 18, 2019, 5:44pm UTC](https://forum.inductiveautomation.com/t/how-do-i-get-a-gateway-script-to-run-every-hour/25909/5 "2019-06-18T17:44:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [June 18, 2019, 5:49pm UTC](https://forum.inductiveautomation.com/t/how-do-i-get-a-gateway-script-to-run-every-hour/25909/6 "2019-06-18T17:49:53Z")

</div>

read timer scripts [Timer Scripts Video at Inductive University](https://www.inductiveuniversity.com/videos/timer-scripts/7.9)  
hopefully it solves your problem.

---

<div class="post-metadata">

**Author:** ![Tim](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim/32/3361_2.png) [@Tim](https://forum.inductiveautomation.com/u/Tim)\
**Post date:** [June 19, 2019, 6:36pm UTC](https://forum.inductiveautomation.com/t/how-do-i-get-a-gateway-script-to-run-every-hour/25909/7 "2019-06-19T18:36:20Z")

</div>

Take a look at this post.

> [@Gateway Script Only at 4pm](http://forum.inductiveautomation.com/t/gateway-script-only-at-4pm/19979):
>
> How can I set up a gateway script to run once at 4pm everyday? I want to write a value to a single tag at this time. thanks

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 19, 2019, 7:36pm UTC](https://forum.inductiveautomation.com/t/how-do-i-get-a-gateway-script-to-run-every-hour/25909/8 "2019-06-19T19:36:06Z")

</div>

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.

```auto
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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [June 21, 2019, 6:27am UTC](https://forum.inductiveautomation.com/t/how-do-i-get-a-gateway-script-to-run-every-hour/25909/9 "2019-06-21T06:27:18Z")

</div>

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.
