Creating a timer

Post your questions and help other users.

Moderator: Martin

Post Reply
Taku22
Posts: 7
Joined: 23 Jun 2013 20:00

Creating a timer

Post by Taku22 » 23 Oct 2013 13:59

http://automagic4android.com/flow.php?i ... 7e32420cb8

I'm trying to create a timer so when I tap a shortcut it asks how long, then waits that long before setting off an alarm. what is stumping me is how to check how much longer before the alarm goes off. can anyone help check my script-work?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Creating a timer

Post by Martin » 24 Oct 2013 17:09

Hi,

You could first calculate the end time and store it in a variable (directly after the input dialog):
1. -action Script: end=getDate()+getDurationMillis(value)

then use an action to calculate the remaining time:
2. -action Script: remaining=end-getDate()

show the notification (divide and multiply by 1000 to strip off the milliseconds):
3. -action Notification on Screen: {getDurationString(remaining/1000*1000)} remaining

sleep some seconds:
4. -action Sleep: 5s

check if the time is elapsed:
5. -condition Expression: ramaining>0
--> true: connection back to 2.
--> false: -action Play Sound


You could also split it into two flows without a loop:
Flow Timer:
-trigger Shortcut
-action Action Input Dialog
-action Script: global_timer_end=getDate()+getDurationMillis(value)
-action Set Flow State: Enable Reminder
-action Sleep: {value}
-action Play Sound

Flow Reminder:
-trigger Periodic Timer: every 5s
-condition Expression: triggertime>global_timer_end
-->true: -action Set Flow State: Disable Reminder
-->false: -action Notification on Screen: {getDurationString(global_timer_end-triggertime)} remaining


Regards,
Martin

Taku22
Posts: 7
Joined: 23 Jun 2013 20:00

Re: Creating a timer

Post by Taku22 » 25 Oct 2013 02:56

Works great, thanks.

Post Reply