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)

15 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
  9. I created one macro that will identify notification particular Apps and then launch this Application.
    Problem is that now when Application open there is one popup small window open and need to take action is OK , I don't know how will it handle OK event .. help

    ReplyDelete
  10. Hi, I created one for how many times i launch "Whatsapp" application , by the end of the day i realized that i am addict to "Whatsapp" :)

    ReplyDelete
  11. Esta aplicación puede seleccionar opciones de otra aplicación? Me explico. Tengo que utilizar la aplicación GSE TIEMPO, para fichar todos los días en mi trabajo. Quiero que a una hora determinada MACRODROID ejecute la aplicación GSE TIEMPO (esto lo he conseguido sin problemas) y seleccione la opción de -entrada-. Después a otra hora determinada quiero que vuelva a abrir la aplicación GSE TIEMPO y seleccione la opción Salida. Si pudiera hacerlo ficharía sin problemas y podría dedicarme a atender a los niños del colegio donde trabajo. Pero no sé si MACRODROID puede actuar dentro de otras aplicaciones.

    ReplyDelete