# Pomodoro Timer for Streamdeck

**URL:** <https://community.folivora.ai/t/pomodoro-timer-for-streamdeck/28814>\
**Category:** Configuration Help & General Discussion\
**Tags:** question, stream-deck\
**Created:** [October 19, 2022, 9:08pm UTC](https://community.folivora.ai/t/pomodoro-timer-for-streamdeck/28814 "2022-10-19T21:08:09Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![Damoeire](https://community.folivora.ai/letter_avatar_proxy/v4/letter/d/96bed5/32.png) [@Damoeire](https://community.folivora.ai/u/Damoeire)\
**Post date:** [November 3, 2022, 8:23pm UTC](https://community.folivora.ai/t/pomodoro-timer-for-streamdeck/28814/21 "2022-11-03T20:23:03Z")

</div>

So I found this:

```auto
function millisToMinutesAndSeconds(millis) {
  var minutes = Math.floor(millis / 60000);
  var seconds = ((millis % 60000) / 1000).toFixed(0);
  return minutes + ":" + (seconds < 10 ? '0' : '') + seconds;
}

millisToMinutesAndSeconds(298999); // "4:59"
millisToMinutesAndSeconds(60999); // "1:01"

```

And thought perhaps I could modify (in the widget area):

```auto
returnToBTT(timeAllowed - timePassed + ' s'); // returning the formatted value to BTT, so it can display it on the button

```

to

```auto
returnToBTT(millisToMinutesAndSeconds(timeAllowed - timePassed));

```

But that didn't work. Is that a function inside a function? Is that allowed? Any ideas from anyone?

---

<div class="post-metadata">

**Author:** ![Andreas\_Hegenberg](https://community.folivora.ai/user_avatar/community.folivora.ai/andreas_hegenberg/32/39221_2.png) [@Andreas\_Hegenberg](https://community.folivora.ai/u/Andreas_Hegenberg)\
**Post date:** [November 3, 2022, 8:38pm UTC](https://community.folivora.ai/t/pomodoro-timer-for-streamdeck/28814/22 "2022-11-03T20:38:38Z")

</div>

To use a function inside a function do it like this:

```auto
let millisToMinutesAndSeconds = (millis) => {
  var minutes = Math.floor(millis / 60000);
  var seconds = ((millis % 60000) / 1000).toFixed(0);
  return minutes + ":" + (seconds < 10 ? '0' : '') + seconds;
}

millisToMinutesAndSeconds(298999);

```

---

<div class="post-metadata">

**Author:** ![Damoeire](https://community.folivora.ai/letter_avatar_proxy/v4/letter/d/96bed5/32.png) [@Damoeire](https://community.folivora.ai/u/Damoeire)\
**Post date:** [November 3, 2022, 9:17pm UTC](https://community.folivora.ai/t/pomodoro-timer-for-streamdeck/28814/23 "2022-11-03T21:17:15Z")

</div>

Many thanks Andreas. Is this what you mean? That doesn't work for me. And when I say it doesn't work, I mean to say, it shows '0:00' on the button. If I change the timeAllowed from 300 to 3000, the counter shows 0:03, which makes me think it's showing minutes rather than seconds. I tried deleting the /1000 in the 'let timePassed =' line, but that didn't help. In a few second, I should know if that's 0:03 is going to move to 0:02. No, I'm sure a minute has passed and it hasn't changed.

Edit: `returnToBTT(millisToMinutesAndSeconds(298999));`  
Is displaying 4:59 as expected.

```auto
(async ()=> {

let timeAllowed = 300; //seconds to count down from
let startTime = await callBTT('get_number_variable', {variable_name:'timer_start_time'}); // the time the timer was started, this is set in the assigned action
let timePassed = Math.round((Date.now()-startTime)/1000); // converting from milliseconds to seconds and rounding

let millisToMinutesAndSeconds = (millis) => {
  var minutes = Math.floor(millis / 60000);
  var seconds = ((millis % 60000) / 1000).toFixed(0);
  return minutes + ":" + (seconds < 10 ? '0' : '') + seconds;
}

returnToBTT(millisToMinutesAndSeconds(timeAllowed - timePassed)); // returning the formatted value to BTT, so it can display it on the button

// If the count down is finished, write some text 
  if (timeAllowed - timePassed < 0) returnToBTT("Time!")
  })();

```

---

<div class="post-metadata">

**Author:** ![Andreas\_Hegenberg](https://community.folivora.ai/user_avatar/community.folivora.ai/andreas_hegenberg/32/39221_2.png) [@Andreas\_Hegenberg](https://community.folivora.ai/u/Andreas_Hegenberg)\
**Post date:** [November 3, 2022, 9:25pm UTC](https://community.folivora.ai/t/pomodoro-timer-for-streamdeck/28814/24 "2022-11-03T21:25:59Z")

</div>

Seems to work for me (just note, timeAllowed and timePassed need to be milliseconds for this function to work:

```auto
(async () => {
  let timeAllowed = 300; //seconds to count down from
  let startTime = await callBTT("get_number_variable", {
    variable_name: "timer_start_time",
  }); // the time the timer was started, this is set in the assigned action
  let timePassed = Math.round((Date.now() - startTime) / 1000); // converting from milliseconds to seconds and rounding

  let millisToMinutesAndSeconds = (millis) => {
    var minutes = Math.floor(millis / 60000);
    var seconds = ((millis % 60000) / 1000).toFixed(0);
    return minutes + ":" + (seconds < 10 ? "0" : "") + seconds;
  };

  if (timeAllowed - timePassed < 0) {
    // If the count down is finished, write some text
    returnToBTT("Time!");
  } else {
    returnToBTT(
      millisToMinutesAndSeconds(timeAllowed * 1000 - timePassed * 1000)
    ); // returning the formatted value to BTT, so it can display it on the button
  }
})();

```

---

<div class="post-metadata">

**Author:** ![Damoeire](https://community.folivora.ai/letter_avatar_proxy/v4/letter/d/96bed5/32.png) [@Damoeire](https://community.folivora.ai/u/Damoeire)\
**Post date:** [November 3, 2022, 9:35pm UTC](https://community.folivora.ai/t/pomodoro-timer-for-streamdeck/28814/25 "2022-11-03T21:35:04Z")

</div>

@Andreas_Hegenberg

It works! I had an idea it was a milli vs secs thing, and was trying to fix it at the let timePassed section.

Awesome. I know have a timer that counts down on the button. I'll see if I can add an alarm, a 2nd push to pause, and long hold to reset, then share.

Cheers!

---

<div class="post-metadata">

**Author:** ![leo](https://community.folivora.ai/letter_avatar_proxy/v4/letter/l/c2a13f/32.png) [@leo](https://community.folivora.ai/u/leo)\
**Post date:** [March 6, 2023, 8:25pm UTC](https://community.folivora.ai/t/pomodoro-timer-for-streamdeck/28814/26 "2023-03-06T20:25:26Z")

</div>

> [@Damoeire](#):
>
> I'll see if I can add an alarm, a 2nd push to pause, and long hold to reset, then share.

Hey,  
I came to this forum to ask something very similar. 🙂  
Were you able to figure this out?

I'm desperately looking for a solution to start and stop a countdown.

---

<div class="post-metadata">

**Author:** ![isaac\_n](https://community.folivora.ai/user_avatar/community.folivora.ai/isaac_n/32/23584_2.png) [@isaac\_n](https://community.folivora.ai/u/isaac_n)\
**Post date:** [March 6, 2023, 8:30pm UTC](https://community.folivora.ai/t/pomodoro-timer-for-streamdeck/28814/27 "2023-03-06T20:30:05Z")

</div>

FWIW, if you're using BTT as a plugin rather than having it completely control the Stream Deck, there's a plugin called Tomato Timer that you could use instead. It's pretty configurable:

![image](https://community.folivora.ai/uploads/default/original/3X/7/e/7e43fe85793ecbddf3d095c9edd6e5ba6b89f656.png)

---

<div class="post-metadata">

**Author:** ![leo](https://community.folivora.ai/letter_avatar_proxy/v4/letter/l/c2a13f/32.png) [@leo](https://community.folivora.ai/u/leo)\
**Post date:** [March 6, 2023, 8:39pm UTC](https://community.folivora.ai/t/pomodoro-timer-for-streamdeck/28814/28 "2023-03-06T20:39:22Z")

</div>

Thank you, I tried that before Andreas implemented Stream Deck support.  
However, I ditched the original software as it was a resource hog and let BTT take over fully.

Maybe it would be possible to use the "Set/Assign Value to Variable" action:  
 ![Screenshot 2023-03-06 at 21.37.07](https://community.folivora.ai/uploads/default/original/3X/6/0/60610fb7343472f0fd3065b27780e18d52844b66.png)

And store a "state" variable like "is\_running", which then can be checked before the script is (re)started.

[Previous page](https://community.folivora.ai/t/pomodoro-timer-for-streamdeck/28814.md?page=1)
