Constraints are being ignored... Is it just me?

Grimmer

New member
I have a macro to send an automatic "Shhh, I'm driving" when connected to any one of several bluetooth devices.

Originally, I used the trigger "received SMS" with a Macro level constraint "Bluetooth Device Connected" listing only the applicable bluetooth devices. That worked some of the time, but all too often the actions fired when I was not connected to any of those devices. So I removed the macro level constraint and changed the trigger to have several individual "received SMS" & "Bluetooth device connected" constraint for each applicable device. That worked great for a long while, but a couple of days ago it started ignoring those constraints as well and is firing the actions when I'm not connected to any of the listed devices.

As a third work around, I will try creating a separate macro that sets a global boolean "Connected" and then remove all of the dysfunctional constraints. Then either use an if statement that exits the macro at the top of the actions list, or nest all of the actions under an if statement.

But the question remains... Why aren't the constraints working? Has anyone else had issues like this? Or is it just me?
 

dsnz

Well-known member
keep your single bt connected constraint
and inside your macro and at start put an if bt connected then log a message
check your log together with the system log (at the same timeframe)
and tell what you get
 

Grimmer

New member
OK. I have added the log action (I couldn't find a way to call up the name of the connected bluetooth device, so it only logs the date/time, macro name, and the incoming SMS number. If nothing becomes apparent with this first approach, maybe I'll have to add device specific (and constrained) log entry actions.

I'll let it cook for a bit to see if it continues to fire automated responses when it isn't supposed to.
 

macro_monkey

New member
OK. I have added the log action (I couldn't find a way to call up the name of the connected bluetooth device, so it only logs the date/time, macro name, and the incoming SMS number. If nothing becomes apparent with this first approach, maybe I'll have to add device specific (and constrained) log entry actions.

I'll let it cook for a bit to see if it continues to fire automated responses when it isn't supposed to.
Did you resolve this? It's been happening to me, too. Same issue with bluetooth device connection being ignored both inside an IF statement and as a constraint.
 

Endercraft

Moderator (& bug finder :D)
Did you resolve this? It's been happening to me, too. Same issue with bluetooth device connection being ignored both inside an IF statement and as a constraint.
Can I have a look at your macro ? It could just be a bad configuration somewhere.
 

Grimmer

New member
It comes and goes... It worked well for a long time but just recently it started occasionally doing it again (there may have been a OTA Android update in there). I suspect that there is an issue with the way that Android reports or MacroDroid reads the status of the bluetooth connections. Many times it has seemed like the issue occurs the first time (or so) after the phone is rebooted, perhaps mitigated by manually opening MacroDroid once after a phone reboot. It may also correlate to the way the bluetooth connection get passed from device to device (i.e. garage speakers transferred to car stereo and back). I could not find a direct way to read what bluetooth device MacroDroid currently thinks it is connected to (I really wanted to include that in the log statement - that is really the most important piece of info). If anyone knows how to do that without a string of constrained log (or IF) statements, please let me know.

I did revert back to the single trigger with the constraints on the Macro rather than multiple parallel triggers that each had a constraint for an individual bluetooth device.

It appears that the "Share as Image" truncates some of the actions. Is there a better way to post a macro?

Thanks for taking the time to look it over and help find if there are any better ways to get it done.

The part of the first truncated IF statement checks to see if the length of the incoming number is at least 7 digits, this is to prevent an auto-response to a non-person. Catches most of them, except those companies that send notifications from a fully qualified phone number. Those will need to be added manually when I get around to it.
Driving_SMS_Bounce.png
 

Endercraft

Moderator (& bug finder :D)
What if you use a device connected trigger, set a global variable to [bluetooth_device_name] and then use that variable for the condition ?
 

Grimmer

New member
I have set up a "Device Connected" macro to set the global variable, and a "Device Disconnected" to clear it. And added some logging to get a feel for how it will behave.

I also set up a "MacroDroid Initialized" macro to clear some variables upon reboot. (Assuming that the "MacroDroid Initialized" will only trigger when it starts from a reboot.)
 

macro_monkey

New member
I found my issue, and it is indeed a Macrodroid issue and not a macro issue. I set up an IF statement to check and it turns out Macrodroid was reporting that my headphones (Pixel Buds A) were connected to Bluetooth when they weren't. I unpaired then re-paired them, then re-configured the macro. Macrodroid no longer erroneously reports them as connected. So something under the Macrodroid hood was misreporting the bluetooth connection.
 

macro_monkey

New member
I got an emailed reply from a user but it's not in this thread, so maybe it was removed. I'll answer the included question anyway in case it helps anyone. I'm on a Pixel 6.

> Are you sure it's something under the Macrodroid hood that was the cause of your issue?

Yes. What I did to test was to create an IF (headphones connected)/THEN (create a notification) macro. Even after forgetting the headphones in Bluetooth and turning them off, the macro continued to report them as connected. Only after removing all mention of the headphones from my macros, re-pairing the headphones to my phone, and adding (device connected) back to my macros were they correctly recognized. So it's clear that Macrodroid will sometimes report a device connected when it is not.
 

MacroDroidDev

Administrator
Staff member
I believe the issue is due to the fact that MacroDroid cannot actually query for the connected bluetooth devices but can only listen for connect and disconnect events and infer the status that way. The issue happens when MacroDroid is started after a bluetooth device is already connected and in this case it doesn't see the connect event so cannot know it's connected. I don't know exactly what I can do about this to make it any better as it's quite a problematic limitation.

If anyone has time it would be great if you could verify the equivalent functionality in Tasker and/or Automate and confirm if they have the same limitation or not. If they do not then it's a clear signal that I need to do better here and there must be a way to do it!
 

macro_monkey

New member
I believe the issue is due to the fact that MacroDroid cannot actually query for the connected bluetooth devices but can only listen for connect and disconnect events and infer the status that way. The issue happens when MacroDroid is started after a bluetooth device is already connected and in this case it doesn't see the connect event so cannot know it's connected. I don't know exactly what I can do about this to make it any better as it's quite a problematic limitation.

If anyone has time it would be great if you could verify the equivalent functionality in Tasker and/or Automate and confirm if they have the same limitation or not. If they do not then it's a clear signal that I need to do better here and there must be a way to do it!
That makes a lot of sense. Thanks for clarifying. I'm not sure how to make sue my macro never uses the phone speaker, but knowing how MD determines bluetooth device connectivity is helpful. For now I've just added a check to make sure it's only firing at a reasonable time and in reasonable places, just in case there's another bluetooth issue.
 

hiyono

New member
I believe the issue is due to the fact that MacroDroid cannot actually query for the connected bluetooth devices but can only listen for connect and disconnect events and infer the status that way. The issue happens when MacroDroid is started after a bluetooth device is already connected and in this case it doesn't see the connect event so cannot know it's connected. I don't know exactly what I can do about this to make it any better as it's quite a problematic limitation.

If anyone has time it would be great if you could verify the equivalent functionality in Tasker and/or Automate and confirm if they have the same limitation or not. If they do not then it's a clear signal that I need to do better here and there must be a way to do it!
Hello.
I am a Japanese who does not speak English well, please forgive me for the translated text using DeepL.

Regarding the issue of not getting the Bluetooth connection status correctly, I am experiencing the same problem and came to this thread.

>If anyone has time it would be great if you could verify the equivalent functionality in Tasker and/or Automate and confirm if they have the same If they do not then it's a clear signal that I need to do better here and there must be a way to do it!

I tried to get the status in Tasker and it seemed to be working fine, so I am assuming that this issue is specific to MacrodDroid.

I am attaching an image so that you can check it out.

Action created
01_action.png02_action_IF.png

Bluetooth status 01
03_blutooth.png
Result 01
04_resultMD.png04_resultTasker.png

Bluetooth status 02
05_bluetooth.png
Result 02
06_resultMD.png06_resultTasker.png
 
Top