[APP][Pro] Chronograph - Adds precise timer, stopwatch and transition functionality to Homey

The used homeyscript flowcards can only return one local tag atm. You’ll have to make a request at Athom’s for adding an additional tag to those homeyscript flowcards.

But, we can use HomeyScript tags as extra step, but these tags are global, so I suggest using the stopwatch/timer name as tag name. You can add multiple HS tags of course if needed.

// Convert milliSeconds to HH:MM:SS as result, and to HH:MM as tag
//
// ENTER STOPWATCH or TIMERNAME
let timerName = "YourTimerNameHere"
// END OF USER INPUT

// -> argument: input in milliseconds
let milliseconds = args[0]
let seconds = milliseconds / 1000;

if (seconds == '' || seconds == undefined) {
    console.log ('Missing argument');
    return(false);
} else {
  d = seconds;
  var h = Math.floor(d / 3600);
  var m = Math.floor(d % 3600 / 60);
  var s = Math.floor(d % 3600 % 60);
}

  // Show as 'HH:MM'
  var clock_hhmm = ('0' + h).slice(-2) + ":" + ('0' + m).slice(-2);
  // Show as 'HH:MM:SS'
  var clock_hhmmss = ('0' + h).slice(-2) + ":" + ('0' + m).slice(-2) + ":" + ('0' + s).slice(-2);

  // Create homeyscript string tag for clock_hhmm
  timerName = timerName + '_clock_hhmm'
  await tag(timerName, clock_hhmm);
  
// just for checks
console.log(clock_hhmm);
//console.log(clock_hhmmss);

return(clock_hhmmss);

I used ‘Koelkastinterval’ as timerName, and you can see the Homeyscript tag is created and available to use in other cards

1 Like

You could return a JSON string with as many results as you want, and parse them afterwards.

2 Likes

@Peter_Kawa Nice, thanks. By modifying your example I can actually output both strings as global variables as well. :pray:

Thank you. I do not know how that can be done, it would be interesting to see, but if it would require more flow cards to parse the JSON string it’s less desirable.

2 Likes

With the JSON handler app, you would only need one flowcard after each HS card, because you can read multiple json properties within one flowcard:

2 Likes

Thanks Arie, (and Anders for the idea).
It still took me a while to get it going with script vars :sweat_smile:

@Rrrr
The script end part now like this, I made a JSON with the available clock values

  // Show time as 'HH:MM'
  var hh_mm = ('0' + h).slice(-2) + ":" + ('0' + m).slice(-2);
  // Show time as 'HH:MM:SS'
  var hh_mm_ss = ('0' + h).slice(-2) + ":" + ('0' + m).slice(-2) + ":" + ('0' + s).slice(-2);

return(JSON.stringify({'hh_mm_ss':hh_mm_ss, 'hh_mm':hh_mm}));

The flow looks like this, the build in logic cards can parse JSON as well, so use what you like.

3 Likes

@Peter_Kawa This does not work for me: the Homeyscript string variables (tags) are not being created, or if I create them, they are not being filled. Any tip?

1 Like

Did you enter a timername on line #4?
Say you entered a timername like, ‘fridge’.
Then a Homeyscript tag should be created named ‘fridge_clock_hhmm’
Just to be clear, the build-in Logic variables has nothing to do with this:

1 Like

Found it (note that double quotes are required, like in your initial example:
let timerName = “YourTimerNameHere”). I looked in the wrong place by checking under Variables (Logic variables). I guess that the global variables can only be found within a flow card? How do I remove a global variable?
image

1 Like

@Peter_Kawa

In test and review now:

Duration and Elapsed (if applicable) tags are now available as HH:mm:ss and mm:ss.

image

image

3 Likes

That’s fast!

Comment: As one cannot know the elapsed duration in advance, leaving out the HH feels not right. Usually I would need either HH:MM:SS or HH:MM when seconds do not matter.
image

Testing now…[deleted] the results are good, so all good!
image

1 Like

Okay, one moment…

Where?

And, next version is in test now: extra cards with Hours (short): HH:mm.

2 Likes

Looking good, Arie!

1 Like

Update 1.5.1

  • Bugfixed from old and new Crash reports.
  • Added a Round Of for GetDuration tags.
    This can be configured in the app settings:
    image
    image
1 Like

After the last update I get this error: “Elapsed is not defined” on get elapsed card
image

1 Like

Okay, the fix for this is live: 1.5.2

2 Likes

New error
image

1 Like

Weird, i understand why the error is there, i just cannot replicate the issue on old or new homey…

Solving it tho.

Update to 1.5.3?
And lett me know if it works now, because i personally do not get the error message you get.
Altho i did respond the results as text, which is now fixed to Number again.

Meaning also, f.i. if time is 0.40 hour, it is now a correct number again with 0.4 (missing the trailing 0).