Request any Info From Your Phone Like Battery Level, Unread Notifications, etc

Workaround for getting data from your phone into a voice response on Google Home or Amazon Echo

  1. joaomgcd
    At the end of this tutorial you'll be able to do something like this:

    Because of the way responses on Google Home and the Amazon Echo work, there's no way to directly get a value from Tasker and reply with it right away when saying a voice command. In other words, there's no way to do this:
    • You: Alexa, ask AutoVoice what's my phone's battery level?
    • Alexa: It's at 66 percent
    Using this workaround you'll get close though. It'll go like this:
    • You: Alexa, ask AutoVoice what's my phone's battery level?
    • Alexa: Checking now. Please say "check results" to get your battery level
    • You: check results
    • Alexa: It's at 66 percent
    It's an extra interaction but this way you'll be able to get any info you want from your phone!

    In short, this is how it'll work:
    • Create a command that triggers with the check battery level command
    • This command will set the status of your battery in a natural language context
    • Create a command that is only triggered when that natural language context exists
    • Have that 2nd command respond with the battery level

    STEP 1 - CREATE "CHECK BATTERY" COMMAND


    • In AutoVoice go to Natural Language -> Commands and create a new command
    • Set the commands to something like what's my phone's battery level
    • Set the response to something like Checking now. Please say "check results" to get your battery level
    • Accept the command with its default name and action


    STEP 2 - MAKE COMMAND NOT FINISH CONVERSATION


    • Click on the command you just created and then Toggle Finish Assistant Conversation
    • Make it not finish the conversation
    (i) This part is crucial if you don't want the assistant to exit AutoVoice after it says that it's checking your battery level. If you don't do this step you'll have to say "alexa ask autovoice to check results" again. By doing this you can just say "check results" right away.


    STEP 3 - CREATE TASK TO SET THE BATTERY LEVEL CONTEXT


    • Create a new Task in Tasker and call it Set Status Context
    • Add a Flash action and write Setting Status Context: %par1
    (i) %par1 will contain the status you want to set. In this case it'll contain the battery level. Because we want to make this task usable in various scenarios (getting battery level, getting unread notification count, etc) we'll make it receive a parameter instead of just hard-coding the battery level here. More on that later.
    • Add an AutoVoice Natural Language Context action
    • Set the Contexts -> Context Name field to status
    • Set Field Values to text
    • Set Field Values to %par1
    (i) This will create a context in natural language called status which will contain a field called text with the value of whatever is passed as a parameter to this task, which will be the battery level. More on contexts here.


    STEP 4 - SET THE BATTERY LEVEL STATUS AFTER VOICE COMMAND


    • Create a new profile in Tasker with the AutoVoice Natural Language event condition
    • Select the command you created before from the list
    • Accept and create an entry task for the profile
    • In the Task use a Perform Task action
    • Set the Name field to Set Status Context
    • Set the Parameter 1 field to your battery is at %BATT percent
    (i) This will call the task we created before and sets its first parameter to your battery is at %BATT percent. This will make %par1 be set to that in the Set Status Context task which will make the Natural Language Context be set to that in that task.


    STEP 5 - CREATE COMMAND TO CHECK RESULTS


    • In AutoVoice create a new natural language command
    • Set the commands to something like check results
    • Set the response to exactly this: #status.text and create the command
    • Click the created command and choose Input Contexts
    • Set the Input contexts to status
    (i) By setting the input context to status you make sure that this command will only be triggered if a context with that name exists. Then in the response you access this context by its name with #status.text. text is the name of the field inside that status. This context is created in step 4 above after the user asks about his battery level.

    In short, after the user asks about the battery level the status is set with the text: your battery is at %BATT percent so this command will trigger!


    STEP 6 - REMOVE CONTEXT


    (i)Since you already heard the results of your battery request you can now remove the context so you don't end up with old contexts

    • Create a new profile in Tasker with the AutoVoice Natural Language event condition
    • Select the command you created in the previous step
    • In the task add an AutoVoice Natural Language Context action
    • Set the Context Name to status again but this time enable the Delete option to remove the context.
    • Back out of Tasker to save.



    If you now ask Alexa or Google Home about your battery level you'll be asked to say "check results" and after that you'll hear your phone's battery level!

    STEP BONUS - CHECK UNREAD NOTIFICATION COUNT


    (i) We can now easily re-use this setup for any other data we may want to retrieve from our phone. In this extra example we're going to get the unread notification count but you can do this with whatever info you want!

    • Create a natural language command like before but this time with the command what's my unread notification count
    • Make sure to make that command not finish the conversation on your assistant
    • In Tasker create a profile with that command
    • In the task use AutoNotification Query to get your current non-persistent notifications
    • In the task call the Set Status Context task and set Parameter 1 to you have %antitle(#) unread notifications
    (i) %antitle(#) will be replaced by the number of titles of notifications you have on your phone. You could have used any other AutoNotification variable like %antext, %anid, etc
    • Back out of Tasker to save


    If you now test this new command something like this will happen: