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

Hello everyone!

Just recently, I was able to successfully get my add-on for the text-based Google Assistant working on Hass.io.

Here is the add-on repo:

Once installed, the setup is similar to https://home-assistant.io/addons/google_assistant/

So, it needs the google_assistant.json file added to /share

Also, it follows the same OAuth setup.

Once completely running and set up, you can broadcast a text message to your Google Home devices using:
http://hassio.local:5000/broadcast_message?message=[YOUR TEXT MESSAGE]

This will enable you to broadcast a text message to all Google Home devices without interrupting your music that is currently playing.

It is extremely useful for when you want an alert to play based on some automation, but you don’t want to interrupt and stop the current music or anything.

Feel free to let me know any comments/suggestions.

Cheers

49 Likes

After installing, you can also turn it into a notification component by doing something like this:

notify:
  - name: Google Assistant
    platform: rest
    resource: http://[HASSIO LOCAL IP]:5000/broadcast_message

Here’s a demo:

https://streamable.com/o3inl

7 Likes

How can I get this installed on non-hassio (docker)?

It’s actually pretty straightforward, as I had to do that when developing it out.

Here are the steps (these steps have been deprecated in favor of the ones underneath):

  1. Clone the repo.

  2. cd into the “google-assistant-websever” folder

  3. Put that file that you need to name “google_assistant.json” in that folder, but name it “client.json”

  4. Create an empty file called “options.json” in the same folder

  5. Add the following two lines to the end of the Dockerfile (but before the entrypoint line):

    VOLUME /data
    COPY *.json /data/

  6. Build the docker image with the following line (Raspberry Pi 3):

    docker build --build-arg BUILD_FROM=“multiarch/debian-debootstrap:armhf-stretch” -t google_assistant_webserver .

  7. Or for amd64 type devices:

    docker build --build-arg BUILD_FROM=“multiarch/debian-debootstrap:amd64-stretch” -t google_assistant_webserver .

  8. Run it using this line:

    docker run --restart always -d -p 9324:9324 -p 5000:5000 --name google-assistant google_assistant_webserver

  9. Sometimes you might need to stop and remove the container if you build multiple times. Here’s the line for that (this will force you to have to use OAuth to authenticate again):

    docker stop google-assistant && docker rm google-assistant

  10. After it starts up, go to http://[LOCAL IP]:9324 to authenticate with Google.

  11. Now you can go to http://[LOCAL IP]:5000/broadcast_message?message=[MESSAGE]

EDIT:

Here are the more simplified steps to get it running on a non-hass.io system:

  1. Follow the instructions here to get the google_assistant.json file: https://home-assistant.io/addons/google_assistant/

  2. Create an empty folder somewhere to put the client.json (renamed from google_assistant.json) and an empty options.json files.

  3. Run this line (substituting /full/path/to/json/folder with the full path to the two json files):

    docker run --restart always -d -p 9324:9324 -p 5000:5000 -v /full/path/to/json/folder:/data --name google-assistant andbobsyouruncle/armhf-google-assistant-webserver:0.0.3

  4. After it starts up, go to http://[LOCAL IP]:9324 to authenticate with Google.

  5. Now you can go to http://[LOCAL IP]:5000/broadcast_message?message=[MESSAGE]

3 Likes

As you are building an image that includes your Google client secrets, I wouldn’t publish it. There are more steps involved in not copying the JSON files, but mounting a volume that contains them. It’s not too big of a deal though unless you’re thinking of publishing it.

Oh, and I sorry, I might’ve misinterpreted your question. If you were asking how to do this without using docker at all, that might be a bit more complicated.

However, it’s extremely easy to install docker on a Raspberry Pi, as there is just a single command that should set it up completely for you:
curl -sSL https://get.docker.com | sh

yeah I’ve got Docker running on my server, so that’s not an issue. Was curious if I could get it integrated into my current home assistant container. Anyway to get this integrated into the official Google Assistant component?

If you have your on custom docker setup running Home Assistant in a container, then I’d say it’s best to leave it running as its own separate container.

The more compartmentalized you have your docker setup, the more manageable it is.

As to getting it integrated into the official Google Assistant add-on, I guess I could fork it and create a pull request to get a configuration variable added to the options.json to make it start in text mode instead of speaker/mic mode (but that’d require using Hass.io).

But I don’t think there is currently any way to run “your own” Google assistant in Home Assistant without running it separately. So, it’d currently either have to be with Hass.io or a custom docker container. The Google Assistant component merely connects to Google to provide your Google assistants with the ability to control your lights and such. I have that running on my HA setup as well.

So basically, this add-on is actually a full-fledged Google Assistant that can do everything a Google Home can do (just like the Hass.io Google Assistant add-on).

The only difference is that it uses their RPC modules to simulate typing whatever it is you want it to do, versus saying it out loud.

And then the webserver merely crafts a message like “Broadcast [YOUR MESSAGE]”, and it would be like telling your Google Home out loud the same thing.

Actually, come to think of it, there is a lot to be expanded upon here.

For instance, this is a full-fledged Google Assistant, yet the webhook only crafts a message like “broadcast [MESSAGE]” for now.

There could be more webhooks to expose other text-based commands you’d want to send to your Google Home. Like “Set an alarm for [ALARM TIME]”, or maybe even just an API endpoint that takes whatever text you give it and uses that as the entire message to Google.

Also, if you tell a Google Assistant something like “Broadcast time for dinner to the living room speaker” then it would only play on that particular Google Home. So, there could be way more options, but this suits my needs for now.

If others wanted to PR my repo, it could get built out to be pretty fully-functional.

4 Likes

Have setup as coded for now and all working thanks. Will play around with this when I have time. A really simple change to make this more flexible would be to just remove the “broadcast” intro to the text request which would then allow a completely flexible google assistant request to be made.

can you share the code for having INTERCOM in the UI

Cool. I got this working. I published a container (Docker) using your instructions. The requirement is that the client.json needs to be added to the host folder for it to work so that the container wouldn’t include my credentials.

I would LOVE for the message to be more generic so you could use it as you stated. Something like:

“Broadcast ‘Its time for dinner’ on bedroom speaker” or “Set a timer for 5 minutes for stove”

I will definitely share it when I get back from work.

But off the top of my head, it was something like this:

notify:
  - name: Google Assistant
    platform: rest
    resource: http://[HASSIO LOCAL IP]:5000/broadcast_message

input_text:
  intercom_message:
    name: Intercom Message

script: 
  send_intercom:
    alias: Send Intercom
    sequence:
      - alias: Send Message
        service: notify.google_assistant
        data_template:
          message: '{{ states.input_text.intercom_message.state }}'
      - alias: Clear Message
        service: input_text.set_value
        data:
          entity_id: input_text.intercom_message
          value: ''

automation:
  trigger:
    platform: state
    entity_id: input_text.intercom_message
  condition:
    condition: template
    value_template: '{{ (states.input_text.intercom_message.state | length) > 0 }}'
  action:
    - service: script.send_intercom

Then you can simply add the component input_text.intercom_message to some group. When you type something and press enter, it will play the message and then clear it from the input box.

2 Likes

Thanks for the feedback! I’ll definitely add a generic webhook for simply passing through the entire message. I like to keep the broadcast_message webhook though because it makes setting up the notify component a lot easier.

I’ll let you know when I’ve added that functionality, and I’ll push up a new version.

1 Like

mmhhh I did all this, everything is fine … but no sound from the GH

Check the logs for my addon that you installed. It should show something that it has attempted to play a sound or something.

Also, if you manually go to http://[HASSIO LOCAL IP]:5000/broadcast_message?message=test does it play?

Also, if you manually go to http://[HASSIO LOCAL IP]:5000/broadcast_message?message=test does it play?

yes this works … mmhhh

Yeah, so it must be some kind of configuration issue with the script or automation for it. Unfortunately I typed that all out from memory, so there might be something off with it somewhere.

If it works by going to it manually, then it will definitely work if the script and automation are done correctly.