Community Hass.io Add-on: Google Assistant Webserver (broadcast messages without interrupting music)

Interesting. Didn’t know that. I have mainly used core integrations and couple of HACS components. It would be interesting to extend the core tts integration with google assistant broadcasting.

I think I have enabled IPV6 on my router, but not sure. Can verify when Im back from easter holidays.

I have set it all up through docker and im getting an error when I try to run the curl command

curl -X POST http://localhost:8085/broadcast  -d '{"message":"Hello world!!"}'  -H "Content-Type: application/json"
{"error":{}}

I know it is seeing the 2 files correctly because if I don’t have the files there it says

{"error":{"code":"MODULE_NOT_FOUND","requireStack":["/usr/src/app/node_modules/google-assistant/components/auth.js","/usr/src/app/node_modules/google-assistant/index.js","/usr/src/app/assistant.js","/usr/src/app/index.js"]}}

I followed the instructions a couple times to make sure I didn’t make a mistake on the google console side
Any ideas?

Could you please share logs from the docker container?

That is the strange thing, nothing every updates in the logs:
just

Google Assistant Broadcast started at: http://localhost:8085

If I go to http://localhost:8085/ in the browser, it correctly shows me an error, but no additional logs in the docker container

error	"Only POST /broadcast endpoint is supported"

and the curl command returns an error and still no additional logs in the docker container

and I know i’m doing curl correctly because if I change ‘message’ to ‘messaged’ it returns

{"error":"Expecting valid JSON body with 'message' property with length of minimum 2 characters."

I am getting the 500 error, just a blank response

 assistant.cast(req.body.message)
    .then((response) => {
      res.json({response: response});
    })
    .catch((error) => {
      res.status(500).json({error: error});
    })

So has to be something with my google OAuth side… hmmm

EDIT: Figured it out… so you need to do this:
in the google cloud platform: Google Cloud Platform
go to ‘create credentials’ → OaAuth client ID → application type: Desktop app then use that JSON file

I was at first doing it with the device registration json file, it was a working json file and creating the token but on the last step was breaking.

So to add to your instructions i would make it

Google OAuth 2.0 Client ID - in order to authenticate yourself and get access to your Google Assistant.

* Follow steps 1-5 in Configure an Actions Console project
* Make sure that you choose "Device registration" when creating new project in Actions Console, then close that tab, you don't need to click 'register model'
* after step 5, of enabling the API you need to configure the oath consent screen, then go to go to credentials then 'create credentials' -> OaAuth client ID -> application type: Desktop app then use that JSON file
Rename the downloaded file from client_secret_****.apps.googleusercontent.com.json ** to** client_secret.json

Thank you @ismarslomic! This is working perfectly and I love that I can broadcast to individual rooms as well.

Hopefully my additional instructions help people get it setup

This solves the broadcasting issue, but couldn’t we also use this to send commands to google assistant?
in the code we just need to remove Broadcast and then we can fully control google… such as
we can have a button in HA send the command ‘turn on my bedroom tv’ (if you have a chromecast that has cec - which i use all the time on my 3 tv’s.
and you can run other commands to google that home assistant can’t do

Glad you fixed the issue yourself! You are right, we could generalize this solution to also handle general Google Conversation and commands, but that was not mine initial intention or need. I wanted to replace the tts integration, which interrupted the music/media being played, with a broadcasting message. You are free to fork this repo and make your own modification :slight_smile:

I’m having some issues getting this add-on to work.

I’ve already have the Google Assistant add-on working using the manual installation instructions from Google Assistant - Home Assistant. Should I use the same .json-file I downloaded for this add-on?

I’ve tried to copy the previously downloaded .json-file from the /config folder to the /share folder and renamed it to “google_assistant.json” but I get this error message in the log when I start the add-on:

[Info] Install/Update service client_secrets file
[Info] Start WebUI for handling oauth2
Traceback (most recent call last):
  File "/hassio_oauth.py", line 76, in <module>
    user_data = json.load(data)['installed']
KeyError: 'installed'

According to a previous post this means the .json-file is not correct. I’ve also tried to generate a new .json service account key in the Google Cloud Platform but this doesn’t seem to work either. Where should the .json key be placed? Can it be a copy of the .json key I’ve already generated?

Sorry for all the questions, I would really like to get this to work for my TTS-notifications.

EDIT: Got it to work somehow using a new, generated key. However, I have two additional questions:

  1. is it possible to remove the introduction before the TTS message? My Google Home now says “Incoming broadcast. The message is…” before the message. I’m using the http://hassio.local:5000/broadcast_message?message=[MESSAGE] URL.

  2. Is it possible to choose what devices shoudl be used for the broadcast? I’ve some devices in the childrens room I sometimes don’t want to broadcast messages to.

1 Like

I think I figured out that KeyError: ‘installed’ issue. The instructions in the readme for this repo reference old instructions for the google assistant integration. I had been providing this addon with a service account json file as I was following the current instructions but it was expecting an oauth client json file from these old instructions:
addons/README.md at e836914c698c561b489467f7d214dc2f2f3006ee · home-assistant/addons (github.com)
I used the same oauth client that I had previously set up for nest and now the addon starts up fine.

1 Like

yes its possible, but the INCOMING BROADCAST phrase is not editable.

For for example sending to tan other device do this,

change text to,
broadcast to (YOUR DEVICE NAME) this is a test 1 .2 .3

I think this is working using the command querystring (@malosaa mentions this above), just not described in the documentation.

Code at:

For example, this works for me (note that in web queries, spaced get turned into %20 - you can type in the command with just spaces and the browser changes it for you):

http://homeassistant.local:5000/command?message=Play%20Youtube%20on%20the%20bedroom%20roku
or
http://homeassistant.local:5000/command?message=Turn%20off%20the%20laundry%20room%20roku

Note for anyone trying to install this (the instructions could use some updating, I started with what @halomademeapc posted),

  1. On the GCP Credentials page, add a new OAuth credential for a Desktop Client, not a web client. You’ll know it’s the right format as the json file will have an “installed” key in it. This is different than the Google Assistant credentials file for the service account.
  2. make sure you’re putting the json file in the /homeassistant.local/share/ directory (not the config directory that other config files are in)
1 Like

Can someone tell me how to get the JSON file?
I am quite stalling

I either get this with a Oauth 2.0:

Or this error in the logs with a service account:

[Info] Install/Update service client_secrets file
[Info] Start WebUI for handling oauth2
Traceback (most recent call last):
  File "/hassio_oauth.py", line 76, in <module>
    user_data = json.load(data)['installed']
KeyError: 'installed'

Any help is appreciated!

Solution: @Maxi1134 I got past that issue with this below.

Go to your developer console.
Go to OAuth consent screen.
Go to +Add users, under test users.
Add the users for the test (even the owner email address if not working without it)

Found at

Im pretty sure this will all stop working in October since this uses a deprecated oauth. I use this heavily. I hope someone updates it.

1 Like

here is an tutorial,

yes i use it to, lets hope it doesnt stop working end of the year… that would be a disaster

1 Like

Hi all!

I’ve got a problem I’ve seen on this thread a few times. I’m unable to start the authentication flow. I’ve tried accessing the following urls:

http://192.168.1.158:9326, http://192.168.1.158:5000
http://192.168.1.158:9326, httpS://192.168.1.158:5000
http://mydynamicdns:9326, http://mydynamicdns:5000
httpS://mydynamicdns, httpS://mydynamicdns:5000

I’ve also forwarded those ports & tried changing the ports to something random. Always get this error from Chrome:

This site can’t be reached
192.168.1.158 refused to connect.

I’ve tried in Firefox too. I’ve put the credentials JSON (google_assistant.json) in /share, /config and /config/share and also tried renaming it to google_assistant_2.json etc.

I’ve generated new credentials through cloud.google.com and applied them to both this plugin/files and to the standard google assistant integration. The standard google assistant integration works fine, for years now.

I’m getting the following error in the logs:

[Info] Install/Update service client_secrets file
[Info] Start WebUI for handling oauth2
Traceback (most recent call last):
  File "/hassio_oauth.py", line 76, in <module>
    user_data = json.load(data)['installed']
KeyError: 'installed'

Anyone has any ideas for troubleshooting?

Thanks a lot!

Look out for an email from Google with instructions to allow you to apply for a final extension until Jan 2023.

“If necessary, you may request a one-time deprecation enforcement extension for each listed OAuth client ID until January 31, 2023. For clarity, the enforcement for the OOB flow deprecation will be enforced on February 1, 2023 with no exceptions or extensions.”

1 Like

which just delays the issue - it doesn’t fix it.

Here say have a quick fix… If now I only could figure out how to apply it… maybe there are people here who do understand?