You can use this task to send commands even with the screen off. However, the assistant will need to be able to listen to your phone actually say the command, while the screen is off, so it may not be convenient in all situations.
If that's not convenient for you, use the process below.
Disclaimer: This task will work in these conditions:
This is how it'll look like in the end:
- Android 6: your screen needs to be on
- Android 7 or 8: your screen needs to be on or smart lock needs to active while the screen is off.
- It will take over your screen for a few seconds while the command is being sent.
If you're ok with these conditions you may proceed
STEP 1 - UNLOCK SCREEN AND START VOICE COMMAND
Make sure that your device has smart lock enabled or that your lock screen doesn't have any security or else the screen unlocking will fail
- Create a new Task called Assistant Command
- Add an AutoInput Unlock Screen action and click the configure button to accept it.
- Add a Voice Command action to start the Google Assistant in Voice Mode
- To test it out add a 3 second Wait action at the start of the task
- Test it and check that voice recognition starts in the Google Assistant
- Test it again with the screen off and check that it still works.
STEP 2 - WRITE THE COMMAND AND SEND IT
If Google Assistant is in a different language for you Type mode will probably appear in your language.
- Add an AutoInput Action and use Easy Setup
- Bring up the Google Assistant, click the Add button in the AutoInput notification and then click on the little keyboard icon on the bottom right. This will make AutoInput detect which button that is so it can click it.
- In AutoInput select the Type mode option followed by the Click action
Due to a bug in the currently released AutoInput clicking Write right away won't make it accept the Write option, so first select Click and then Write. I'll try fixing this issue.
- Add another AutoInput Action and use Easy Setup again
- Bring up the Google Assistant, click on the little keyboard icon on the bottom right, click the Add button in the AutoInput notification and then click the input box on Google Assistant. This will make AutoInput detect the input box so it can write in it.
- In AutoInput select the Type a message option followed by the Click action
- Under Action select Write
- Under Text To Write write Broadcast hello world
- Repeat the whole Easy Setup process again but now for the send button in the Google Assistant
- Test the task and it should now open the assistant, write the text and send the command
STEP 3 - BACKING OUT OF THE ASSISTANT
- Add 2 AutoInput Global Actions with the Back action selected
- Because the assistant doesn't like it if you back out too fast add a 1 second wait action between these 2 back actions
- Test the task again. It should now send the command and then leave you right where you were.
- You can probably see that it backs out too early and the command doesn't have time to process, so add a 3 second wait action before the first back action
STEP 4 - SEND COMMAND FROM ANYWHERE IN TASKER
This is just for testing purposes so you can test the task by running it directly. %par1 will normally be a parameter sent from a different task. This way the command sent to Google Assistant is dynamic and can be easily sent from any task
- Add a Variable Set action as the first action and set %par1 to Broadcast hello world if it's not already set
- Change the action where AutoInput writes text in Google Assistant so that it writes %par1 instead of Broadcast hello world
- Create a new task called Test Assistant
- Add a Perform Task action
- Choose to perform the Assistant Command task that you created before
- Under Parameter 1 write anything you want to send as an assistant command
- Back out of Tasker to save both tasks
- Open the Test Assistant task again and run it to see that it sends the command passed as the parameter
You can now perform an assistant command any time you want to in any Tasker task!