Thursday, November 28, 2013

MacroDroid Variables

Having recently introduced MacroDroid variables I get a lot of requests for more information on what they are and how they can be used. This blog post will explore how you can use MacroDroid variables to enhance your existing Macro set.


What is a variable?

In simple terms a variable is just an identifier that can hold some kind of value. MacroDroid currently support three different types of variable as follows:
  • boolean - A simple true or false value (effectively on/off)
  • integer - A numerical value (whole number)
  • string - A literal sequence of characters.


What can I do with them?

There are a few different uses for variables as highlighted below
  • Add a constraint so that a macro will only fire if a variable has a certain value. In this way variables can be used like MacroDroid modes, without effecting the single global state.
  • Output the value of a variable into an SMS/email, pop up message etc.
  • Trigger another macro when a variable is set to a certain value.
  • Create simple counters so you can count how many times an event happens and then trigger another macro at a certain count.


Concrete examples

The best way to understand how to use MacroDroid variables is with some simple examples.

1) Log how many SMS have been received in a day

Macro 1: Count SMS
- Trigger: Incoming SMS (Any)
- Action: Set Variable sms_count + 1

Macro 2: Log SMS Count
- Trigger: Day Time Trigger 23:59
- Actions: Calendar - Log Event (value of sms_count)
              Set Variable sms_count = 0

At the end of each day the number of incoming sms will be written to the calendar and reset to zero, ready to count the incoming SMS for the next day.

2) Block/Unblock a macro from firing via SMS. The example macro to block is one that makes the phone buzz every 1 minute (for example if you want a regular buzz when running or similar).

Macro1: Block Buzz
- Trigger: Swipe screen (left to right)
- Actions: Set variable block_macro to true
              Pop up message "Macro Blocked"

Macro2: Enable Buzz
- Trigger: Swipe screen (right to left)
- Actions: Set variable block_macro to false
              Pop up message "Macro Enabled"

Macro3: Regular Buzz
- Trigger: Regular interval (1 minute)
- Actions: Vibrate
- Constraint: Variable (block_macro = false)

12 comments:

  1. I have used the variable feature very successfully to suppress a macro. When in car mode I have two macros, one that reads out notifications and one that reads out SMS messages. The initial problem is that if I receive an SMS i don't want it notified AND read out, just read out. I solved the problem by creating a boolean variable that is set to false when a SMS is received. This stops the notification macro from working for receiving an SMS, but still works for all other notifications.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Reformulated :::
      Can we also delete, get rid of a MacroDroid variable once it has been created_? I_didn't quite find a way to do so thus far. Am I blind ?

      Delete
    2. Hit the menu/overflow button from the main MacroDroid home screen and you can edit your list of variables.

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Reformulation for this one :::
      Here's another sort of request. I'd wish for some kind of string functions on_MacroDroid variables. Particularly I'd like to be able to remove the leading zero from the built-in [minute] time variable.

      Delete
    2. Applies when [minute] is below 10 of course.

      Delete
  4. Can somebody give some more examples of how they use variables, there's not a lot of info even on the forums.

    ReplyDelete
  5. Is there a way to create an integer variable based on how many characters are in a notification?

    ReplyDelete
  6. How to create a macro that runs only once a day

    ReplyDelete
  7. ¿Se guardan las variables cuando Exporto las Macros?

    ReplyDelete
  8. ¿Se guardan las variables cuando Exporto las Macros?

    ReplyDelete