Page 7 of 15

Re: Domoticz to Google Assistant integration

Posted: Wednesday 13 November 2019 7:21
by DewGew
BazsoDombiAndras wrote: Wednesday 13 November 2019 1:24 Hi All!

First of all, thank you DewGew for this Python server, looks like a very promising project!

I'm trying to set it up, but I'm stuck on setting the URLs as per the instructions:

Code: Select all

Navigate back to the Actions on Google Console.

On the top menu click Develop, then on the left navigation menu click on Actions.
Enter the URL for fulfillment, e.g. https://<YOUR REVERSE PROXY URL>/smarthome (replace with your actual URL), click Done.
On the left navigation menu under Account Linking.
Select No, I only want to allow account creation on my website. Click Next.
For Linking Type, select OAuth.
For Grant Type, select Authorization Code for Grant Type.
Under Client Information, enter the client ID and secret from earlier.
Change Authorization URL to https://<YOUR REVERSE PROXY URL>/oauth (replace with your actual URL).
Change Token URL to https://<YOUR REVERSE PROXY URL>/token (replace with your actual URL).
Let's say that the Domoticz Python server is running on 192.168.0.200:3030
I have an Apache reverse proxy and I have set up some redirects like:
domoapp.mydomain.com -> 192.168.0.200:3030/smarthome
domoappoauth.mydomain.com -> 192.168.0.200:3030/oauth
domoapptoken.mydomain.com -> 192.168.0.200:3030/token

The problem is that the above links don't even work on the local server, I mean if I enter 192.168.0.200:3030/smarthome into a browser, I get "not supported". If I enter 192.168.0.200:3030/oauth into the browser, I get "response_type must equal "code". If I enter 192.168.0.200:3030/token into the browser, I get "Page not found!: '/token'".

Could you please clarify what the proper target URLs are on the local server for the smarthome, oauth and token endpoints that need to be specified to Google? I mean what URLs should the reverse proxy redirects point to on the local machine on which the Python server is running? In other words, what are the endpoint URLs to which the Python server responds? Where should the reverse proxy direct the traffic to?

Another thing that is not clear: what should the OAuth credentials (U_NAME and U_PASSWD) be in the config.py? Can I enter any username and password there and something will ask for them? Or should these values be taken from somewhere from Google?

One final thing:

Code: Select all

Select No, I only want to allow account creation on my website. Click Next.
For Linking Type, select OAuth.
For Grant Type, select Authorization Code for Grant Type.
This part never came up during the Google setup process. The Google settings must have changed since the instructions were put together. Now there's no way to say "No, I only want.." and there is no field for specifying Grant type. This is what the Account Linking page looks like today:

accoutnlinking.png

Thank you!
You are correct, this part is not needed anymore. I will update the wiki.

Code: Select all

Select No, I only want to allow account creation on my website. Click Next.
For Linking Type, select OAuth.
For Grant Type, select Authorization Code for Grant Type.
About the urls I have set up my reverse proxy like this: https://domoapp.mydomain.com -> 192.168.0.200:3030,
now I can connect with https://domoapp.mydomain.com/smarthome, https://domoapp.mydomain.com/oauth etc.
If you want to test goto https://domoapp.mydomain.com/sync or http://192.168.0.200:3030/sync it should show a login page.
If that works you can now add your app in google home app.

Explanation: the urls https://domoapp.mydomain.com/smarthome, https://domoapp.mydomain.com/token etc. do not show any pages. DZGA server is using them to post and get api to Google.

Re: Domoticz to Google Assistant integration

Posted: Friday 15 November 2019 0:18
by BazsoDombiAndras
There's something really very strange related to how http and https is handled in the server...

If I set up my reverse proxy with https, like https://domoapp.mydomain.com -> https://192.168.0.200:3030 and I visit https://domoapp.mydomain.com/sync, then the Python server is giving me "400, Invalid request type" and "400, Invalid request header" errors. I read up on Google about this and it is caused by using https where http is expected. So this leads me to think that the Python server is not prepared to handle https requests, it works only with http.

That's not very good, but ok, let's try to set up the reverse proxy like http://domoapp.mydomain.com -> http://192.168.0.200:3030 (use http instead of https this time). And if I visit http://domoapp.mydomain.com/sync, it actually works and brings up the login page! So everything is great, right? Wrong! Because in Google, when you set up the fulfillment URL, authorization URL and token URL, it only accepts links which start with https (not http!)

OK... so the server only works with http, Google only accepts https. What can we do? Well, let's set up a redirect in the reverse proxy which automatically redirects all https requests to http. So when Google launches a https request, that will be actually sent to the http address at the Python server. Now it will finally work, one would think. But no, because Google errors out saying that the server redirected too many times, in other words it detects that one redirect and one is too many for it.

I do not see any solution to make it work and I'm very curious how other people managed to get it up and running.

Re: Domoticz to Google Assistant integration

Posted: Friday 15 November 2019 0:40
by BazsoDombiAndras
The solution is to set up a direct mapping from https to http in the reverse proxy, like so:
https://domoapp.mydomain.com -> http://192.168.0.200:3030

For example, my Apache 2 reverse proxy settings look like this:

Code: Select all

<VirtualHost *:80>
        ServerName domoapp.mydomain.com

        <Proxy *>
                Order allow,deny
                Allow from all
        </Proxy>

        ProxyPreserveHost On
        ProxyRequests Off

        ProxyPass / http://192.168.0.200:3030/
        ProxyPassReverse / http://192.168.0.200:3030/
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName domoapp.mydomain.com

        <IfModule mod_headers.c>
                Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
        </IfModule>

        SSLProxyEngine on

        <Proxy *>
                Order allow,deny
                Allow from all
        </Proxy>

        ProxyPreserveHost On
        ProxyRequests Off

        ProxyPass / http://192.168.0.200:3030/
        ProxyPassReverse / http://192.168.0.200:3030/

</VirtualHost>
</IfModule>

Re: Domoticz to Google Assistant integration

Posted: Friday 15 November 2019 0:53
by BazsoDombiAndras
Unfortunately I'm still unable to get it working with Google :(
Now I actually get the login screen when I select the "[test]AppName" app from the "Add devices list". I enter the user name and password defined as U_NAME and U_PASSWD in the "OAuth credentials" section of the config.py file.

After login I get:
"Signing in.."
"Linking your [test]AppName account"
"Could not update the setting. Check your connection."

On the Python server I see this after the login screen disappears:

Code: Select all

Request: -->
{
  "inputs": [
    {
      "intent": "action.devices.SYNC"
    }
  ],
  "requestId": "9985023441422713640"
}
Finally, after a long time, long after I get the "Could not update the setting. Check your connection." error on my phone the Python server shows a response listing all my devices:

Code: Select all

Response: -->
{
  "requestId": "9985023441422713640",
  "payload": {
    "agentUserId": "1234",
    "devices": [
      {
        "id": "Light/Switch118",
        "name": {
          "name": "All Lights"
        },
        "attributes": {},
        "traits": [
          "action.devices.traits.OnOff"
        ],
        "willReportState": false,
        "deviceInfo": {
          "manufacturer": "Virtual Devices"
        },
        "type": "action.devices.types.LIGHT"
      },
      
      ...
      
    ]
  }
}
It is a very long list of devices, I have between 100-200 devices in Domoticz. Could it be that retrieving that long list of devices takes too long and something times out?

Re: Domoticz to Google Assistant integration

Posted: Friday 15 November 2019 1:51
by BazsoDombiAndras
Isn't it wonderful when problems solve themselves? :)
After a while the "[TEST]AppName" account was automatically linked to my Google Home account and my Domoticz devices showed up in GoogleHome :) I suspect that this happened after I went to the testing section in the Google actions console.

However, the timeout is still a problem. If I try to check let's say the thermometer Domoticz device named "Attic temperature", the Python server shows immediately this request:

Code: Select all

Request: -->
{
  "inputs": [
    {
      "intent": "action.devices.QUERY",
      "payload": {
        "devices": [
          {
            "id": "Temp30"
          }
        ]
      }
    }
  ],
  "requestId": "18271249480173547938"
}
... after that the Google Home times out and it says to check my network connection, another 10-20 seconds pass and finally the Python server spits out the response, way too late:

Code: Select all

Response: -->
{
  "requestId": "18271249480173547938",
  "payload": {
    "devices": {
      "Temp30": {
        "online": true,
        "thermostatMode": "heat",
        "thermostatTemperatureAmbient": 29.7,
        "thermostatTemperatureSetpoint": 29.7,
        "thermostatHumidityAmbient": 49
      }
    }
  }
}

Re: Domoticz to Google Assistant integration

Posted: Friday 15 November 2019 7:43
by DewGew
I dont have those problem. Seems like you have some issues to connect to google. Dubble check your setting with reverse proxy.
You could try to use a tunnel to see if it your server or not. No need to open any ports on the router.
Open a terminal and run dzga server.
Open another terminal and Install nodejs localtunnel with npm eg.

Code: Select all

npm install -g localtunnel
Then run localtunnel with:

Code: Select all

lt --port 3030 --subdomain testdzga
You will receive a url, https://testdzga.localtunnel.me, add this url instead of https://[YOUR REVERSE PROXY URL] in actions on google. (Dont for get to click save and test buttons)
Test now if you get the responses more quickly

Re: Domoticz to Google Assistant integration

Posted: Friday 15 November 2019 10:29
by BazsoDombiAndras
Thank you for your help!

I've tried the localtunnel, but it works just the same. I think the problem might me my internet connection or the speed of my Domoticz server, as this morning it works somewhat faster. Now it is just at the limit of the timeout. Sometimes it returns a response just in time, other times not. Is it possible to somehow increase that timeout? Is that timeout a setting in Google or in the Python server?

Thanks!

Re: Domoticz to Google Assistant integration

Posted: Friday 15 November 2019 10:49
by DewGew
There in no timeout to set in python script. Question is if the timeout is to google or to your domoticz setup. Are you running this dzga on a separate device or localy?

Re: Domoticz to Google Assistant integration

Posted: Friday 15 November 2019 11:03
by BazsoDombiAndras
The DZGA server is not on the same machine as the Domoticz server, but they are on the same high-speed local network (both on WiFi). I guess I could try to move the DZGA to the Domoticz machine, but the requests would go through the current DZGA machine anyway, because that one operates the reverse proxy (and I can't move that). This 4-5 second timeout is a bit unreasonable. I've read that it's a Google setting.

Re: Domoticz to Google Assistant integration

Posted: Friday 15 November 2019 14:08
by DewGew
BazsoDombiAndras wrote: Friday 15 November 2019 11:03 The DZGA server is not on the same machine as the Domoticz server, but they are on the same high-speed local network (both on WiFi). I guess I could try to move the DZGA to the Domoticz machine, but the requests would go through the current DZGA machine anyway, because that one operates the reverse proxy (and I can't move that). This 4-5 second timeout is a bit unreasonable. I've read that it's a Google setting.
I think its on google side or your internet connection. Also check if your homegraph api is valid. Sometimes I had to change when i got slow. But its suppost to work without homegraph

Re: Domoticz to Google Assistant integration

Posted: Friday 15 November 2019 14:09
by BazsoDombiAndras
Yepp :( Thank you for your ideas and for your help!

Re: Domoticz to Google Assistant integration

Posted: Saturday 16 November 2019 11:54
by tage
Hi

i also have some trouble to get this to work.
domoticz -> raspberry
Domoticz-Google-Assistant -> linux pc
and reverse proxy (pound) same linux pc
router portforward port 443 to linux pc
reverse proxy listen port 443 send that to port 3030 (Domoticz-Google-Assistant)
double check and have make new projects on google console just to make sure that is okey.
when try add "test" project in google home i come to login page and when type username and password i got this in domoticz-google-assistant log :

Code: Select all

192.168.0.10 - - [16/Nov/2019 11:36:10] "POST /login HTTP/1.1" 301 -
192.168.0.10 - - [16/Nov/2019 11:36:11] "GET /login?client_id=574522741018-46vmha139e9vi049mlucupdiq49dp3gt.apps.googleusercontent.com&redirect_uri=https%253A%252F%252Foauth-redirect.googleusercontent.com%252Fr%252Fmitt-projekt-259118&redirect=/oauth&state=AB8b_TOhbrqakbQy04zp9D8Xt-5pgNQmUuVDQiDdFNP4rthBSz9OXZ5Fw1Y8mDAV7Sv7KzgBurXetyTqwrb8T-kRuQ2TdTblyVdUTR_zhffPz5tipNx0EpzUvZzgGe6r3yhtl7ciO5gC5agRvoENE9pYGOEl6tCaW754HqjxM6g8FdjAaXlKWvZpYhqi_19eIKk-tnEeww0QjmXB-OuMDdBJWgi7GGu-C4vu2agewbPHQtBvxGl14rdAAk6WgcOj-U7Jjn2CUHUy8OcP8rKflBm17e7XgYQfQ_GNhz62wL7SC_WBKsWW7ueHlcTheEUc2yIH_2LUsohOaXf1k5zL3ZouS3GmzjyvUDWuproy4NTssaSy0OLniMwJsT5q2r2BUJxqVHIDdWAUVjkPma8scgF1VbwupfDy0UYARNbkm2EP-Ad1aMpoYqLhKN9ibuCEKIbpfpg80rAWg2dbzCtZbRiApVj6S5QiDAjsLe6LVsfo2NSM0YH_mXqmpJ6FgetML4Ae3VaN8uniwe9BhaoylEwfaK2bX1fIyxqE56CsUwQ3G-G48KHi4t8ldnsuQo2qhg89ysNH9OcrrxFczUNxUnhNoYbOpBo-7ayvwJmwlL_35_aeQUcbteA HTTP/1.1" 200 -
and got back to add new device app.
when try again and select my test app this shows up on phone/tablet :

Code: Select all

Page not found!: '/https%3A%2F%2Foauth-redirect.googleusercontent.com%2Fr%2Fmitt-projekt-259118'
then i have to kill python3 pid and start it again to come to login page when trying again .

/tage

Re: Domoticz to Google Assistant integration

Posted: Wednesday 20 November 2019 15:15
by DewGew
I need some more feedback on dzga server beta try beta:

Rpi/ubuntu one line install (installs: dzga, startup service, gui):

Code: Select all

bash <(curl -s https://raw.githubusercontent.com/DewGew/dzga-installer/master/install.sh)
Domoticz Google Assistant Beta Wiki

Re: Domoticz to Google Assistant integration

Posted: Thursday 21 November 2019 20:01
by DewGew
tage wrote: Saturday 16 November 2019 11:54 Hi

i also have some trouble to get this to work.
domoticz -> raspberry
Domoticz-Google-Assistant -> linux pc
and reverse proxy (pound) same linux pc
router portforward port 443 to linux pc
reverse proxy listen port 443 send that to port 3030 (Domoticz-Google-Assistant)
double check and have make new projects on google console just to make sure that is okey.
when try add "test" project in google home i come to login page and when type username and password i got this in domoticz-google-assistant log :

Code: Select all

192.168.0.10 - - [16/Nov/2019 11:36:10] "POST /login HTTP/1.1" 301 -
192.168.0.10 - - [16/Nov/2019 11:36:11] "GET /login?client_id=574522741018-46vmha139e9vi049mlucupdiq49dp3gt.apps.googleusercontent.com&redirect_uri=https%253A%252F%252Foauth-redirect.googleusercontent.com%252Fr%252Fmitt-projekt-259118&redirect=/oauth&state=AB8b_TOhbrqakbQy04zp9D8Xt-5pgNQmUuVDQiDdFNP4rthBSz9OXZ5Fw1Y8mDAV7Sv7KzgBurXetyTqwrb8T-kRuQ2TdTblyVdUTR_zhffPz5tipNx0EpzUvZzgGe6r3yhtl7ciO5gC5agRvoENE9pYGOEl6tCaW754HqjxM6g8FdjAaXlKWvZpYhqi_19eIKk-tnEeww0QjmXB-OuMDdBJWgi7GGu-C4vu2agewbPHQtBvxGl14rdAAk6WgcOj-U7Jjn2CUHUy8OcP8rKflBm17e7XgYQfQ_GNhz62wL7SC_WBKsWW7ueHlcTheEUc2yIH_2LUsohOaXf1k5zL3ZouS3GmzjyvUDWuproy4NTssaSy0OLniMwJsT5q2r2BUJxqVHIDdWAUVjkPma8scgF1VbwupfDy0UYARNbkm2EP-Ad1aMpoYqLhKN9ibuCEKIbpfpg80rAWg2dbzCtZbRiApVj6S5QiDAjsLe6LVsfo2NSM0YH_mXqmpJ6FgetML4Ae3VaN8uniwe9BhaoylEwfaK2bX1fIyxqE56CsUwQ3G-G48KHi4t8ldnsuQo2qhg89ysNH9OcrrxFczUNxUnhNoYbOpBo-7ayvwJmwlL_35_aeQUcbteA HTTP/1.1" 200 -
and got back to add new device app.
when try again and select my test app this shows up on phone/tablet :

Code: Select all

Page not found!: '/https%3A%2F%2Foauth-redirect.googleusercontent.com%2Fr%2Fmitt-projekt-259118'
then i have to kill python3 pid and start it again to come to login page when trying again .

/tage
Still have issues?

Re: Domoticz to Google Assistant integration

Posted: Thursday 21 November 2019 21:30
by EscApe
@DewGew
I need some more feedback on dzga server beta try beta:
Thanks again.. just pulled the latest beta. I ran into some trouble, but that might have been my own fault. The previous beta was working fine, but after updating my devices would show offline. Removed and re-added from google home and all is fine again. I did change my username and password a couple of weeks ago, so maybe that was the cause? I had no problems restarting the service (within those couple of weeks), but an update might be different(?)

Anyway, the latest beta seems to be working just fine.

Re: Domoticz to Google Assistant integration

Posted: Friday 22 November 2019 7:14
by DewGew
EscApe wrote: Thursday 21 November 2019 21:30 @DewGew
I need some more feedback on dzga server beta try beta:
Thanks again.. just pulled the latest beta. I ran into some trouble, but that might have been my own fault. The previous beta was working fine, but after updating my devices would show offline. Removed and re-added from google home and all is fine again. I did change my username and password a couple of weeks ago, so maybe that was the cause? I had no problems restarting the service (within those couple of weeks), but an update might be different(?)

Anyway, the latest beta seems to be working just fine.
Great thanks.

Re: Domoticz to Google Assistant integration

Posted: Sunday 24 November 2019 13:30
by JXR
I had BIG issues with DZGA performing duplicate requests to Domoticz. Took me ages to figure out where it came from (GActions, Proxy, Domoticz, or somewhere in the DZGA code), but I found it. Probably every single user has this issue, but it feels I'm the only one who noticed and had issues with it (due to IR).

The issue is on line 431 of smarthome.py:

print(json.dumps(self.smarthome_process(message, token), indent=2, sort_keys=False))

In this line the smarthome_process call is made a second time. It can be fixed by replacing with:

print(json.dumps(response, indent=2, sort_keys=False))

I hope it helps.

Re: Domoticz to Google Assistant integration

Posted: Sunday 24 November 2019 13:53
by EscApe
Probably every single user has this issue, but it feels I'm the only one who noticed and had issues with it (due to IR).
Looks like you are right. I did not notice it, but can see the double commands in my logs.

Re: Domoticz to Google Assistant integration

Posted: Sunday 24 November 2019 18:32
by DewGew
EscApe wrote: Sunday 24 November 2019 13:53
Probably every single user has this issue, but it feels I'm the only one who noticed and had issues with it (due to IR).
Looks like you are right. I did not notice it, but can see the double commands in my logs.
Updated on github. Thanks for pointing this out :)

Re: Domoticz to Google Assistant integration

Posted: Sunday 24 November 2019 21:03
by JXR
My pleasure guys! Btw; awesome project, work's like a charm and your setup guide is 100% spot on (Y)