How do Constraints work?

Mach3Maelstrom

New member
I want to use a geofence to detect when I'm entering my parking garage so that I can pop up a reminder to tell my wife which floor I parked the car on. But I know geofences uses a lot more battery power, so I'm looking to only check the geofence during the 1-2 hour window I typically drive home.

But as I was writing the script, I wanted to double-check how Triggers & Constraints are treated in MacroDroid so I don't accidentally create an always-on geofence.

For example, say I set the Constraint for a specific Time of Day and the trigger for when I enter a Geofence -- how does the script treat this interaction?

(A) While-If Statement

Code:
while (Time of Day is between X & Y) {
   if (Geofence Trigger) {
      [execute code]
   }
}

or (B) If-While Statement

Code:
if (Geofence Trigger) {
   while (Time of Day is between X & Y) {
      [execute code]
   }
}

I suspect the answer is (A), but I couldn't find any documentation confirming.
 

Pseudocyclic

Well-known member
Have you considered:

A: IF trigger fired = geofence trigger AND time of day is between X & Y
A: execute payload actions
A: ENDIF

?

Why not apply the time of day constraint to the geofence trigger?

Alternatively use two macros - first macro with X and Y triggers to enable/disable the second macro at the appropriate times, second macro with geofence trigger.
 

MacroDroidDev

Administrator
Staff member
I recommend you create a macro with a Geofence trigger and then have another macro to turn this on and off at the desired time. This will ensure your Geofence is only being checked during this limited time window.
 

Mach3Maelstrom

New member
I recommend you create a macro with a Geofence trigger and then have another macro to turn this on and off at the desired time. This will ensure your Geofence is only being checked during this limited time window.
Thank you! I'll take this route to create this automation.

I'd still like to understand how Triggers/Constraints interact within MacroDroid -- aka while grateful for the fish, I'd like to learn how to fish.

Are triggers/constraints handled like Case A or Case B per my OP?
 

MacroDroidDev

Administrator
Staff member
The while loop comparison is not correct in any case, as a macro trigger is a one of instantaneous event.

Essentially a trigger will fire and at the point any constraint is checked to make sure the macro can run and if all conditions are true the macro will be invoked.
 
Top