how to wake and give a command to a google assistant device via API? - actions-on-google

I would like to issue a command to a google device remotely using google's api.
I have multiple google devices (Nest mini and Nest hub) that I would like to trigger a specific one by sending a request and issue a command with code.
ie.
Send request to Office's nest mini equivalent to OK Google, <something>
or
Send request to Kitchen's nest hub equivalent to OK Google, start 30 min timer
or
Send request to Living Room's nest hub equivalent to OK Google, initiate custom action
After the command is issue programmatically, the device would then behave as if the command was given in person.
I am new to Google's environment and I have not been able to find any docs that could potentially do this.

Related

give Google Assistant device commands programmatically

Is it possible to give Google Assistant commands programmatically? For example, I'd like to be able to send a command as text "turn on the fan" and have GA react as if that was the spoken command. I would also accept sending a JSON request in whatever format needed (with device IDs or whatever the API needs).
My situation is I have a ceiling fan that is controlled by Google Assistant. I want to be able to control it programmatically. For example, some event happens and my code wants to turn the fan on. Is there any way my code can tell GA to turn on the fan?
I tried using the Google Assistant SDK. I can send it text like "what time is it?" and get back text and audio, eg "It is 11:00am". However, I have a test device called "washer" and if I send text "is the washer running?" I get back "Sorry, I didn't understand". If I speak the words into my phone, I get back "The washer is running".
Why can't the GA SDK interact with my device? The credentials I give to the GA SDK are the same I use for my SmartHomeApp that defines the "washer" device.
To do this, you can setup up a virtual Assistant device and then send commands to it.
Check out Assistant Relay, which is a service that sets up a virtual Assistant device and exposes a REST API so you can send text commands to it, as if they were spoken.
Per the Documentation:
Simply send Assistant Relay any query you would normally send Google
Assistant, and Assistant Relay will call the Assistant SDK an execute
your command.
Per the problem you are having with the Google Assistant SDK, I believe what you are trying to achieve is only possible with a device, be it physical or virtual and not by using the SDK directly.
There are a lot of firewall and security issues allowing each smart device to to connect to the Internet. To alleviate this problem, Google's design methodology uses a fulfillment device as a bridge to connect to the device locally from one of their devices.
You are locally, on your smartphone, hooking into Google Assistant.
The phone is the fulfillment glue for the "washer" device.
According to this page:
Google Home or Google Nest device is required to perform the
fulfillment.
Due to the portable nature of cell phones, it does not make sense to allow one to be used as the fulfillment device remotely, hence the local hook.

What could be the reason for a Google Action with external endpoint (API) to work on the Actions Console Simulator, but not as deployed?

I am new to the whole creation-process of Google Actions.
I created an Action with the new Action Console.
It has an fulfillment endpoint to my server (as example: www.mypage.com/api).
For testing purposes it has no authentification, so it generates a public API response.
Said API generates a simple JSON response based on a send event handler.
In short: Action onEnter sends handler to API, API queries SQL database and sends the response back to my Google Action that then "speaks" the SQL result.
The result with the Actions Console Simulator is:
Testing with "Smart Display device: everything works.
Testing with "Speaker (e.g. Google Home): everything works.
Testing with "Phone": main intent is invoked and text is shown but does not get spoken.
So i tested the command "Hey Google, talk to the unicorn app" directly on my smartphone.
Here **everything works fine ** as said smartphone has the same e-mail like the one on my Action Console account: it recognizes the main invocation command and when i ask by voice to get the data, the data is received from my server and spoken.
So something is wrong with the "Phone" device in the simulator. This has been confirmed by me from other users saying that they often have trouble with the simulator function correctly.
I then deployed my Action.
It was reviewed and approved.
A few seconds later i received an auto-email saying that there were too many errors with my app, asking me to check its health status. I did so and in the Health tab, i can see that it has an error but it does not show me what the error is.
THEN I CONTACTED A ACTIONS-ON-GOOGLE EXPERT
They helped me a lot into the right direction but could not go deeper into the problem as my connection (the endpoint API) is outside of their servers.
So i ended with their tip on checking the Google Cloud Logging Console.
As said Logging Console is also new for me, i learned on how to query my results but:
How can i query for the so called "is_health_check" flag?
I am asking this because the Google Expert recommended me to search for said flag but i do not know on how to query it.
Sorry for this ultra-long entry but i am trying to be as transparent to you as possible, as i have been trying this out for several days now.
Thanks in advance for your time, ppl!
So the error is simple once that you know how Google handles the external webhooks. Thanks to the help of 2 Actions-On-Google Experts i was informed that Google pings your external Webhook from time to time.
As soon as they get an error as result from said ping, the Action will be deactivated from the Assistant until a new ping response sends that everything is fine again.
My problem was that after deploying the action and while it was under reviews, i continued to work on the code on my server. While coding, the Google server pinged and received an error code.
My fault, but at least i learned the thing about pinging your action!

Is it possible to retrieve the configured rooms/locations in the fulfillment service?

I have been experimenting with Google Smart Home and the protocol flow looks very clear for me. In summary:
action.devices.SYNC - sent by Google Smart Home to fulfillment service to find out the available devices
action.devices.EXECUTE - sent by Google Smart Home to fulfillment service to execute a certain action on a device
On the smartphone/tablet, the customer can place a device in a certain location. This allows him to ask questions such as Turn everything in my office off. Internally, Google Smart Home knows which devices are located in the office, and sends a action.devices.EXECUTE action for each device in the office subsequently, as explained above.
I am now wondering about the following: is it possible to retrieve the configured locations/rooms in the fulfillment service also? Is this information exposed and available to retrieve?
It is not possible to receive information about a user's home layout through the Home Graph API. When the user gives a command like "Turn everything in my office off", you may get several OnOff commands in your fulfillment, although you will have no way of knowing the original query.

Can I turn data in google assistant app into file format for upload?

I am creating an app for google assistant which will collect data while a user plays a game and then send that data to a project database. The API I am using to sent the data (synapse) requires it to be in file format, however, I can't find a way to create a file for the data due to the nature of google assistant apps. Am I overlooking a way to do this/is there a way to get around this and send the data somewhere else to make it into file format? The data is stored in a JSON object.
The conversation that your users have with your Action will be relayed from their Assistant device (such as Google Home) to Google's servers, which do a little processing, and then to your server. Your server is then responsible for sending back a reply to Google's servers, which sends it on to the Assistant device. This is very similar to how a web browser and server work, and for good reason - your server accepts commands via a "webhook", which is just a fancy way of saying that Google's servers contact your server via HTTPS, and you're sending back a reply via HTTPS.
Your webhook can do anything - as long as it does it fast enough. You can store what command the person has issued and either aggregate a number of them into a file format to send, or send each one.
Your Action does not, itself, run on the user's device any more than a web page with a form "runs" on the user's device. It displays there, just like your Action is read out loud... but almost all interaction is sent back to you with minimal processing on the device itself.

Google Channel API - How to test it locally?

I want to test my application which share messages between two users using google channel api, but I manage to see messages going only from one side to the other.
is it because I'm opening 2 channels on the same machine? I am running the application on different browsers (Chrome and IE) and each one logged in with a different user name? shouldn't that be enough?
Any suggestion on how to test my application on a single PC, or must I connect another PC for such application?
Thanks
Muky.
You surely can test Google Channel API on a single machine. (I've done it, it works). Note that, when I run it on my local machine, I see the browser makes continuous requests (polling) although, when I upload it to Google App Engine, I only see push notifications. (You can check out the requests using Firebug in Firefox - in the NET tab). As far as I understand, Channel API is simulated in local mode using polling whereas, when uploaded to Google App Engine, they make use of Comet (not polling, rather long-lived requests).
I don't think your case was a browser issue. Each logged in user should open one channel. Then when you want to send a message to every users, you should send a message to each id that's logged in.