Variables in MacroDroid
What is a variable?
Imagine that a variable is a reserved space on your desk to use later:
- The Label: The name of that space (e.g.
User). - The Content: What you store there (e.g. "
Josué").
What's the trick?
Your macro knows it must look for "whatever is in that space".
If tomorrow you change the content, the macro will still work the same because it doesn't look for a fixed text, but for what is stored in that position.
In summary: It is a mental note for your macro: "Store this data here, I'll use it later".
Local vs Global Variable
MacroDroid has two main types of variables:
Global Variables
Syntax:
{v=varName}or[v=varName]Available everywhere:
✅ All macros
✅ Action block
✅ Constraints
✅ Conditions
✅ Text fieldsIdeal for sharing data between different macros or storing information.
Best use:
User settings, counters, API responses, last known location, states (flags), etc.
Local Variables
Syntax:
{lv=varName}or[lv=varName]Only available within the macro where they are created (including any Action Block called by that macro).
Perfect for temporary or private data that should not be shared with other macros.
Best use:
Intermediate calculations, loop counters, temporary API keys or any value you only need within a macro.
Quick rule:
Use Global Variables when you need to share or keep data between macros.
Use Local Variables when the data is private to a single macro.
Secure Variables
You can mark any variable (Global or Local) as Secure.
- Secure variables have their value automatically cleared when the macro is:
- Exported
- Uploaded to the template store.
This is key to protect sensitive information such as:
- Passwords
- API Tokens
- Private keys
- Personal data
Recommendation: Always mark as Secure the variables that contain sensitive information.
How to use Variables
Variables can be used in almost any part of MacroDroid:
- In conditions and If/Else logic
(e.g. “If{v=isLoggedIn}is true”) - In constraints
(e.g. “Only run if{v=batteryLevel}> 50”) - In text fields
using Magic Text ({v=varName}or{lv=varName}) - As input or output
in many actions (HTTP Request, Shell Script, Text Manipulation, Mathematics, etc.)
You can insert them easily by tapping the Magic Text button
(usually the ... icon) in any text field.
Variable Behavior
Variable values are persistent by default.
You can change the value of a variable using actions such as:
- Set Variable
- Clear Variable
- Outputs of actions such as HTTP Request, Shell Script, Read File, etc.
Recommended Videos
Here are two official tutorials about variables:
