Reputation: 3
I want to create a smart home app Google Home using Actions SDK. As it is now, I have a cloud server and its OAuth 2.0 API and some real IOT devices, all the cloud environment is prepared. When I 've browsed the document of Smart Home, I feel confused, I edit a json file and upload it to my google project with gaction, and isn't done? If it is, How to handle the response json of SNYC,QUERY and EXECUTE? Thanks a lot.
Upvotes: 0
Views: 544
Reputation: 11978
In the Actions on Google console for your project, there should be a webhook field. You put the URL that the HomeGraph will call. In your webhook, you'll receive a JSON payload that contains the intent
and other parameters for you to handle.
let reqdata = request.body;
let input = reqdata.inputs[0];
let intent = input.intent;
switch (intent) {
case "action.devices.SYNC":
console.log('post /ha SYNC');
// Do sync
break;
case "action.devices.QUERY":
console.log('post /ha QUERY');
// Do query
break;
case "action.devices.EXECUTE":
console.log('post /ha EXECUTE');
// Do execute
break;
default:
response.status(401).set({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type, Authorization'
}).json({error: "missing intent"});
break;
}
You should return a JSON payload as a response.
The actual way to adjust your IoT device is entirely dependent on your server and device implementation.
You can check out the sample project to figure out a bit more.
Upvotes: 2