How to make a 15 minute timer in KWGT?

Hi everyone, I want to create a widget in KWGT that works as a 15-minute timer. The idea is that it starts by showing “15:00” with a button next to it. When I press the button, it should start counting down to “00:00” and then reset back to “15:00,” waiting for me to press the button again to start over.

The problem is that I have no idea where to start. Could someone guide me on what functions or formulas I should use?

Thanks!

$tu()$ function might be more useful for timer related stuff however you could also do that with some creative thinking with triggering flow and reducing the second number by 1 every 1 second by using cron trigger(just an idea not sure if could be done using flow).
some helpful links

honestly you can almost find most of kustom related tutorials in brandon craft’s yt channel. and with some idea of your own gets you awesome kreations. :slight_smile:

1 Like

Thank you very much bro this is very helpful :pray:

Hi there,

To create a timer functionality, I would suggest you to create a live wallpaper inKLWP instead of a widget in KWGT. The reason is KWGT will not update the timer every second.

Here’s an example of the Kustom script for a timer functionality.

  1. Create a global variable for the trigger switch, name it: Button
  2. Create a global variable for the starting minute. Name it dMin and set its value to a minute number (ie. 15)
  3. Create a global variable for the starting second. Name it dSec and set its value to 59.
  4. Create a Text element and set its value to the Kustom script below.
  5. Add a touch action to the Text element, select Toggle Global Switch action type, then select the Button variable from the selection.

KUSTOM SCRIPT

$
lv(theMin,
if(gv(button)=0,gv(dmin),#theMin)
)
$$
lv(theSec,
if(gv(button)=0,gv(dsec),#theSec)
)
$$
lv(theSec,if(gv(button)=1,
gv(dsec)-tu(seq,1/60,0,gv(dsec))
))
$$
lv(theMin,if(gv(button)=1,
if(#theSec=gv(dsec),#theMin-1,#theMin)
))
$$
lv(theMin,if(gv(button)=1,
if(#theMin<0,gv(dmin),#theMin)
))
$$
if(#theMin<10,"0","")
$$
if(gv(button)=0,0,#theMin)+":"
$$
if(#theSec<10,"0","")
$$
if(gv(button)=0,0,#theSec)
$

PREVIEW

Timer Preview


I hope this would help.
:smiling_face::+1:

2 Likes

Thanks bro, I really didn’t know the problem with the seconds in kwgt, it’s very helpful.