Friday, December 8, 2017

Automate Flow: Auto enable Bluetooth to connect to car hands-free when you are driving, else disable Bluetooth

This is an example of Automate flow. To learn more about Automate for Android phones, click here.

It is always a good idea to disable the Bluetooth function of your Android phone until you want to pair it with another Bluetooth device, such as hands-free system, GPS, audio speaker, input device (keyboard, mouse, gamepad, ...), etc. This will help to conserve some battery usage of your phone.

However, if you are always wearing a Bluetooth smartwatch that paired with your smartphone, you will need to let the Bluetooth function of your phone to always stay on. In that case, this Automate flow might not be so relevant for your need.

Nowadays, driving laws in many places in the world prohibit holding your phone in your hand while driving. If you are caught with that, you could be imposed with penalty and fine. Therefore, you need a hands-free system to answer to phone calls while driving. Many modern cars already have built-in hands-free function in their audio system. Certain automotive GPS device such as Garmin DriveAssist, Garmin DriveSmart, etc. is also able to link with your smartphone through Bluetooth to provide hands-free and some other additional functions.

Well, if you always disable Bluetooth of your Android phone and manually enable it whenever you want to pair it with a Bluetooth device, it would be very tedious if you are a frequent driver. You will need to enable Bluetooth whenever you sit in your vehicle and started its engine, and disable Blueooth whenever you parked your vehicle and stopped its engine, otherwise you will not be able to use the hands-free function. This Automate flow will help you to automatically perform those action.

In addition, normally when we are in a vehicle on the road, there is no WiFi available. This flow will also help you to disable WiFi when it detected you are travelling in a vehicle. You can edit the flow and remove the "Disable WiFi" block in it if your vehicle does provide WiFi connection that you want to use.


The flow begins with a block to stay and wait until it detected your Android phone carried along with you is travelling in a vehicle. This is a very interesting Automate block. Beside "in vehicle", it can also detect whether you or your phone is:
  • On bicycle
  • On foot
  • Running
  • Still
  • Tilting
  • Walking
  • Unknown
It makes use of sensors of your phone to perform the guessing, and report back with a confidence level. The "in vehicle" block setting of the above flow is as below:

The flow will continue its further actions when it is at least 85% sure that you are in a vehicle. The detection interval is set at 2 minutes. If you want the flow to react faster, you can shorten this detection interval, but it might drain more battery at the same time.

Once it detected you are in a vehicle, it will disable WiFi function of your phone (Block 3).

It will then detect whether the battery level of your phone is above 30%. If it is below, whether your phone is plugged to a power source for charging. If both conditions are negative, it will disable Bluetooth and do nothing. I put 30% battery level as this should be sufficient to keep your phone on with Bluetooth paired for quite a long journey. You can adjust this minimum battery level requirement in Block 14 according to your situation. If your driving distance is most of the time pretty short, probably 15% minimum is good enough for you.

If battery level is OK, it will proceed to enable Bluetooth, wait for 10 seconds for your phone to pair with the Bluetooth device in the vehicle (which as a prerequisite, they must be successfully paired before), such as your car audio system hands-free, or your GPS. If the pairing is successful, it will keep the Bluetooth connection until it is disconnected. Disconnection will happen when your car audio system is switched off (when car engine turned off), or when you manually disable your phone Bluetooth function (in case you do not intend to use hands-free during that journey. For example, you are a passenger in your own car which one of your family member is driving for that trip).

It will wait for 3 minutes before going back to detect whether you are in a vehicle again. 3 minutes is a reasonable minimum time interval for you to leave your car and then to drive it again. That will be the estimated time to stop the car engine, pump the petrol, and resume driving. For other occasions, probably the interval is much longer. You can edit Block 13 to change this interval shorter or longer to suit your need too.

In the event Bluetooth pairing failed after the Bluetooth is enabled, you are very likely to be not in your own car, but in another vehicle either as passenger or driver. Since the hands-free function is not available to you in that vehicle, the flow will proceed to disable Bluetooth and wait for a longer 30 minutes (which you can edit Block 20 to change it to be shorter or longer). 30 minutes is an estimation that you will probably won't drive in your own car, since you are travelling in another vehicle at that moment.

In fact, you can remove both Block 13 and Block 20 and immediately go back to activity checking if you want. The 2 delay blocks are merely for the flow to take a break (and save some battery).

Thursday, December 7, 2017

Automate Flow: Auto enable WiFi when you arrive home and disable WiFi when you leave home

This is an example of Automate flow. To learn more about Automate for Android phones, click here.

It is always a good idea to disable the WiFi function of your Android phone until you want to connect to a WiFi network. This will help to conserve battery usage, and also prevent your phone from automatically get connected to certain open WiFi without your aware, which might be used to hack in your phone.

Normally, there are fix places with WiFi that you will definitely want to use, to conserve your mobile Internet data quota usage. Those places include your home and/or your work place.

This Automate flow will help you to automatically disable WiFi function of your phone after your leave your home, and automatically enable it back when you arrive your home. It will even inform you by voice so that you are aware when WiFi is automatically enabled and disabled by this flow.


Enabling WiFi function does not guarantee a successful connection, because sometimes your access point (AP) or wireless router might have problem in establishing the WiFi connection.

Therefore, after enabling WiFi, this flow will wait for 10 seconds, which should be long enough for normal WiFi connection to be established. It will then check if the connection is successful or not.

If the connection is successful, it will log down the name a.k.a. SSID (service set identifier) of the AP or wireless router your phone has connected to.

If the connection is not successful, it provides option for you to remain enable WiFi or to disable it. Regardless of your selection, you will still need to troubleshoot and find out why the WiFi connection cannot be established. It could be caused by your AP or wireless router is switched off, or hang, or WiFi function disabled, or DHCP IP address allocation full, or other possible issue. If your phone has never made a successful connection with the WiFi at the location before, or you have made your phone "forget" about it, the connection will also be not successful as well.

Before you can use this flow, you need to tell it where is your home. This can be done by tapping on Block 12 "When at location". The following screen will come out.

Tap on the "Pick a location on map..." button to bring out Google map. You can then search for your home by either tapping on the "target" icon if you are currently at home, or by tapping on the search (magnifying glass) icon and key in your home address for search, or by manually selecting the location by navigating the map and tap on the targetted place.


When you are done, tap on the OK button below to capture the location's coordinate.

The Radius setting determines the area that you consider your phone is at home. Normally, 50 meter radius as shown above is a good choice. You can set its value larger so that your WiFi is automatically enabled faster when your approaching home, and automatically disabled after you have travelled further away from your home.

You can use this same flow for other places with fixed WiFi, such as your work place. Just go through the same steps able to set the location before running it. You might also want to change the word from "home" to "office" in Blocks 14, 15, 16 and 17 of the flow.

With slight modification, you can even expand this flow to be used for multiple locations.

Wednesday, December 6, 2017

Automate Flow: Always go back to Home screen whenever phone is unlocked at launcher screen

This is an example of Automate flow. To learn more about Automate for Android phones, click here.

This is a very simple Automate flow with only 4 blocks (including the Flow beginning block).

Most if not all Android launchers support multiple screens for you to organize your apps and widgets into different screen as needed. One of the screens is your Home screen, which normally is where you put your mostly accessed apps and widgets.

When you are at the launcher screen without any opened foreground app, you can always go back to the Home screen by pressing your phone's Home soft key or Home button.

If most of the time, when you unlock your phone and start using it, you want to be at the Home screen regardless of which launcher screen you were at when your phone went to sleep and locked itself, this is exactly what this Automate flow will do.



This flow will wait until you unlock the phone, and check if you are at the launcher screen (meaning, no app is opened at the foreground). If yes, it will emulate pressing the Home button so that you will go to the Home screen automatically.

If you were running an app at the foreground (such as Whatsapp, browser, email, Facebook, etc.) when the screen was last locked, the flow will do nothing and you will return to the app screen after unlock.

In order for this flow to work properly, you need to set the correct launcher app of your phone in the "Is foreground app" block, because different Android phone vendor might provide their own launcher app to the phone. In addition, Android system also allows you to install and use 3rd party launcher app such as Nova launcher, Apex launcher, TSF launcher, etc.


You can tap on the "Pick activity..." button as shown above to select the launcher app you use in your phone.

The setting in the above screen is for Samsung TouchWiz launcher. For HTC phones, set the Package to "com.htc.launcher" and leave the Activity Class as empty field.

What if you never set any screen lock to your phone? In that case, you just need to change the "When device unlocked" block to "When screen is on" block.

Hint: Click on the "Older Posts" link to continue reading, or click here for a listing of all my past 3 months articles.