Best way to have a timer counter tag

What is the best way to have a timer tag.
Currently I'm having like an expression tag with exp : 'getSecond(now())'
There's a tag change script on the expression tag which first reads the existing value of a memory tag and then increments it by one.
But there are times where missed events are encountered, so which doesnot increments the counter tag every one sec.
Any alternate way to have a counter tag ?

Instead of a memory tag, you might consider using secondsBetween(date1, now()) with a date1 value set to indicate a count of 0.

2 Likes

Building on this, use a tag to store the future datetime if using a timer with a preset span OR the start datetime if using an accumulating timer with no set end. Then use ryan_deardoff's method, using your timestamp tag for one of the date values.

Is the NOW() function impacted by DST? If so, is there a better function to use?

The tag change script is getting triggered every second, and the execution of script written on it is getting completed in ms, so how can there be any missed event? still wondering on this?

Some other tag valueChange events are breaking the rules and tying up the thread pool.

Thanks!
Opened a ticket with support to better troubleshoot this.
But if there is a good post/resource that delves into subject matter, appreciate a link.