Google Home - Actions (API) now available!

Thanks for the info… I have been wondering that very thing since watching this thread for some time. I have just bought a home mini and would like to use it with Openhab but I don’t want to connect to any cloud services… although of course you need to connect to google itself. I’m in Australia, and the latency to US servers is a consideration, and the more intermediaries I have to use the slower it gets.

Have you created, or is there otherwise documentation on how to do the method you describe?

First, let’s talk security. To be safe, you need at least 2 routers/switches. The openhab-cloud/openhab-google assistant will seat behind your modem/router with the necessary ports opened. Your openhab server seats behind the second router, no port opened.

  1. install openhab-cloud first
  2. deploy openhab google assistant afterwards on the same machine

When you say “second router”, what exactly do you mean? I have a single router (gateway) that my openhab/raspi sits behind.I haven’t installed openhab-cloud (in fact I dont even know what that is) but I can do so if its required. I have port forwarding on my router for incoming OH connections.

actually… minor correction… my OH is running on a Pine64, not the raspi.

That’s good. You are able to configure everything.

I have an issue with Assistance account linking. I have provided endpoint as https://< cloud host >/oauth/authorize and error reported as Cannnot GET /oauth/authorize. Dont know how to enable oauth service on openhab cloud instance. Please suggest if any step missing

What does “Cannnot GET /oauth/authorize” mean?

What do your openhab-cloud logs say? What about the openhabassistant function logs?

The more info the more helpful we can be.

What code changes and how do you deploy openhab-google-assistant locally?

Got something you can share? I have noticed a bit of latency, but I have a hard time imagining hosting it locally would improve many things. I’d love to be wrong though.

in the attaed image there’s my error message after oauth

Is there any guide in the net in order to set it up completely from scratch? Would be extremely appriciated!

Configured openhab-google-assistant with help of link https://github.com/openhab/openhab-google-assistant. Also, openhab AWS cloud instance configured as per link Githhub README.md

Checked openhab cloud logs and there is nothing for “Cannnot GET /oauth/authorize”. Logs as below

2018-01-30T08:23:31.132Z - debug: openHAB-cloud: Checking for offline openHABs (0)
2018-01-30T08:23:31.132Z - debug: openHAB-cloud: Checking orphaned rest requests (0)
2018-01-30T08:24:31.188Z - debug: openHAB-cloud: Checking for offline openHABs (0)
2018-01-30T08:24:31.189Z - debug: openHAB-cloud: Checking orphaned rest requests (0)
2018-01-30T08:25:00.452Z - info: openHAB-cloud: every5min statistics collection job started
2018-01-30T08:25:00.457Z - info: openHAB-cloud: every5min statistics collection job finished
2018-01-30T08:25:31.217Z - debug: openHAB-cloud: Checking for offline openHABs (0)
2018-01-30T08:25:31.217Z - debug: openHAB-cloud: Checking orphaned rest requests (0)
2018-01-30T08:26:31.277Z - debug: openHAB-cloud: Checking for offline openHABs (0)
2018-01-30T08:26:31.277Z - debug: openHAB-cloud: Checking orphaned rest requests (0)
2018-01-30T08:27:31.326Z - debug: openHAB-cloud: Checking for offline openHABs (0)
2018-01-30T08:27:31.327Z - debug: openHAB-cloud: Checking orphaned rest requests (0)
2018-01-30T08:28:31.374Z - debug: openHAB-cloud: Checking for offline openHABs (0)
2018-01-30T08:28:31.374Z - debug: openHAB-cloud: Checking orphaned rest requests (0)
2018-01-30T08:29:31.430Z - debug: openHAB-cloud: Checking for offline openHABs (0)
2018-01-30T08:29:31.430Z - debug: openHAB-cloud: Checking orphaned rest requests (0)
2018-01-30T08:30:00.463Z - info: openHAB-cloud: every5min statistics collection job started
2018-01-30T08:30:00.471Z - info: openHAB-cloud: every5min statistics collection job finished
2018-01-30T08:30:31.461Z - debug: openHAB-cloud: Checking for offline openHABs (0)
2018-01-30T08:30:31.462Z - debug: openHAB-cloud: Checking orphaned rest requests (0)

Also checked nginx openhab-cloud.org-access.log as below but no error
80.213.114.104 - - [30/Jan/2018:06:34:47 +0000] “GET / HTTP/1.0” 400 682 “-” "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"
54.183.171.240 - - [30/Jan/2018:06:51:47 +0000] “GET / HTTP/1.1” 200 3504 “-” "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 S$
115.110.104.225 - - [30/Jan/2018:07:54:40 +0000] "GET /oauth/authorize?response_type=code&client_id= &redirect_uri=ht$
115.110.104.225 - - [30/Jan/2018:07:54:41 +0000] “GET /favicon.ico HTTP/1.1” 200 2180 "https://< host >/oauth/authorize?response_type=code&client_id=
115.110.104.225 - - [30/Jan/2018:08:27:37 +0000] "GET /oauth/authorize?response_type=code&client_id=< Id >&redirect_uri=ht$

Please suggest anything missing or need to check

This oauth issue has been resolved. Its my bad - in url added /oauth/ instead of /oauth2/

However, another issue still not resolved. Local openhab running on Raspberry pi is not connecting to my cloud instance but it can connect to myopenhab.org instance. Please suggest.

Have you set the openHAB cloud addon to point your myopenhab cloud instance? If not, do that.

Yes I did that. Whenever change the host name from OH cloud to my OH cloud host., log shows that “Shutting cloud service…” but no more logs to connect to my host. However, when I changed from my OH cloud host to myopenhab.org host then I can see logs that indicating “Shutting cloud instance” and “Connecting to myopenhab.org with client id …”

So openHab could addon configuration in place

I’m just going to list some the basic things I can think of, maybe it will help.

  • https?
  • account on your own instance with correct uuid and secret?
  • restart raspberry?

You want the highest level of security for your home network with your connected devices. Since installing openhab-cloud will require opening some ports, move your home network with your openhab server behind a second router.

You have to let openhab google assistant call backs go through openhab-cloud: some additions are needed to openhab-cloud routes. To make make your life easier with the code change, you deploy openhab google assistant under openhab-cloud directory. With this setup, do the following changes with the openhab-cloud:

file ./routes/index.js
add var googleassistant = require(’…/googleassistant/functions/index’);
add to function Routes.prototype.setupRoutes : this.setupGoogleAssistant(app);
add new function:
Routes.prototype.setupGoogleAssistant = function (app) {
// Google Assistant backend
app.all(’/openhabGoogleAssistant’, googleassistant.openhabGoogleAssistant);
};

file ./app.js
replace:
if (!req.path.match(’/rest*’) && !req.path.match(’/oauth2/token’) && !req.path.match(’/ifttt/’))
with:
if (!req.path.match(’/openhabGoogleAssistant
’) && !req.path.match(’/rest*’) && !req.path.match(’/oauth2/token’) && !req.path.match(’/ifttt/*’))

Anyone interested in Thermostat functionality take a look at this PR and review. I would not add as it requires a few fixes. [NEW 1/31/2018] Also, works with CurrentTemperature only, but you need to add Temp Unit (e.g. Fahrenheit) in the item.

  • Celsius: Currently all my devices report in Fahrenheit so I have no basis for testing this (one function - isEventFahrenheit - was sending to utils folder with what looks like an Alexa skill function so I revised)
  • [FIXED 1/31/2018] Thermostat Group parsing: I did not have the coding ability to parse efficiently so it is currently set in order in the .items file:
  1. Thermostat Group
  2. Mode (String)
  3. Current Temp (Number, %.1f) - No more than 1 decimal!
  4. Setpoint Temp (Number, %.1f) - No more than 1 decimal!
  • Mode [FIXED 1/31/2018]: I only have hydronic baseboard heating, no central air so I only have one mode: Heat. I think I had some more user-side issues so I think a few of my changes to the mode section could be stepped back

Please take a look at the pull and feel free to comment, just looking to advance this as much as possible and contribute where I can!

[EDIT]: For troubleshooting your logs:
Traits: Cloud-to-cloud  |  Google Home Developers
DeviceTypes: Cloud-to-cloud  |  Google Home Developers

The SYNC Validator is invaluable, just paste your code in and it will check the JSON, then you can trace through your code.

Thx,
Ryan

1 Like

I think you might be missing the scope in mongodb, see @MARZIMA previous post on this

The fact that you are getting your OH-Cloud instance on the Home App means you are almost there…

I don’t think so. My line of thinking was, why not have a openhab-cloud with integrated google assistant back-end functionality? My personal rational was also that I didn’t have another pi lying around and that I was too lazy to setup another node.js environment for openhab google assistant.

Since I can’t post more than 3 posts, here are some additional info for the other members I cannot respond to:

  • After you have successfully installed openhab-cloud, encapsulated it with pm2 process manager. Since openhab google assistant is logging to the console, you will be able to debug using pm2 logs . This will also add the benefit of being able to automatically launch openhab-cloud when you reboot the server.

  • The account linking on Google Actions should look like this:

Authorization URL : https:// youropenhab-cloud/oauth2/authorize
Token URL : https:// youropenhab-cloud/oauth2/token

  • The action.json that you upload to Google should look like this, after you have enabled the openhabGoogleAssistant route in your openhab-cloud instance:

{
“actions”: [{
“name”: “actions.devices”,
“deviceControl”: {
},
“fulfillment”: {
“conversationName”: “automation”
}
}],
“conversations”: {
“automation” :
{
“name”: “automation”,
“url”: “https:// youropenhab-cloud/openhabGoogleAssistant”
}
}
}

  • Finally, the file functions/config.js of your openhab google assistant (that you deployed under your openhab-cloud instance) should look like this:

module.exports = {
//userpass: ‘user@foo.com:Password1’,
host: ‘youropenhab-cloud’,
port: 443,
path: ‘/rest/items/’,
};

  • a few comments; since everything runs locally, a little bit more performance could be squeezed out by replacing https protocol with regular http between openhab, openhab-cloud and openhab google assistant.
  1. in openhab, the openhab-cloud binding can use a local address : http://192.168.x.x:3000/
    Note that we use http, not https; also openhab-cloud is listening on port 3000 with default installation.

  2. The openhab google assistant file functions/config.js becomes:

module.exports = {
//userpass: ‘user@foo.com:Password1’,
host: ‘localhost’,
port: 3000,
path: ‘/rest/items/’,
};

  1. in the openhab google assistant file functions/rest.js, replace all occurrences of the word https with http

A few more comments:

  • The Google Home app is buggy, so even if you got everything right, the initial synching may still not work. If this is happens:
  1. Authenticate a second time and click on ‘Allow’
  2. If the Google app forwards you a second time to the allow/deny page, do not click on ‘Allow’ a second time. Just close the window.
  3. If this still doesn’t work, try to delete the cache of the Google app and do the synch again
  • Google is still playing catch up with Amazon; you won’t be charged for testing… for know. When they change their policy, just switch to another ASR provider. Or even better, run your ASR locally, I have been playing with a few ones recently. Performance and user experience is still so-so… so sticking with Google ASR for now.

Sorry for the dupe post @atzat, I will just leave the below link which helps with OH Cloud setup below…

while you’re fixing your OAuth links don’t forget to setup your “google-assistant” scope, then make sure it’s in mongodb (look up through the posts if you don’t know what that means) :wink:

This is also a good resource if you get hung up on the https (I used the letsencrypt…its free…easy, etc.)

do you mean that google action is “not” part of cloud service?

the google action we uploaded won’t be charged when running?

Thanks.