# Timer Using Now()

**URL:** <https://forum.inductiveautomation.com/t/timer-using-now/100509>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [January 6, 2025, 10:32pm UTC](https://forum.inductiveautomation.com/t/timer-using-now/100509 "2025-01-06T22:32:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liam\_Dietrich](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@Liam\_Dietrich](https://forum.inductiveautomation.com/u/Liam_Dietrich)\
**Post date:** [January 6, 2025, 10:32pm UTC](https://forum.inductiveautomation.com/t/timer-using-now/100509/1 "2025-01-06T22:32:18Z")

</div>

Goal: Use the `now()` expression function to get the current time and repeat every 5 seconds.  
Ex. now, now+5s, now+10s... etc.

Issue: Using `now(5000)` does not run instantly, rather waits 5 seconds as it is intended to.  
Ex. now+5s, now+10s, now+15s

Are there any easy suggestions to get around this issue?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 6, 2025, 11:03pm UTC](https://forum.inductiveautomation.com/t/timer-using-now/100509/2 "2025-01-06T23:03:04Z")

</div>

This is a little strange. Can you explain what is the real problem you are trying to solve?

---

<div class="post-metadata">

**Author:** ![Liam\_Dietrich](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@Liam\_Dietrich](https://forum.inductiveautomation.com/u/Liam_Dietrich)\
**Post date:** [January 6, 2025, 11:30pm UTC](https://forum.inductiveautomation.com/t/timer-using-now/100509/3 "2025-01-06T23:30:02Z")

</div>

I need data on a popup to refresh every 5 seconds and do not want the wrong information showing for the first 5 seconds the popup is open.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [January 6, 2025, 11:36pm UTC](https://forum.inductiveautomation.com/t/timer-using-now/100509/4 "2025-01-06T23:36:22Z")

</div>

What data do you have on this popup? Just a timer? A table of data? How are you getting the data to this popup?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 6, 2025, 11:40pm UTC](https://forum.inductiveautomation.com/t/timer-using-now/100509/5 "2025-01-06T23:40:51Z")

</div>

- In Project Browser, select the root of your popup view.
- In Perspective Property Editor scroll down to CUSTOM.
- Create a new custom property `startTime`.
  - Create an expression binding on `startTime` with the expression, `now(0)`. This will fire once when the popup opens and save the current timestamp in the custom property.

- Create a second tag, `timeout`.
  - Add an expression binding,  
`(now(1000) - {this.custom.startTime}) > 5000`  
This will evaluate every 1000 ms and will return `true` when the popup has been open for 5000 ms.

- Right-click on `custom.timeout` and select Edit Change Script. Add the script,

```python
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if currentValue.value:
		self.custom.timerStart = system.date.now()

```

This will update `timerStart` resetting `timeout` allowing the sequence to repeat.

---

<div class="post-metadata">

**Author:** ![bwirth](https://avatars.discourse-cdn.com/v4/letter/b/41988e/32.png) [@bwirth](https://forum.inductiveautomation.com/u/bwirth)\
**Post date:** [January 7, 2025, 12:14am UTC](https://forum.inductiveautomation.com/t/timer-using-now/100509/6 "2025-01-07T00:14:00Z")

</div>

Or you could use an expression structure binding with one of the expressions being your timer. ( now(5000) ).

---

<div class="post-metadata">

**Author:** ![Liam\_Dietrich](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@Liam\_Dietrich](https://forum.inductiveautomation.com/u/Liam_Dietrich)\
**Post date:** [January 7, 2025, 3:19pm UTC](https://forum.inductiveautomation.com/t/timer-using-now/100509/7 "2025-01-07T15:19:33Z")

</div>

Thanks Transistor and bwirth for the responses.

This seemed to be the simplest solution:  
Use an expression structure binding with two parameters, one set to `now(0)` and the other `now(5000)`. Ensure to set 'Wait On All' to False on the binding.  
Then add an expression transform...

```python
if(
	{value}['time'] - {value}['startTime'] < 5000, 
	{value}['startTime'], 
	{value}['time']
)

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 7, 2025, 3:53pm UTC](https://forum.inductiveautomation.com/t/timer-using-now/100509/8 "2025-01-07T15:53:15Z")

</div>

how about `toDate(max(now(0), now(5000)))` ?

note that in my tests, `now(5000)` does give a value immediately, so I get the same results:  
t0, t0+5, t0+10, etc...
