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

I forgot to put the notify component

Awesome. :slight_smile:

So you got it to work?

1 Like

I canā€™t seem to get the UI to clear the field after submit - is that something you customized?

Yeah, the automation plus script I created above should do the trick.

Iā€™ve basically made the script call the notification, and then clear the input_text component. And then the automation only triggers the script if the length is greater than zero, and the input_text component state changes.

Ahh, got it. In converting your automation to AppDaemon I had a syntax error that I wasnā€™t catching.

Here is an AppDaemon app to monitor input_text changes and call a notify service. Basic use is as you have yours now, in the future with added webhooks this could be used to have an intercom or control specific to each room or device.

import appdaemon.appapi as appapi

#
# App to monitor input_text input to use as an intercom to google assistant devices
#
# Forum Discussion:
# https://community.home-assistant.io/t/community-hass-io-add-on-google-assistant-webserver-broadcast-messages-without-interrupting-music/37274
#
#
# EXAMPLE appdaemon.yaml entry
###
# Intercom:
#   class: intercom
#   module: intercom
#   entities:
#     - intercom_input: input_text.intercom
#       notify: googleassistant
#
#
# Arguments
###
# intercom_input: input_select entity to be monitored
# notify: the notify component to use
#
#
# NOTES:
#   Example Notify:
#     - name: googleassistant
#       platform: rest
#       resource: http://192.168.1.188:5000/broadcast_message
#
#
# Release Notes
#
# Version 1.0:
#   Initial Version
#
#
# ####################################################################
# ####################################################################


class intercom(appapi.AppDaemon):
    
    def initialize(self):
      if "entities" in self.args:
          for item in self.args["entities"]:
            intercom_input = item["intercom_input"]
            notify = item["notify"]

            msg = "Intercom setup using {}.".format(
                self.friendly_name(intercom_input))
            self.log(msg, "INFO")

            # Setup Listener
            self.listen_state(self.state_changed, entity=intercom_input, notify=notify)

      else:
          msg = "Intercom enabled but no entities configured."
          self.log(msg, "INFO")

    
    def state_changed(self, entity, attribute, old, new, kwargs):

        intercom_input = entity
        notify = kwargs['notify']

        if new != "" and new != " " and old != new:
          notifyservice = 'notify/{}'.format(notify)
          self.call_service(notifyservice, message=new)
          self.call_service('input_text/set_value', value=" ", entity_id=intercom_input)


1 Like

Yes! Only thing that after a restart in the box is shown unknown (minor issue)

1 Like

Have you been able to get the ā€œspecialā€ broadcasts to work using this method? For instance, if I personally say ā€œBroadcast, itā€™s dinner timeā€ - google will ring a bell and then say ā€œitā€™s dinner timeā€ or ā€œBroadcast, Iā€™m homeā€ will play a trumpet followed by ā€œHey there, kylerw has arrivedā€.

When using the intercom, it always plays back using TTS/Text To Speech.

I havenā€™t tried that out, but it could need to be specifically formatted a certain way. If you have the Google Assistant app on your phone, then it letā€™s you try out text messages that you can then move over to Home Assistant.

So, in the Google Assistant app, it would be ā€œbroadcast [some message]ā€.

Hereā€™s the link to the specific messages in case you havenā€™t seen it yet:
https://support.google.com/googlehome/answer/7531913?co=GENIE.Platform%3DAndroid&hl=en

Yeah, I took the liberty of adding a new api resource for a generic command and using broadcast without the quotes around the message gives the special responses.

Awesome! Iā€™m definitely going to have to add all that when I get home then.

Just submitted a PR for the changes I had made. Hopefully thatā€™s ok. :slight_smile:

1 Like

Struggling to set a timer with this using my edited API. If anyone works out the correct syntax (and the same goes for an alarm) without require any additional chat/response please feed back here.

I think the issue is that the alarm or timer is being set on the ā€œvirtualā€ google home and there currently is not the capability to set a timer or alarm on another device.

That would explain it. Thanks.

Not seeing your pull request by the way. Interested to see it as Iā€™d already submitted one myself but Iā€™m no coder!

Hey andrewdolphin! I have a comment or two on your PR. Iā€™d say once those two minor things are taken care of, I can trigger the Docker build from where I am and get the new version out there.

Just merged a PR from @kylerw that takes the add-on to version 0.0.3, adding a webhook for generic messages that arenā€™t for broadcasts.

http://[HASSIO LOCAL IP]:5000/command?message=[any Google command]

You can use this to send any generic message you want to Google that the Google Assistant app could normally handle.

ā€œTurn on the hallway lights,ā€ or ā€œSet a reminder for [something]ā€, etc.

4 Likes

We should change to that (rather than have 2 types)?

@anon35356645

Itā€™s just a version upgrade, and Hass.io would suggest it. Although, if itā€™s working for you, then thereā€™s really no need to upgrade.

but if I use this, in order to broadcast a message I have to add BROADCAST in the text before the message, correct?
Basically I can:
turn on living room light
or
broadcast Itā€™s time for dinner