Page 1 of 2

Use Timer

Posted: 30 Aug 2013 11:59
by ahmadmll
Hi my friends
I want to create a flow to calculate my use time of my phone.
Start by screen on and stop screen off and repeat it.
Can you help me????

Re: Use Timer

Posted: 02 Sep 2013 08:52
by ahmadmll
Is not there way for timer action?
Users ,please try!
I need it.

Re: Use Timer

Posted: 02 Sep 2013 10:45
by MURTUMA
PLease try to read the documentation. in the catalog there is an example flow of how to work with gleeo. With screen on and screen off trigger and that example you can easily archieve what you're requesting.

Re: Use Timer

Posted: 02 Sep 2013 16:00
by Martin
Hi,

Here is one possible solution using global variables.

Create a global variable global_usage_duration with type Number and a value of 0 (menu->Manage->Global variables, Add) to collect the total duration when the device was in use.
Create a second global variable global_turned_on with type Date initialized to the current time. This variable will contain the time the display has been turned on.

The following flows will add the duration the display has been turned on to the variable global_usage_duration:

Flow1 (to remember when the display has been turned on)
-trigger Display State: On
-action Script: global_turned_on = triggertime

Flow2 (to add the duration to the global variable)
-trigger Display State: Off
-action Script: duration = triggertime - global_turned_on;
global_usage_duration = global_usage_duration + duration


Flow3 (to reset the duration at midnight)
-trigger Time: everyday 00:00
-action Script: global_usage_duration = 0

Regards,
Martin

Re: Use Timer

Posted: 03 Sep 2013 15:45
by ahmadmll
Hi Martin
Thank you for your try for my need.
I create that three flows:
http://automagic4android.com/flow.php?i ... d630ec302d
But itgive me a number on "global_usage_duration" that is unknown its unit.
Please guide me.

Re: Use Timer

Posted: 03 Sep 2013 17:33
by Martin
Hi,

The unit of time for dates is milliseconds.
You can use a small inline expression in the script to format the duration to something more readable:
{global_usage_duration/1000} to show the duration in seconds as a plain number
{getDurationString(global_usage_duration)} to show the duration like 2h 5m 14s 123ms
{getDurationString(global_usage_duration/1000*1000)} to show the duration without milliseconds
{getDurationString(global_usage_duration/60000*60000)} to show the duration without seconds

Regards,
Martin

Re: Use Timer

Posted: 04 Sep 2013 07:13
by ahmadmll
Thank very well,Martin.
I love u. -^*^-
Just i want to insert ":" between numbers.
Is it possible?
Excuse me .

Re: Use Timer

Posted: 04 Sep 2013 16:53
by Martin
It's not possible directly. You can use a script to directly store the formatted value in a global variable and show the global variable instead.
Something like this (directly in the script after incrementing global_usage_duration, untested):
mph=1000*60*60;//millis per hour
hours = global_usage_duration/mph;
minutes = (global_usage_duration%mph)/60000;
global_formatted_duration=hours+":"+minutes;

Re: Use Timer

Posted: 05 Sep 2013 02:17
by ahmadmll
Martin,your suggested usage timer is a timer not usage timer.
I turned off my phone at 12:00am and turn it on at 6:00 am, "get duration string(global_usage_duration)" is 11h 36m
What's problem?
Please solve it!!!!

Re: Use Timer

Posted: 06 Sep 2013 13:29
by Martin
Hi,

Sorry, I don't understand. Can you describe the problem in more detail?

-Did you manually shut the device down or just turn the screen off? In the shutdown case, the screen is probably still turned on when Automagic is terminated so it won't execute the screen off flow. You could add a trigger Shutdown to mitigate the problem.
-Did you reset the variable global_usage_duration to zero at midnight? You also have to set variable global_turned_on to triggertime at midnight when the screen is on, otherwise the duration before midnight is counted again when the screen is turned off.

Regards,
Martin