Create a live countdown

Hello,

How to create a live count down? For example, a user will select 20 mins, I want to create a live countdown. I have no idea how to start this hence I am looking for guidance on a solution for this.

The reason I want to do this:
I want to shelve alarms using system.alarm.shelve() and provide the user/operator a live countdown of the alarm for when it will be unshelved automatically

Thank You

1 Like

Hi Raees,

You can create a live countdown by storing the selected duration (e.g., 20 minutes) and the start time (system.date.now()) in custom properties or tags. Then, calculate the remaining time by subtracting the current time from the end time using an expression or script. Use a Perspective Timer component to update the display every second. Bind a label or LED display to show the formatted remaining time as HH:mm: ss. When the countdown hits zero, you can trigger any follow-up action, such as ending the alarm shelf period.

1 Like

It can be done without a timer event, using now(1000) in an expression will make it update every second.

1 Like

Perspective doesn't have a Timer component. Did you mean something else?

Strongly suspect the above user is a bot; would welcome evidence to the contrary.

2 Likes

I was thinking that too. But some comment history looks more legit than others.

I flagged one a little while ago for obvious spam.

Gee, some think that I'm a bot, but even I didn't recognise it as one.
Maybe I'm not?
New era philosophy: "I think, therefore I (sp)am."

1 Like

Maybe you were programmed to think you aren't a bot? :face_with_hand_over_mouth:

Not sure if you found your solution or not, but here is one I did awhile back when I was testing something similar to this.

I put this in my Gateway Script

tagPath = '[Temp]Countdown'
currentValue = system.tag.readBlocking('[Temp]Countdown')[0].value

if currentValue > 0:
	system.tag.writeBlocking([tagPath], [currentValue - 1])

Then made a Memory Tag with the data type set to Integer. Hope this helps.

I'd make 2 tags:

  1. a datetime memory tag with the target (the 0)
  2. an integer derived (or expression ?) tag that would use now(1000) and dateDiff to calculate the number of seconds between now and the target. You can always reprocess that integer to show hours, minutes and whatnot for display purposes
1 Like

You should definitely use tags for this as @pascal.fragnoud mentions, not a timer event script. Tags are far simpler to configure and add to, but more importantly, are more efficient and performant as well