Search results for

All search results
Best daily deals

Affiliate links on Android Authority may earn us a commission. Learn more.

Android customization - how many days until Christmas? Voice input and variable management in Tasker

This Tasker project uses variables to count down to an upcoming date. We step it up by using voice input and output to trigger this Android customization.

Published onNovember 27, 2014

I hope you’ve found some use out of last week’s Android customization post, certainly, being able to fall to sleep to your favorite music is a great thing. This week we give in, just a little bit, to the urges of the season. That is, with many of you reading this while resting off a Thanksgiving day meal, it is time to start thinking about Christmas.

Perhaps Christmas is not your thing. Please do not get caught up on this part of the process, you can use this project for any day you desire. What we wish to look at today is utilizing voice input and some tricky variable management in Tasker.

Before we get started

Get it on Google Play Button
You will require Tasker to follow along today. Tasker will run you $2.99 from the Google Play Store. For best results, I recommend using an Android 4.0+ device, and please keep in mind that some Samsung devices with S-voice do not play well with Tasker’s Voice input and text-to-speech output.

Now would also be a good time to track down an appropriate image to be used as your icon for the project. To keep it simple, here, take this one I slapped together using the Androidify app.

Androidify Christmas Lollipop

Before we go diving in, this is a rather involved project that focuses on two new concepts we’ve not touched before, and expands on another that we’ve only used in its simplest form. The project itself looks to take your voice command as an input, act on your question and by converting and comparing variables, then output an answer to your question through your device’s text-to-speech feature.

Without the technical explanation, we will be asking our Android device “how many days until Christmas?” and it will answer us out loud. Let’s get started.

How to collect voice input through Tasker

Create a new Tasker Task and name it uniquely and concisely, I’ll call mine “DaysUntilX“.

Tap the “+” button to add our first action.

Tasker Task Voice input

Choose Input.

Choose Get Voice.

You do not need to do anything here, but I find that adding a Title enhances the experience. I’ve added in “Say: how many days until Christmas.” Then hit the system Back button to save and exit.

Tap the “+” button to add a new action.

Tasker Task Voice to Variable

Choose Variables.

Choose Variable Set.

We want to create a local variable that will take the collected voice input for evaluation.

In the Name section, enter a variable name starting with the percentage sign followed by lowercase letters, I’ve called mine “%voiceinputx“.

In the To section, enter the collected voice input by typing “%VOICE“, without the “‘s, of course. You could have also tapped the labels icon and scrolled through the list to find %VOICE.

Tap the system Back button to save and exit.

Now that we have collected your voice input and saved it into a variable, lets act upon it. First things first, we evaluate the input and exit the Task if something doesn’t look, or sound, right.

Evaluate the voice input and terminate the Task if anything sounds wrong

Tap the “+” button to add your next action.

Tasker Task variable match Alert Flash Voice

Choose Alert.

Choose Flash.

Under Text, write yourself a quick message that will display if your voice input is not adequate to proceed. I simply put “Sorry, I don’t understand %voiceinputx, please try again and repeat the phrase exactly.

Now, most important, hit the “+symbol to the right of IF.

In the first text field, enter your voice input variable name, mine was “%voiceinputx“.

Tap the “~” button and choose Doesn’t Match, which will change the button to “!~”.

In the second text field, enter the exact phrase that you want used to trigger your project. I have entered “how many days until Christmas“.

It is important to note that this is a case sensitive comparison. Most of us will want all of the words to be lowercase, but capitalizing “Christmas” should still work. You may need to play with this, luckily, our flash alert will display what text it has collected if you’ve entered the variable in the Text above.

Tasker Task Alert Flash Error Message - Edited

Tap the system Back button to save and exit.

Now, if the above phrase didn’t match, we want to outright halt the Task.

Tap the “+” button to add a new action.

Tasker Task variable match Stop

Choose Task.

Choose Stop.

Tap the “+symbol beside If and repeat the input as in the above Flash Alert action. This way, if our text collected does not match the text expected, the command Stop will terminate everything that is to come.

Tap the system Back button to save and exit.

Having collected voice input and used it to evaluate whether or not to proceed with the task, we will actually no longer need it today. From here, we just want to work with variables, then respond with our answer. We have some crazy work to do with those variables, so hang on. If you find that you are struggling to understand what exactly is happening, please just follow along, I suspect you’ll find that it is easier to understand this project when everything is in place at the end.

Here is what we are going to need to do. We will need to set a variable and tell it when Christmas is. Create another variable with today’s date. Compare the two. Finally, add that value into a text-to-speech string. That almost made this sound easy, let’s do it.

Create and compare Tasker date variables

We are going to be using the same basic procedures a few times over here, so, for further reference, to create a variable, tap the “+” button to add a new action, choose Variables, then choose Variable Set.

Tasker Task Variable Set

Your first variable will be for your actual target date. In this case, Christmas.

Tasker Task Variable xmasday

Variable Name will be something like “%XMASDAY“. Note that I made it all capital letters, so that I can use this variable in other projects.

Variable To will be the date, “12-25-2014“, or whatever date you wish to work with.

Tap the system Back button to save and exit.

Create the next variable, for today.

Tasker Task Variable today

Variable Name something like “%today“. Note that this is all lowercase characters, I won’t need this variable for other projects, so I keep it local so that it deletes out of RAM when the Task is complete.

Variable To should collect the current date, which is available as a built-in variable, “%DATE“.

Tap the system Back button to save and exit.

Now we need to compare the two variables. The problem we face is that Tasker cannot do a mathematical calculation on dates, so we will need to convert the values to something that Tasker can work with, seconds.

Tap the “+” button to add a new action.

Tasker Task Variable Convert xmas

Select Variables.

Select Variable Convert.

Variable Name will be your Christmas day variable, I had called mine “%XMASDAY“.

Under Function, select Date Time to Seconds.

Under Store Result In, create a new local variable, I’ll call mine “%xmassec“.

Tap the system Back button to save and exit.

Tasker Task Variable Convert today

Now, repeat the steps for your today variable. That is, choose Variable then Variable Convert, Variable Name “%today“, Function Date Time to Seconds and Store Result In “%todaysec“. Finish up by tapping the system Back button.

Do math on variables

From here, we need to identify how many seconds difference between the two dates, then turn that into a manageable value. For each step below, we will just create a new variable for each action, I think that will help you understand the process a little easier. In a perfect world, we would just change the value of the existing variables. More on that another time.

Tap the “+” button to add another action. This will be another Variable Set action.

Tasker Task Variable Do Math to sec

Variable Name%secstoxmas

Hit the check mark beside Do Maths.

In the Variable To field, enter “%xmassec – %todaysec“.

Tap the system Back button to save and exit.

Now, we have the value in seconds, let’s create a new variable to convert to days. Basic math, really.

Tasker Task Variable Do Math to days

Variable Name “%daystox“.

Hit the check box beside Do Maths.

Variable To%secstoxmas / 60 / 60 / 24

I left the math long so it was easy to see what I was doing. Seconds divided by sixty gives minutes, divided by sixty gives hours, divided by 24, of course, gives days.

Tap the system Back button to save and exit.

Congratulations, you now have the answer of how many days it is until Christmas, or whatever you have made your target date. All there is left to do is something with that value. Here comes the text-to-speech, because, why not.

Tap the “+” button to add yet another action.

Tasker Task Say text to speech

Select Alert.

Select Say.

In the Text field enter an appropriate statement, including your final variable from above. I have entered “There are %daystox days until Christmas.

Feel free to play with the rest of the settings, if you desire, then hit the system Back button to save and exit.

Tasker Run / Play Task
That is all there is too it. I say that like this was simple. In a way it really was, just a lot of steps to get to this point. Anyhow, go ahead and tap that Task Play button in the bottom corner to test out your project. Don’t be disheartened if it does not work the first time, some tweaking may be required.

Last thing before you exit out of the Tasker Task, tap that icon button in the other bottom corner and add an image to your project, this is where that picture I gave you above comes in.

Tasker Task icon

What’s next

Of course, I have not given you a trigger for this project. You may opt to simply place a Tasker Task widget on your Homescreen. That is probably easiest. From there, if you are really into this thing, why not add it as a piece of a Zooper Widget Christmas design. Wouldn’t hurt to display the countdown right beside your clock. Then, of course, you can remove the voice input validation and simply have it read out the days remaining statement when you click it in your Zooper Widget design.

Tasker Task Say text to speech options

For bonus points, you can add extra text-to-speech commands. In this case, you would want to turn on the If parameter in each Say action. What I’ve done is create three Say actions, one that fires if Christmas is yet to come, another for when it is Christmas day and the last to gently remind me that I’ve missed the special day.

Back to the beginning of this project, we only put voice input into this project for the sake of learning how to use it. It truly does not serve the project very well. Feel free to axe it from the lineup. Tasker includes the ability to disable actions within a Task, without having to delete them. Long press on the desired action, then select the power icon that appears in the top right, or the word Disable, depending on your version of Tasker.

Tasker Task Voice Input Box

Finally, we have a little treat for you today, I’ve gone ahead and packaged up the entire project into an importable XML file. Download it to your device, then long press the Task tab header to choose Import. You’ll have to put your own icon for the project though. For your security, the download hashes as MD5 Checksum: D7B6AE1D1B1975F1DBB57948D8C82E3E

Next Week

We hope that you’ve found use for this week’s Android customization project. Please keep in mind that Christmas is just an example, this project will let you count down to any date you desire, and is good for any time of the year.

Next week, we need to take it a little easier, let’s look at methods to keep your display on longer. Yes, we touched on this subject before, using Tasker – this time out, we’ll show you what the Android OS itself can do, and how to manage those settings.

What is the best use of voice input controls you have running on your device?

You might like