Page 1 of 15

Domoticz to Google Assistant integration

Posted: Wednesday 06 March 2019 12:12
by Pawcio
Domoticz to Google Assistan integration

Based on the home assistant implementation:
https://github.com/home-assistant/home- ... _assistant
and https://github.com/actions-on-google/smart-home-nodejs

Required:
- Public IP
- python >= 3.5
- reverse proxy for establishing secure connection (aog itself provides currently only unsecure one - http only)

Aog delivers:
- the oauth authorization and smarthome endpoint for the google assistant
- OnOff, Brightness, Scene and OpenClose traits, rest to be done...
Please feel free to modify it, extend and improve


Before first launch, config.py must be modified properly:
PORT_NUMBER = 3030 -> port number for the aog server

SMARTHOMEPROVIDERGOOGLECLIENTID = 'AxqqWpwYj4' - Client ID issued by your Actions to Google, check actions on google configuration
SMARTHOMEPROVIDEGOOGLECLIENTSECRET = '11MH3uWlMVrqa7FAbKLBoNUMCyLC22' - Client secret
SMARTHOMEPROVIDERAPIKEY = 'zOzaSyBu5Y8W7EiHvO1eyPmOAtZRxM9GaLP_uLA' -> https://github.com/actions-on-google/sm ... quest-sync

DOMOTICZ_URL='http://[DOMOTICZ_IP]:[PORT]'
U_NAME_DOMOTICZ = 'domoticz user name'
U_PASSWD_DOMOTICZ = 'domoticz user password'

#oauth credentials -> required for app linking
U_NAME = 'username'
U_PASSWD = 'password'

if required nicknames, room hint and ack for selected devices can be added:
DEVICE_CONFIG = {
'135' : { - domoticz's idx of the device
'nicknames' : ['Kitchen Blind One'], - list of the nicknames
'room' : 'Kitchen' , - room hint
'ack' : True}, - ack for command execution


starting aog server:
python3 aog


1. Change your Account linking setting in Actions on Google console https://console.actions.google.com/, look for the Advanced Options in the bottom left of the sidebar.
Change Linking type to OAuth and Authorization Code.
In the Client information section:
Set Client ID - SMARTHOMEPROVIDERGOOGLECLIENTID
Set Client Secret - SMARTHOMEPROVIDEGOOGLECLIENTSECRET
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).
In the Configure your client section:
Do NOT check Google to transmit clientID and secret via HTTP basic auth header.
Click ‘Save’ at the top right corner, then click ‘Test’ to generate a new draft version of the Test App.



https://[YOUR REVERSE PROXY URL]/sync - force devices sync

Re: Domoticz to Google Assistan integration

Posted: Wednesday 06 March 2019 21:40
by reydecopas
Hi!!!!

I have been looking around about GassistPI and IFTTT but I wanted something like HomeAssistant directly to Google Assistant...

Thanks a lot!!!

Re: Domoticz to Google Assistan integration

Posted: Wednesday 06 March 2019 22:35
by EddyG
Please clarify / explain where those file should be placed. Should it be in the root of domoticz?
I already have an https reversed proxy on my synology pointing to my raspberry where domoticz runs.

Re: Domoticz to Google Assistan integration

Posted: Thursday 07 March 2019 7:49
by Pawcio
Hi,
Actualy it is a standalone implementation. It means that you can put this AOG module wherever you want, even on another machine.

Re: Domoticz to Google Assistan integration

Posted: Thursday 07 March 2019 11:14
by EddyG
Oke, Tnx.

Re: Domoticz to Google Assistan integration

Posted: Thursday 07 March 2019 12:29
by EddyG
Am I missing something?
python3 aog does not work -> can't open file 'aog'
python3 server.py does not work -> no error message.

Re: Domoticz to Google Assistan integration

Posted: Thursday 07 March 2019 12:45
by Pawcio
Did you try in one level up?
You cannot be inside aog folder.

Re: Domoticz to Google Assistan integration

Posted: Thursday 07 March 2019 12:51
by EddyG
Sorry, :oops: That worked.

Re: Domoticz to Google Assistan integration

Posted: Friday 22 March 2019 10:16
by ressof
Pawcio wrote: Wednesday 06 March 2019 12:12 Domoticz to Google Assistan integration
Hi

Is it possible to explain a bit more how to configure Google Actions for this to work? I am a complete newbie at Actions on Google.

Re: Domoticz to Google Assistan integration

Posted: Friday 22 March 2019 14:01
by DewGew
Im trying this but after I have linked my account it say its an error try agin.
In terminal for aog I get

Code: Select all

"POST / HTTP/1.1" 404 -
Whats wrong?

Re: Domoticz to Google Assistan integration

Posted: Tuesday 26 March 2019 16:05
by DewGew
ressof wrote: Friday 22 March 2019 10:16
Pawcio wrote: Wednesday 06 March 2019 12:12 Domoticz to Google Assistan integration
Hi

Is it possible to explain a bit more how to configure Google Actions for this to work? I am a complete newbie at Actions on Google.
Setup Instructions
Use the Actions on Google Console to add a new project with a name of your choosing and click - Create Project.

Click Home Control, then click Smart Home.
On the left navigation menu under SETUP, click on Invocation.
Add your App's name. Click Save.
Click Save.
Add Credentials

Navigate to the Google Cloud Console API Manager for your project id.
Click 'Create credentials'
Click 'OAuth client ID'
Choose 'other'
Add name e.g. 'SMARTHOMEPROVIDERGOOGLECLIENTID'
Copy the client ID shown and insert it in SMARTHOMEPROVIDERGOOGLECLIENTID in config.py
Copy the client secret shown and insert it in SMARTHOMEPROVIDEGOOGLECLIENTSECRETin config.py
Add Request Sync

The Request Sync feature allows a cloud integration to send a request to the Home Graph to send a new SYNC request.

Navigate to the Google Cloud Console API Manager for your project id.
Enable the HomeGraph API. This will be used to request a new sync and to report the state back to the HomeGraph.
Click Credentials
Click 'Create credentials'
Click 'API key'
Copy the API key shown and insert it in SMARTHOMEPROVIDERAPIKEY in config.py.
Navigate back to the Actions on Google Console.

On the left navigation menu under BUILD, click on Actions. Click on Add Your First Action and choose your app's language(s). Enter the URL for fulfillment, e.g. https://[YOUR REVERSE PROXY URL]/smarthome, click Done.
On the left navigation menu under ADVANCED OPTIONS, click on 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). In the Configure your client section:
Do NOT check Google to transmit clientID and secret via HTTP basic auth header.
Click ‘Save’ at the top right corner, then click ‘Test’ to generate a new draft version of the Test App.

Re: Domoticz to Google Assistan integration

Posted: Monday 01 April 2019 14:09
by ressof
Thank you for your detailed explanation.

I can now link my test application on Google Home app but it cant find any devices or sensors.
In the aog log I see this

Code: Select all

No user data
127.0.0.1 - - [01/Apr/2019 14:05:50] "GET /oauth?response_type=code&client_id=[MASKED]&redirect_uri=https://oauth-redirect.googleusercontent.com/r/domoticz-[MASKED] HTTP/1.0" 307 -
127.0.0.1 - - [01/Apr/2019 14:05:50] "GET /login?client_id=[MASKED]&redirect_uri=https%3A%2F%2Foauth-redirect.googleusercontent.com%2Fr%2Fdomoticz-[MASKED] HTTP/1.0" 200 -
127.0.0.1 - - [01/Apr/2019 14:06:18] "POST /login HTTP/1.0" 301 -
Do you know what the problem is?

Re: Domoticz to Google Assistan integration

Posted: Thursday 04 April 2019 9:39
by DewGew
ressof wrote: Monday 01 April 2019 14:09 Thank you for your detailed explanation.

I can now link my test application on Google Home app but it cant find any devices or sensors.
In the aog log I see this

Code: Select all

No user data
127.0.0.1 - - [01/Apr/2019 14:05:50] "GET /oauth?response_type=code&client_id=[MASKED]&redirect_uri=https://oauth-redirect.googleusercontent.com/r/domoticz-[MASKED] HTTP/1.0" 307 -
127.0.0.1 - - [01/Apr/2019 14:05:50] "GET /login?client_id=[MASKED]&redirect_uri=https%3A%2F%2Foauth-redirect.googleusercontent.com%2Fr%2Fdomoticz-[MASKED] HTTP/1.0" 200 -
127.0.0.1 - - [01/Apr/2019 14:06:18] "POST /login HTTP/1.0" 301 -
Do you know what the problem is?
Redirect URL is wrong. Check you URL settings in Action on Google and in your reverse proxy settings.

Re: Domoticz to Google Assistan integration

Posted: Thursday 04 April 2019 13:10
by ressof
Is the redirect url, "https://[YOUR REVERSE PROXY URL]/smarthome", the url to domoticz or to aog
"https://[YOUR REVERSE PROXY URL]/oauth" is to aog?
"https://[YOUR REVERSE PROXY URL]/token" is to aog?

Re: Domoticz to Google Assistan integration

Posted: Saturday 06 April 2019 20:00
by DewGew
ressof wrote: Thursday 04 April 2019 13:10 Is the redirect url, "https://[YOUR REVERSE PROXY URL]/smarthome", the url to domoticz or to aog
"https://[YOUR REVERSE PROXY URL]/oauth" is to aog?
"https://[YOUR REVERSE PROXY URL]/token" is to aog?
Yes. Can be the settings in your reverse proxy also

Re: Domoticz to Google Assistan integration

Posted: Saturday 06 April 2019 20:01
by DewGew
I cant make ’ack = True’ to work. Any ideas?

Re: Domoticz to Google Assistan integration

Posted: Monday 08 April 2019 14:22
by ressof
Now I get this in my log

Code: Select all

127.0.0.1 - - [08/Apr/2019 14:13:45] "POST /login HTTP/1.0" 301 -
127.0.0.1 - - [08/Apr/2019 14:13:47] "POST /token HTTP/1.0" 200 -
when I link the action on my google home app.

I get a message that the link is succesful in the google home app but after a few seconds it says
"An error occurred, please try again"

Why is this?

Re: Domoticz to Google Assistan integration

Posted: Monday 08 April 2019 18:47
by DewGew
ressof wrote: Monday 08 April 2019 14:22 Now I get this in my log

Code: Select all

127.0.0.1 - - [08/Apr/2019 14:13:45] "POST /login HTTP/1.0" 301 -
127.0.0.1 - - [08/Apr/2019 14:13:47] "POST /token HTTP/1.0" 200 -
when I link the action on my google home app.

I get a message that the link is succesful in the google home app but after a few seconds it says
"An error occurred, please try again"

Why is this?
Did you do this:
Navigate back to the Actions on Google Console.

On the left navigation menu under BUILD, click on Actions. Click on Add Your First Action and choose your app's language(s). Enter the URL for fulfillment, e.g. https://[YOUR REVERSE PROXY URL]/smarthome, click Done.

Re: Domoticz to Google Assistan integration

Posted: Tuesday 09 April 2019 1:31
by pvm
Would it be possible to run this using the mydomoticz service? (I might be asking something stupid here, reason for asking is not having complexity in safely opening system to the dangerous 'outside' world)

Re: Domoticz to Google Assistan integration

Posted: Tuesday 09 April 2019 9:11
by DewGew
pvm wrote: Tuesday 09 April 2019 1:31 Would it be possible to run this using the mydomoticz service? (I might be asking something stupid here, reason for asking is not having complexity in safely opening system to the dangerous 'outside' world)
Its possible if the developer for mydomoticz service wants that. Its more like Controlicz then.
This python code creates your own google assistant service. With this you only open a port to aog server not to domoticz. and I use a reverse proxy on my synology.
internet <--> router <--> synology <--> reverse proxy <--> aog server <--> domoticz