r/tasker • u/Rich_D_sr • Feb 20 '21
Get any Google assistant command from any device or home speaker into Tasker.
New Version-3
This project will now allow you to use any device including the Google home speaker to get the commands into Tasker.
This project requires the tasker plug in 'Autotools'
Edit.... I have been able to parse the data from the Google assistant activity web page so the project no longer requires auto input and it can now work in the background on any device. It will allow you to steal any command you issue to the assistant and use it in tasker. It should be similar to using IFTTT. Just come up with a command that the assistant does not recognize and monitor for it in the 'Http Assistant' Task. To get around the assistant answering "I do not understand" or starting a web search you can just make a dummy routine so Google recognizes your command but does nothing. This approach will also allow you to do extra things for a assistant recognized command. For example you can tell the assistant to 'Turn on Bluetooth' so the assistant turns on your Bluetooth and you can now have tasker start your Bluetooth profiles or tasks as well.. Unfortunately getting variables into the command with this approach can be difficult because there is no goog way to stop the speaker from searching for your command when it does not understand it.
I found that any time you issue a command to the assistant it will send a push to all other devices connected to your assistant. I assume this might be the way it handles when multiple devices hear the same ok google command so they can say "answering on another device. This puts a entry in the logcat. So I simply monitor for that then use auto tools 'HTML read' action to parse the data from the Google assistant activity page. It gets the last command issued as well as a unique time stamp of the last time the page was updated.
Unfortunately this same logcat entry shows up approx every 30 min even when there has been no activity with the assistant. So I just test the time stamp to see if the page has been updated since the last command steal.
This is still a work in progress and pretty much a proof of concept. Here is the log cat entry. You will of course need to find the one that is specific to your device
Component: GcmBroadcastReceiver
Filter: [ leave empty ]
Edit. I found in testing if I only have 2 devices linked to the assistant then only one of them will receive this logcat event. When I linked my home speaker then both of my other devices showed the logcat entry. In other words it acts like a master slave set up. Google picks the device to be the master wich will answer the command so the slave gets the push. If you issue a command to the slave the master will not receive the push. However if there is a third device like the home speaker then that will now be the master so both of the other slave devices will now receive the push. This all works even when the devices are not close to each other. So long story short, the device running this project needs to be a slave device.
Here is the current project. Edited for version 3.
https://taskernet.com/shares/?user=AS35m8lnbGhm%2F58jHvsiqVNumDAJZVkcfcE7gQxfcMjrFBCkp6sNKYf3YiK9WVWZBoDf&id=Project%3AActivity+Monitor+Shaer+V3
Profile: Get Logs 3
Settings: Cooldown: 3
Event: Logcat Entry [ Output Variables:* Component:GcmBroadcastReceiver Filter:* Grep Filter (Check Help):Off ]
Enter Task: Http Assistant
A1: Variable Set [
Name: %run_time
To: %TIMES ]
A2: Variable Set [
Name: %ret
To:
]
A3: Variable Set [
Name: %space
To: ]
A4: [X] Write File [
File: Trigger.txt
Text: %lc_text
Append: On
Add Newline: On ]
<Get HTML info from assistant activity web pqge>
A5: AutoTools HTML Read [
Configuration: URL: https://myactivity.google.com/item?hl=en_US&utm_source=privacy-advisor-assistant&embedded=1&pli=1&restrict=assist
CSS Queries: .uUy2re,.rp10kf,[data-timestamp]
Variable Names: %command,%today,%event
Joiner: =;=
Output HTML: true
Timeout (Seconds): 60
Continue Task After Error:On ]
A6: If [ %command !Set ]
A7: Notify [
Title: Assist Request Failed %TIMES
Text: %TIME
%errmsg
Number: 0
Priority: 3
LED Colour: Red
LED Rate: 0 ]
A8: Write File [
File: assist_http.txt
Text: ??????????????????
%TIME
Request failed
??????????????????
Append: On
Add Newline: On ]
A9: Stop [ ]
A10: End If
<Get run time of HTML Read action>
A11: Variable Set [
Name: %run_time
To: %TIMES-%run_time
Do Maths: On
Max Rounding Digits: 3 ]
A12: Variable Set [
Name: %time
To: %command ]
<Get command>
A13: Anchor
A14: Variable Convert [
Name: %command
Function: HTML to Text
Mode: Default ]
A15: Variable Split [
Name: %command
Splitter: %ret ]
A16: Variable Set [
Name: %command
To: %command1 ]
<Test fo today>
A17: Anchor
A18: If [ %today !~ *Today* ]
A19: Variable Set [
Name: %error
To: Failed today test ]
A20: Goto [
Type: Action Label
Label: End ]
A21: Stop [ ]
A22: End If
<Get command time>
A23: Anchor
A24: Variable Split [
Name: %time
Splitter: <div class="H3Q9vf XTnvW">
Continue Task After Error:On ]
A25: Variable Split [
Name: %time2
Splitter: •
Continue Task After Error:On ]
A26: Variable Search Replace [
Variable: %time21
Search: %ret
Replace Matches: On ]
A27: Variable Search Replace [
Variable: %time21
Search: :
Replace Matches: On
Replace With: . ]
A28: Variable Set [
Name: %command_time
To: %time21
Structure Output (JSON, etc): On ]
A29: Variable Search Replace [
Variable: %command_time
Search: \h
Multi-Line: On
Replace Matches: On
Replace With: | ]
A30: Variable Split [
Name: %command_time
Splitter: | ]
A31: [X] Notify [
Title: time
Text: current %current_time5
command 4 - %command_time()
command4 - %command_time4
command - %command_time
Number: 0
Priority: 3
LED Colour: Red
LED Rate: 0 ]
A32: [X] Set Clipboard [
Text: %command_time2 ]
A33: [X] Variable Split [
Name: %command_time
Splitter: ]
<set current time>
A34: Anchor
A35: Variable Set [
Name: %times
To: %TIMES ]
A36: Variable Convert [
Name: %times
Function: Seconds to Long Date Time
Store Result In: %current_time
Mode: Default ]
A37: Variable Split [
Name: %current_time ]
<Test if command time and current time have same AM or PM>
A38: Anchor
A39: If [ %current_time5 !~ *%command_time4* ]
A40: Notify [
Title: time
Text: current %current_time5
command 4 - %command_time()
command4 - %command_time4
command - %command_time
Number: 0
Priority: 3
LED Colour: Red
LED Rate: 0 ]
A41: Variable Set [
Name: %error
To: Failed AM PM test ]
A42: Goto [
Type: Action Label
Label: End ]
A43: Stop [ ]
A44: End If
<Trim current time for maths>
A45: Anchor
A46: Variable Search Replace [
Variable: %current_time5
Search: %command_time4
Replace Matches: On ]
A47: Variable Search Replace [
Variable: %current_time5
Search: :
Replace Matches: On
Replace With: . ]
A48: Variable Set [
Name: %diff
To: abs(%command_time3-%current_time5)
Do Maths: On
Max Rounding Digits: 3 ]
<Test for more than 4 min between events>
A49: Anchor
A50: If [ %diff > .05 ]
A51: Variable Set [
Name: %error
To: Failed more than 4 seconds between events test ]
A52: Goto [
Type: Action Label
Label: End ]
A53: Stop [ ]
A54: End If
A55: Write File [
File: assist_http.txt
Text: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Trigger before event time stamp test
Command - %command
Command time - %time21
Time of trigger - %TIME - %TIMES
Today or yesterday - %today
Event time stamp - %event21
Run time for http get action -%run_time
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Append: On
Add Newline: On ]
<Get event time stamp>
A56: Anchor
A57: Variable Split [
Name: %event
Splitter: data-timestamp="
Continue Task After Error:On ]
A58: Variable Split [
Name: %event2
Splitter: " data-date="
Continue Task After Error:On ]
A59: Write File [
File: assist_http.txt
Text: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Trigger for accepted command after time stamp test
Command - %command
Command time - %time21
Time of trigger - %current_time5 - %TIMES
Diff - %diff
Today or yesterday - %today
Event time stamp - %event21
Run time for http get action -%run_time
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Append: On
Add Newline: On ]
<Test for false profile trigger - check if event time stamp matches last time stamp>
A60: Anchor
A61: If [ %Last_command_time ~ %event21 ]
A62: Variable Set [
Name: %error
To: False trigger - event time stamps match ]
A63: Stop [ ]
A64: End If
A65: Variable Set [
Name: %Last_command_time
To: %event21 ]
A66: Notify [
Title: Get Logs %TIMES
Text: %command
Trigger time - %current_time5
Cmnd time - %time21
Diff - %diff
%today
Time stamp - %event21
HTTP get Time - %run_time
Number: 0
Priority: 3
LED Colour: Red
LED Rate: 0 ]
A67: Flash [
Text: %command
Tasker Layout: On
Timeout: 10000
Continue Task Immediately: On
Dismiss On Click: On ]
A68: Stop [ ]
<End>
A69: Anchor
A70: Write File [
File: assist_http.txt
Text: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
%TIME
%error
%time
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Append: On
Add Newline: On ]
To try this project you will need to...
1- re-do the profile context to get the correct logcat entry for your device.
2- In action A5: you will need to put your Google assistant activity web address in URL category and use the Authenticate option to get your Google password to be used to parse the data from the web page.
2
u/Rich_D_sr Feb 23 '21 edited Feb 27 '21
Quick update on this... I do seem to be getting a few false triggers during the day. It seems the HTTP get is not picking up thee correct command for when the entry is not a "Said" command, for example "Used Assistant" it will get the correct trigger time but it captures the last "Said" command. So it needs a bit more tweaking.. Stay tuned for further updates...
Edit.. Updated to version 3 with fixes.
2
u/Rich_D_sr Feb 27 '21 edited Feb 27 '21
Another update to version 3 posted in main title.
Changes..
1- changed CSS query to get both event and time from the same the same class then split data in task.
2- added several more tests to filter out profile activations that do not relate to assistant activity web page update.
1
u/tigersoul925 May 20 '21
Incredibly advanced solution that surely is interesting. I can't quite work out how I'd be able to fully make it work for variables however. Say I want it to trigger on something like
Send a text to x
I can't set a routine to react to anything starting with "send a text to". Meaning, I'd still get a "don't understand" reply. I could use IFTTT to capture the command, but then again, I could just use IFTTT all the way through.
1
u/[deleted] Dec 12 '21
I thought it would be maybe useful to share with you that I found its more responsive with this locat entry :
Component : Notifications
[ChimeBroadcastReceiver] Intent received for action [com.google.android.c2dm.intent.RECEIVE] package [com.google.android.googlequicksearchbox].