Introducing the Webhook trigger

MacroDroid
4 min readJun 21, 2018

--

In V3.25 of MacroDroid a new trigger was introduced call the Webhook trigger.

Icon for a Webhook

What is a webhook?

From the wikipedia definition of a webhook: https://en.wikipedia.org/wiki/Webhook

Webhooks are “user-defined HTTP callbacks”

What does this mean for MacroDroid?

In simple terms it means you can type a particular Url into a web browser and then a trigger will be invoked on your device.

An example of such a URL is shown below:

http://trigger.macrodroid.com/c306bcd7–5f78–4895-bee4–69600af77d4d/example

This URL consists of the following parts:

http://trigger.macrodroid.com/ (A fixed address always at the start)

c306bcd7–5f78–4895-bee4–69600af77d4d (A unique device id assigned to an individual device)

example (An identifier for a specific trigger so you can have as many Webhook triggers as you desire on a single device).

For more techy users you can use both an HTTP GET or HTTP POST in the above format.

How can I use it?

Of course the whole point of MacroDroid is for you the user to come up with your own unique way of using the trigger but to get you started it may help to offer a few examples.

Inter device communication in MacroDroid -By using the Open Website/HTTP get action (and selecting the HTTP Get option), you can invoke a trigger on another device.

Integration with IFTT -IFTT is a very powerful automation app that can connect to a ton of web services to trigger events (but it’s Android capabilities are very limited compared to MacroDroid). Unfortunately they don’t make it easy to integrate with an Android app such as MacroDroid (unless you pay them lots of money) so by using a WebHook action (THAT in IFTT speak) you can easily invoke a MacroDroid macro from IFTT.

Trigger MacroDroid events from a desktop browser -By simply creating a series of browser bookmarks you could have a quick and easy way to manipulate your phone. For example you can create a webhook with id ‘silent’ that will put your device into do not disturb and then be invoked from a bookmark in your chrome browser.

Send information from your home automation system to MacroDroid -For example using Prota OS you could invoke a WebHook to send the temperature of a sensor to store in a MacroDroid variable.

Sending parameters

In addition to an identifier it is also possible to send URL parameters to the trigger which are then used to set MacroDroid Variables. The format for sending parameters is as follows:

http://trigger.macrodroid.com/c306bcd7–5f78–4895-bee4–69600af77d4d/example?intparam=42&strparam=sometext

For example we could configure a macro that speaks some text that can be defined in the web link and then send that text across as follows:

http://trigger.macrodroid.com/c306bcd7–5f78–4895-bee4–69600af77d4d/speakText?textToSpeak=Hello

Please be aware you should have previously defined the MacroDroid variable in the list of variables. MacroDroid will attempt to set the value based on the variable type but if for example you try and send a text string on an integer variable it will of course not work correctly.

About the device id

You may be rightly wondering why the url ends up being so unfriendly with such a long and hard to remember deviceId. The device id is generated at first app run to uniquely identify a device. The value chosen is a UUID which simply means to all intents and purposes we can be sure this is will be unique and a clash between two devices will never occur.

In the long run I’m open to the possibility of creating user friendly aliases to a URL to help produce something that is easier to remember and share but it is not without difficulties.

I would need to implement some way of tracking what user ‘owns’ a particular alias so they could transfer it to a new device. The advantage of the current mechanism is that no user management/sign in is required.

As with a URL it is likely that popular aliases would be taken quickly for example a user might want to identify there device as ‘GalaxyS9’ so ids such as this would be quickly snapped up.

I welcome your feedback on this but in the mean time I hope this is good enough to get going with.

TinyUrl and Url sharing

When configuring a Webhook trigger there is the option to generate a TinyUrl link for the URL (fixed address + your unique deviceid). This essentially creates a much shorter alias which you can then just append your ids to trigger particular macros.

Also from the configuration page you are able to easily share and copy the URL link of both the standard and tiny url so you can send the link to where you need it.

--

--