Use Contexts in Natural Voice Commands

Learn how to set contexts for your natural voice commands to control which intents trigger

  1. joaomgcd
    In this example we're going to put the user's current location in context so that you can query that location with a natural language command.

    For example, you could update your location each time you got home or to work and then someone could ask your Google Home where you were and it would know if you are at home or at work.

    STEP 1 - SET HOME CONTEXT


    • Create a new Tasker task called Set Home Context
    • Add an AutoVoice Natural Language Context Tasker action
    • Under Contexts set Context Name to location
    • Set Field Names to current
    • Set Field Values to home


    STEP 2 - SET AWAY CONTEXT


    • Copy the AutoVoice Natural Language Context action you just added
    • Create a new Tasker task called Set Away Context
    • Paste the action you copied
    • Change the Field Values value to away under Contexts


    STEP 3 - CREATE INTENT IN AUTOVOICE


    • Open AutoVoice -> Natural Language -> Commands
    • Add a new command
    • Add a bunch of phrases that you would like to use for this like where am I or what's my last location
    • Set the response to Your current location is #location.current
    • Optionally change the name and action of the intent but you can keep it as it is
    (i) The # sign lets you access the input context. In this case we want the response to include the location from the context so we access #location and then the current field inside that, so we add .current. Remember that you set the current field in the Tasker action before to either home or away so this is what it'll contain here.


    STEP 4 - SET CONTEXT AND OUTPUT VARIABLE


    Because you'll probably want to use this in Tasker as well and want to have easy access to the current location there it's better if you create an output variable with the value.

    • Create a new parameter with the name currentlocation
    • Set the type to Any
    • Set the value to #location.current (remember that this will contain your current location from the context)
    (i) This will create a new variable in the natural language command that you can then use in Tasker with the name %currentlocation


    STEP 5 - TEST


    If you now set the context to home and say the where am I? command you'll see that you'll get a new natural language command trigger with the currentlocation variable set to home. If you set it to away you'll get that in the variable :cool:
    Note that if you hadn't done step 4 above you wouldn't get back a variable to use in Tasker, but the voice command response would still contain your current location.