Turning NFC on when application closes

Sciamano

New member
Hello,
I had this "genius" idea of putting an NFC tag on my car phone holder so that when I enter my car and place the phone in the holder, my car dashboad (CarHome Ultra, BWTW) automatically opens (and other things automatically happen). The problem is that the NFC tag will be read continuously as long as the phone stays in the holder, therefore in my macro triggered by the NFC tag I also disable NFC once the macro is triggered.

So far so good.

Problems arise when trying to obtain the opposite: how do I reliably turn NFC on again after I pick the phone from the holder and exit my car?
I tried with the following:

NFC_Toggle_in_CarHome_Ultra_2-2_2.png
But it won't work reliably. First of all because the Application Closed trigger also fires when CarHome Ultra goes in the background (which, for example, happens as soon as I start Waze or Google Maps). I also tried adding the Notification Cleared trigger trying to take advantage of the fact that when CarHome Ultra goes in the background it will show a notification that allows to go back to CarHome Ultra or exit it: my logic was "when I exit the car (and exit CarHomeUltra by using the EXIT button within the app) the notification will disappear, triggering the macro" but this is also not a reliable system because the Notification Cleared trigger apparently won't fire when the notification disappears because the app has been closed, but only fires when clicking 'exit' on the notification.
Or at least this is what happens to me: if I exit CarHome Ultra by using the exit button from within the app, the trigger won't fire, but it will fire if I close CarHome Ultra using the exit option shown in the notification.

The result is that I'm never sure whether NFC has been turned on again or not, and I have to check manually (and eventually turn it back on manually if it's not), which defeats all the purpose/advantage of having a macro take care of this.

I also tried adding the constraint you see in the picture above but it does not change much.

How can I obtain what I need? I'm sure it's possible and that it's just beyond my macrodroid abilities.
Thank you
 
Last edited:

dhj49er

Well-known member
I have read that DMU uses Bluetooth to connect to the cars multimedia.

Does your car have Bluetooth?

If so, use Bluetooth connect and disconnect to the car as triggers.

I find this approach works well to set the phone to a Car mode on entering the car and exit Car mode on leaving the car.

With this approach there is no need for NFC tag.

If no Bluetooth, do you charge your phone when you use it your car?

If so, try using power disconnected as the trigger for when you leave the car.
 

Sciamano

New member
Thanks for the suggestions.
My car has bluetooth but I can't use that as a trigger for different reasons, that it are too long to explain. If I could use BT as a "trigger" I wouldn't even need to use Macrodroid, as CarHome Ultra integrates an "autostart when car is connected via BT" function that would make the macro useless.
Unfortunately I can't use that.
Maybe the power disconnection could be more exploitable, but how do I "teach" macrodroid to distinguish the power disconnection in the car from other power disconnections? I need this macro to run only when I exit the car...
 

dhj49er

Well-known member
Set a Boolean variable (InCar say) true in the macro that triggers on NFC flag. Then have a macro triggered by power disconnect with constraint InCar true. In this macro wait a few seconds ( to make sure the phone isn't near the tag!) turn on NFC and include the action set InCar false.
 
Last edited:

Sciamano

New member
This could be a viable solution. Thank you.
I will test this.
The only drawback would be when I put the phone in the holder without connecting the power cable, but it's definitely a step forward.
 

Qarboz

Well-known member
Thanks for the suggestions.
My car has bluetooth but I can't use that as a trigger for different reasons, that it are too long to explain. If I could use BT as a "trigger" I wouldn't even need to use Macrodroid, as CarHome Ultra integrates an "autostart when car is connected via BT" function that would make the macro useless.
Unfortunately I can't use that.
Maybe the power disconnection could be more exploitable, but how do I "teach" macrodroid to distinguish the power disconnection in the car from other power disconnections? I need this macro to run only when I exit the car...
You can try the experimental Bluetooth Beacon trigger, if it works you should have solved it
 

dhj49er

Well-known member
Is a car Bluetooth a beacon?

Isn't it a device that's found when the phone scans for Bluetooth devices?

I'm not able to check on my car today but I've turned on another Bluetooth device after I had started a beacon scan. No beacon was found
 

Qarboz

Well-known member
Is a car Bluetooth a beacon?

Isn't it a device that's found when the phone scans for Bluetooth devices?

I'm not able to check on my car today but I've turned on another Bluetooth device after I had started a beacon scan. No beacon was found
In fact I've never used it, I thought it was similar to the "WiFi SSID Transition -> SSID in range" trigger but for Bluetooth instead of WiFi but I could be wrong.
If it doesn't work it could be that it is experimental and not definitive.
 

dhj49er

Well-known member
In fact I've never used it, I thought it was similar to the "WiFi SSID Transition -> SSID in range" trigger but for Bluetooth instead of WiFi but I could be wrong.
If it doesn't work it could be that it is experimental and not definitive.
I understand a Bluetooth beacon is a low power device that transmits small amount of data over BLE. I don't believe you can pair a beacon via the Bluetooth device scanner. I'm not sure as I don't have a BT beacon.

Conventional Bluetooth devices are higher power and transmit lots of data.

I think the reason is it's experimental, it needs to be checked with different beacons.

It's not the same as WiFi SSiD in range.
 

Sciamano

New member
If the car had some kind of dock it would be much simpler, but all I have is a USB socket which I use to charge the phone while I am driving.
That's why I resorted to NFC tags for a few tasks. For example I have also placed a tag in my car that opens my garage door when scanned, which is the reason why I need a reliable way to turn NFC back on as soon as I pick the phone up from the car holder.
I have now redesigned my macros in order to use the InCar variable and the power disconnection as the trigger, I only have to test them as soon as I get back home.
 

dhj49er

Well-known member
If the car had some kind of dock it would be much simpler, but all I have is a USB socket which I use to charge the phone while I am driving.
That's why I resorted to NFC tags for a few tasks. For example I have also placed a tag in my car that opens my garage door when scanned, which is the reason why I need a reliable way to turn NFC back on as soon as I pick the phone up from the car holder.
I have now redesigned my macros in order to use the InCar variable and the power disconnection as the trigger, I only have to test them as soon as I get back home.
If the NFC tag that starts DMU gets triggered after disconnecting the power and executing the NFC on, try the following

Use physical separation to prevent it or (better method) add the constraints inCar false to the macro that starts DMU. Then in the power disconnect macro after setting NFC ON, wait a few seconds before setting InCar false. The few seconds could be 10 or more as all it does is stop you from connecting to the NFC tag, so preventing it triggering, even if the tag and phone are close enough.

Another suggestion - use the InCar true as a constraint on the macro that's triggered by the NFC tag that opens the garage door. The few seconds I mentioned in the previous para now becomes the time window to swipe the garage door tag, so might need to increase it to 20 or 30 seconds.
 

Sciamano

New member
Use physical separation to prevent it or (better method) add the constraints inCar false to the macro that starts DMU.

This is a great idea. Adding a pause before changing the variable would allow me to read the NFC tag to open the garage door without the risk of triggering the "holder" NFC tag again (thus turning NFC off inadvertently again).

On to testing!

Thank you!

Btw, the other suggestion can't be followed because the NFC tag that opens the garage door doesn't trigger a macrodroid macro, but sends a command to Home Assistant instead. But thanks anyway, I have learned a lot from your suggestions.
 

dhj49er

Well-known member
This is a great idea. Adding a pause before changing the variable would allow me to read the NFC tag to open the garage door without the risk of triggering the "holder" NFC tag again (thus turning NFC off inadvertently again).

On to testing!

Thank you!

Btw, the other suggestion can't be followed because the NFC tag that opens the garage door doesn't trigger a macrodroid macro, but sends a command to Home Assistant instead. But thanks anyway, I have learned a lot from your suggestions.
It's not a typo!

The inCar constraint on your DMU macro must be false. This is the state it will be in when you enter the car. If you change it to true the macro will never run.
 

Sciamano

New member
Yes, I realized what you meant a few seconds after originally posting. I immediately edited that part out but I guess I haven't been fast enough :D
 

Sciamano

New member
After testing this method for a few days I can say it works flawlessly.
"Problems" arise only when I don't connect the phone to the USB cord when I enter the car, which might happen when I only need to drive a short distance, but unfortunately this can't be helped, since I can't think of any other trigger to use.
Thanks a lot to @dhj49er for the suggestions, help and patience.
 
Top