# Phone automation — Automate Whatsapp messages with NFC, Tasker & Auto Input in 15 mins

--

I have (had?) a problem — every morning when I reach my office, I ping my wife that I’ve reached the said office. Some days, I forget. And she, being an Indian wife, worries a tad too much and I end up getting calls and pings asking if the road split open and swallowed me whole — rendering me incapable of sending a simple message of ‘reached’ to her.

I’m a lazy person. I also know that necessity is the mother of all invention. And that it is the grand-aunt of automation. So without further ado, here is how we’ll wire up the phone to send my wife a message every time I reach office.

## The Flow

As you can see, there are a few apps involved that do most of the heavy lifting for us. The main flow is:

2. The task runs the logic to determine if & what message to send
3. Opens Whatsapp and sends the message
4. Closes Whatsapp

## Step 1 — Preparation

This is a fairly straight forward exercise. Install the following apps from the Play store:

1. NFC Tools
4. Auto Input

Purchase a NFC tag with a 3M sticker. You’ll get this online for really cheap (link).

Note, when you’re buying these, make sure they’re writable and NXP MiFare compliant.

## Step 2 — The Task

Before we wire the system up together, we’ve to build the task on Tasker. I won’t go into details on Tasker itself, but think of it as a really powerful MS Excel Macro tool for your phone — except that you’re not restricted to a spreadsheet and it’s more for your phone.

Here is a step by step logic breakdown:

a. We first determine if the day is a working day. Hence the regex:
[^(Fri)|(Sat)]{3} (we work Sunday to Thursday here in the GCC)

What this does is checks if the first 3 characters ({3}) are not Fri or Sat. The Day of the week variable is %DAYW in Tasker, which you can get by tapping on the Variable icon in the task.

b. Now that we know we’ve to send the message, we’ve to determine what the message is — for this, we need to know the time. Typically, I reach office anywhere between 7am to 11am, depending upon work. And I leave anytime after 3pm and before 10pm. Based on that, I have to send different messages.

To get the timing right, we need to split the %TIME variable (output is hh.mm) and get the hh part. Variable split helps in breaking down the %TIME variable on ‘.’ and putting the values in %TIME1 (hh) and %TIME2 (mm). Once we determine the IF logic, we can write the message values to a variable %MSG.

c. Since we’ve determined the message, the only thing left is to send the message. Whatsapp API comes in handy here — https://api.whatsapp.com/send?phone=<phoneNumber>&text=%MSG

d. Now, so far, we’ve opened the Whatsapp application and entered the message. But the message isn’t sent till you press on the ‘Send’ button. That’s where Auto Input comes to the rescue. Auto Inputs allows you to fake inputs to your phone. We’ll use Auto Input to press the send button.

e. Now that the message has been sent, we just need to go back home, without disturbing the phone!

f. Enable External access on your Tasker. It’s a configuration that allows other apps to trigger any of Taskers Tasks. You can find this in the Preferences, as shown to the left.

## Step 3 — Write to the tag

Here is how to do that using NFC tools. Remember you need NFC Task to run the task:

## Step 4: Profit!

Alright, let’s talk about the problems with this approach and how we can solve it in the future:

1. The trigger for this is manual — the NFC tag sits in my car/on my desk that forces me to tap it. If I remember to tap, I can remember to send!
2. This requires the phone to be unlocked, due to security. I’m yet to find a way I can bypass this. The only other way is to make a Web service call in the background which then triggers a message (in the cloud), without invoking the UI. It seems difficult, but I’ll consult my local android expert soon.
3. It would have been easier for me to track the Bluetooth connection to the car and track the change of Bluetooth connection — if car Bluetooth disconnects, it could mean I’m in the office, if I simultaneously check the location at that time. That would increase my efforts drastically, but some of you better motivated folks could take a stab at this? Do keep me posted.

And there you have it folks! An easy 3 step guide to make automation a reality in your life.