Use Timer

Post your questions and help other users.

Moderator: Martin

ahmadmll
Posts: 69
Joined: 06 Jul 2013 15:02

Use Timer

Post by ahmadmll » 30 Aug 2013 11:59

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????

ahmadmll
Posts: 69
Joined: 06 Jul 2013 15:02

Re: Use Timer

Post by ahmadmll » 02 Sep 2013 08:52

Is not there way for timer action?
Users ,please try!
I need it.

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: Use Timer

Post by MURTUMA » 02 Sep 2013 10:45

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.

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

Re: Use Timer

Post by Martin » 02 Sep 2013 16:00

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

ahmadmll
Posts: 69
Joined: 06 Jul 2013 15:02

Re: Use Timer

Post by ahmadmll » 03 Sep 2013 15:45

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.
Attachments
Screenshot_2013-09-03-20-02-55.png
Widget setting picture that show value
Screenshot_2013-09-03-20-02-55.png (159.69 KiB) Viewed 22959 times

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

Re: Use Timer

Post by Martin » 03 Sep 2013 17:33

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

ahmadmll
Posts: 69
Joined: 06 Jul 2013 15:02

Re: Use Timer

Post by ahmadmll » 04 Sep 2013 07:13

Thank very well,Martin.
I love u. -^*^-
Just i want to insert ":" between numbers.
Is it possible?
Excuse me .

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

Re: Use Timer

Post by Martin » 04 Sep 2013 16:53

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;

ahmadmll
Posts: 69
Joined: 06 Jul 2013 15:02

Re: Use Timer

Post by ahmadmll » 05 Sep 2013 02:17

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!!!!

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

Re: Use Timer

Post by Martin » 06 Sep 2013 13:29

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

Post Reply