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.
(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!")
})();
Seems to work for me (just note, timeAllowed and timePassed need to be milliseconds for this function to work:
(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
}
})();
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:
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:
And store a "state" variable like "is_running", which then can be checked before the script is (re)started.