# Gateway Script Only at 4pm

**URL:** <https://forum.inductiveautomation.com/t/gateway-script-only-at-4pm/19979>\
**Category:** Ignition\
**Created:** [October 4, 2018, 12:43pm UTC](https://forum.inductiveautomation.com/t/gateway-script-only-at-4pm/19979 "2018-10-04T12:43:15Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 5, 2018, 3:51pm UTC](https://forum.inductiveautomation.com/t/gateway-script-only-at-4pm/19979/8 "2018-10-05T15:51:50Z")

</div>

> [@Tim](#):
>
> if curTime == '16:00:00'

Bad. If the gateway experiences any heavy load at 4pm, this expression can miss the event. Especially if using fixed delay. If using fixed period, and the event that normally falls a 3:59:59 is slightly delayed, this can fire twice in a row. The chance is low, so you wouldn't be likely to see either problem often, but it **would** happen.

I would use something like this in a project script module:

```auto
from java.util import Date
lastTrigPath = '[default]some/path/to/datetime/tag'

# Simple function to convert any timestamp to the trigger point on the same day
def truncateToTrigger(ts):
	return Date(ts.year, ts.month, ts.date, 16, 0, 0)

# Check if time to run the triggered event. Call from timer script
def checkTrigger():
	last = system.tag.read(lastTrigPath).value
	nextTrig = truncateToTrigger(last)
	if nextTrig.time < last.time:
		nextTrig = system.date.addDays(nextTrig, 1)
	now = Date()
	if nextTrig.time <= now.time:
		system.tag.write(lastTrigPath, now)
		# Do the trigger stuff here

```

Call `project.something.checkTrigger()` from a gateway timer script of the desired precision. It will not double fire, and will always fire if the event is late. Even if it's late due to a gateway reboot.

---

_[View the full topic](https://forum.inductiveautomation.com/t/gateway-script-only-at-4pm/19979)._
