Trigger a macro every n hours

hendis

Member
Basically, title says it all. I need to perform an action every n hours. It doesn't matter to me if the macro triggers every n hours, or if the macro triggers every hour but there is logic in the macro to perform an action every n hours.

Anyhow, this is a simple problem that I don't know how to solve. Does anybody have any ideas?
 

Qarboz

Well-known member
Basically, title says it all. I need to perform an action every n hours. It doesn't matter to me if the macro triggers every n hours, or if the macro triggers every hour but there is logic in the macro to perform an action every n hours.

Anyhow, this is a simple problem that I don't know how to solve. Does anybody have any ideas?
If n doesn't change you can use the "Regular interval" trigger

Otherwise you need to be more detailed what n corresponds to
 
If the Regular Interval trigger won't do, consider creating a stopwatch.

T: Stopwatch value > n hours

A: reset & restart stopwatch
 

Abalsam

Active member
If the Regular Interval trigger won't do, consider creating a stopwatch.

T: Stopwatch value > n hours

A: reset & restart stopwatch
The stopwatch has a limitation that if macrodroid is reset the stopwatch does not restart or resume. This means that your macro would need to take that into account or it may fail to run as expected if macrodroid resets.
 

Abalsam

Active member
The stopwatch has a limitation that if macrodroid is reset the stopwatch does not restart or resume. This means that your macro would need to take that into account or it may fail to run as expected if macrodroid resets.
Back in January, I actually put together and shared a proof of concept macro to ensure a stopwatch would resume and trigger as expected after a macrodroid reset. You can find the thread here.
Thread 'Test macro to ensure stopwatch trigger persistence' http://www.macrodroidforum.com/inde...to-ensure-stopwatch-trigger-persistence.1771/
 
What do you guys mean about resetting MacroDroid?

As in disable and reenable?

Or uninstall & reinstall? (This, I realize, changes your Android's MD webhook.)

Or do you mean something else?
 

Abalsam

Active member
What do you guys mean about resetting MacroDroid?

As in disable and reenable?

Or uninstall & reinstall? (This, I realize, changes your Android's MD webhook.)

Or do you mean something else?
Android occasionally kills processes and if the process is a service, it automatically restarts. That is what I meant by MacroDroid restarting (ie doing what it is supposed to do when the os stops it).
 
Specifically, what are you looking to do based on the system time?
I was considering an exercise/experiment/challenge to get stopwatch functionality with system timestamp variables. Save what system time it is whenever a trigger is fired that you might use to start and stop a stopwatch. Subtract smaller from larger and run expressions to convert & display as hh:mm:ss.

That'd be the time that's passed between two stamps. There might even be a way to make it work when you regret not having started a stopwatch at a specific time.

If that's feasible, it would serve as a workaround for this thing about MacroDroid resetting.

I understand that, by the way, and it makes sense. Just a bit surprised since my stopwatches show my neglect to, um, stop them.

On the oldest Android device I've got that I still put to regular use, I set up macros & stopwatches to time how long screen's off & on, charging & discharging. I just never got around to auto-resetting them or storing the lengths. My "screen off" timer now says over 1,893 hours and "discharge time" is over 2,021 hours.

If it's normal for MacroDroid to auto-reset from time to time, including stopwatches, I just wonder why mine tend to run so long. First guess is I should check the OS.
 

Dm114

Well-known member
I was considering an exercise/experiment/challenge to get stopwatch functionality with system timestamp variables. Save what system time it is whenever a trigger is fired that you might use to start and stop a stopwatch. Subtract smaller from larger and run expressions to convert & display as hh:mm:ss.

That'd be the time that's passed between two stamps. There might even be a way to make it work when you regret not having started a stopwatch at a specific time.

If that's feasible, it would serve as a workaround for this thing about MacroDroid resetting.

I understand that, by the way, and it makes sense. Just a bit surprised since my stopwatches show my neglect to, um, stop them.

On the oldest Android device I've got that I still put to regular use, I set up macros & stopwatches to time how long screen's off & on, charging & discharging. I just never got around to auto-resetting them or storing the lengths. My "screen off" timer now says over 1,893 hours and "discharge time" is over 2,021 hours.

If it's normal for MacroDroid to auto-reset from time to time, including stopwatches, I just wonder why mine tend to run so long. First guess is I should check the OS.
Sorry but I don't really understand why you want to use stopwatches. Why wouldn't you use local variables (1 per activity you want to follow) this way:
T1: Trigger when Activity1 begins
T2: Trigger when Activity1 stops
T3: Trigger when Activity2 begins
T1: Trigger when Activity2 stops
A: If T1 fires Then StartTime1=[system_time]
A: Else If T2 fires Then Elapsed1=Elapsed1+[system_time]-StartTime1
A: If T3 fires Then StartTime2=[system_time] A: Else If T4 fires Then Elapsed2=Elapsed2+[system_time]-StartTime2
A: End If

Then, the rest of your macro would convert elapsed time from seconds to hours:minutes:seconds for every activity.
 

Abalsam

Active member
I was considering an exercise/experiment/challenge to get stopwatch functionality with system timestamp variables. Save what system time it is whenever a trigger is fired that you might use to start and stop a stopwatch. Subtract smaller from larger and run expressions to convert & display as hh:mm:ss.

That'd be the time that's passed between two stamps. There might even be a way to make it work when you regret not having started a stopwatch at a specific time.

If that's feasible, it would serve as a workaround for this thing about MacroDroid resetting.

I understand that, by the way, and it makes sense. Just a bit surprised since my stopwatches show my neglect to, um, stop them.

On the oldest Android device I've got that I still put to regular use, I set up macros & stopwatches to time how long screen's off & on, charging & discharging. I just never got around to auto-resetting them or storing the lengths. My "screen off" timer now says over 1,893 hours and "discharge time" is over 2,021 hours.

If it's normal for MacroDroid to auto-reset from time to time, including stopwatches, I just wonder why mine tend to run so long. First guess is I should check the OS.

First I have stopwatch timers running almost daily without noticing things taking longer than they should.

Second what I do before starting a stopwatch to ensure I can restart it if macrodroid resets is this:
1 I save the current system time to a variable.
2 I add to that variable the amount of time in seconds the stopwatch is to run before triggering.
3 I set a trigger in the macro for macrodroid initialized (to catch the os restarting macrodroid).

I then do the following steps if the macro is triggered when macrodroid initializes:
1 I compare the time the stopwatch is set to trigger (set in step 2 above) with the current system time and also check if the stopwatch is still running.
2 if the stopwatch is still running and the trigger time is still in the future do nothing.
3 if the trigger time has past do whatever the macro is supposed to do at trigger time.
4 if the stopwatch is not running and the trigger time is still in the future, start the stopwatch to trigger when it reaches the trigger time (trigger time - system time) and end.
 
Top