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?
Creating a timer
Moderator: Martin
Re: Creating a timer
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
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