Multi-device variables

Hello everyone, I got a phone and a tablet, both with macrodroid installed. But there are some macros I'd like to set with them both. Such as controlling the tablet's flashlight with the phone, or, depending on which one has more battery, or being used at the moment, puts the other on battery economy.
I imagine it's possible if there were a way to share some variables between devices.
I thought about cloud services, but i don't know how to pull this off nor if it's the best/more viable solution.
If someone could help me out with this I'd be incredibly glad! :D
 

Dm114

Well-known member
Hello everyone, I got a phone and a tablet, both with macrodroid installed. But there are some macros I'd like to set with them both. Such as controlling the tablet's flashlight with the phone, or, depending on which one has more battery, or being used at the moment, puts the other on battery economy.
I imagine it's possible if there were a way to share some variables between devices.
I thought about cloud services, but i don't know how to pull this off nor if it's the best/more viable solution.
If someone could help me out with this I'd be incredibly glad! :D
You can use webhook:
 
Thanks a lot! I tried it and it kinda worked!
But i still have one problem, as far as I know, the webhook triggers just on the device which owns the device id, in the link. Is it possible to make one wwebhook link trigger on multiple devices?
 

Endercraft

Moderator (& bug finder :D)
Thanks a lot! I tried it and it kinda worked!
But i still have one problem, as far as I know, the webhook triggers just on the device which owns the device id, in the link. Is it possible to make one wwebhook link trigger on multiple devices?
Not possible. Each device must have it's own id - that's just how it works on the server.
 
Not possible. Each device must have it's own id - that's just how it works on the server.
Fine, but is there a way to replicate the same webhook which triggered the macro?
For example:
I used this as a webhook:
so, this will also trigger it:
Is there a way this macro can catch the string "?randomVar=5"?
If so, I could replicate this webhook to create similar ones on different devices, such as:
Thanks a lot! You're helping soooo much!

edit:
I found the magic string "webhook_url" and bursted in flames of hope, but it just copies until the deviceID :(
No identifier nor var updates
 
Last edited:

MacroDroidDev

Administrator
Staff member
I'm not sure I understand the issue here.

If you want to send a series of webhook calls to different devices passing the same value you could just do this:

https://trigger.macrodroid.com/deviceID1/identifier?randomVar=5
https://trigger.macrodroid.com/deviceID2/identifier?randomVar=5
https://trigger.macrodroid.com/deviceID3/identifier?randomVar=5

Then as long as each device has a macro configured with a webhook trigger it should be triggered and set the relevant variable on the local device.
Thanks for the reply!
The problem I'm dealing with is to replicate a webhook i received, to other device.

For example, i receive this webhook:
https://trigger.macrodroid.com/MyDeviceID/identifier?randomVar=5
My device will update the RandomVar to 5, but won't have direct access to the string "?randomVar=5" to replicate this webhook to my other devices.

I tried the magic string "webhook_url" but it just got "https://trigger.macrodroid.com/MyDeviceID/identifier"

My goal is to create the string
"https://trigger.macrodroid.com/deviceID1/identifier?randomVar=5"
 

MacroDroidDev

Administrator
Staff member
Can't you just construct the string manually, using the set variable action something like:

Set variable webhookUrl = https://trigger.macrodroid.com/<WhateverDeviceIdYouChoose>/identifier?randomVar={v=randomVar}

So in the case the randomVar value 5 is taken from the variable that gets updated when you receive the webhook on your primary device.
 
Yes, that could be a way if I had just one variable, it would be easily predicted. But im planning to deal with a bunch of them.
RandomVar1, RandomVar2, and so on.
That would be trickier to predict.
 

RSF

Well-known member
Could you populate a dictionary-type variable, instead of individual variables?

i.e....
In the initial call (whether in a macro on a device, or from a browser, etc.)
  1. Use a URL like so: DeviceID2/triggerID?dict(a)=avalue&dict(b)=bvalue&dict(c)=cvalue
In the "receiving" device's macro
  1. Specify that webhook trigger from above (https://trigger.macrodroid.com/DeviceID2/triggerID)
  2. Define a dictionary variable called "dict". That'll get populated with whatever number of variables you send in the webhook above, as many as you send
  3. Iterate through the dictionary, appending each variable to a URL string as shown below to incrementally form the webhook for the next device (see screenshot below)
  4. Finally, "forward" the webhook to another device via a HTTP GET action using that URL
Screenshot 2023-04-18 10.24.48 AM.png

In the next "receiving" device's macro
  1. Same as above... just change the device ID each time in the URL to specify the next device
 
Last edited:
Top