Self.call_service("hangouts/send_message",

Hi All,

Can anyone describe how to use the call_service function to call the new hangouts/send_message service.

I have tried

self.call_service(“hangouts/send_message”,target=“idXXX”,message=“test”)
self.call_service(“hangouts/send_message”,target="[{ ‘id’: ‘XXX’}]",message=“test”)
self.call_service(“hangouts/send_message”,target="[{ ‘name’: ‘conversation’}]",message=“test”)
self.call_service(“hangouts/send_message”,target="[{ ‘id’: ‘XXX’}, { ‘name’: ‘conversation’}]",message=“test”)
self.call_service(“hangouts/send_message”,id=“idXXX”,message=“test”)
self.call_service(“hangouts/send_message”,name=“conversation”,message=“test”)

and all of the above with the message
message=“test”
message=’{“text”: "test}’
message=’[{“text”: "test}]’

some get errors, but most just finish correctly but nothing gets sent to the hangouts conversation.

Any help is appreciated.

Hell @simonhq,

I haven’t used it (and don’t plan to :roll_eyes:), but I think what you seeking for is self.call_service(“hangouts/send_message”,target=[{ ‘id’: ‘XXX’}, { ‘name’: ‘conversation’}], message=[{“text”: "test}])

The doc says it needs a list, which you are technically not passing based on the examples you gave you have tried.

Regards

1 Like

Thank you!

Final line looks like this

 self.mmessage = "hello"
 self.call_service("hangouts/send_message",target=[{ "name": "Home" }] ,message=[{ "text": self.mmessage }])

one thing I found, if you include the { “id” : “fadjf” } as well as the name, it will treat it as two conversations and send the message to the conversation twice, so you only need the id or the name for it to work correctly.

Hi!

I’m also trying to send using Hangouts. The goal is to send a message from an automation.
I’ve tested using the service developer tool but can’t get the JSON format correct.

{ target=[{ "name": "Test" }], message=[{ "text": "Test" }] }

gives me “Invalid JSON”.

Any suggestion on what to change?

Hi rock3r

in automation it should look like this:

action:
    - service: hangouts.send_message
      data: 
        target:
          - id: !secret hangout_id
        message:
          - text: 'message'

In appdaemon like this:

self.call_service("hangouts/send_message",target=[{ "name": "Home" }] ,message=[{ "text": "message" }])

hope this helps

i could never get this hangouts working. each time it tells me wrong credentials… even after retry several hours after… any hint to make it work?

Hi thundergreen,

there is some notes on this page https://www.home-assistant.io/components/hangouts/ about 2-factor authentication and the like that might help

I’ve no two factor authentication…that’s why and I try multiple times per day

And I don’t see any message for the token.

Thanks @simonhq, it helped!

When using Hangouts from an automation the:

  • Action type is “Call service”
  • Service is “Hangouts.send_message”
  • Service data JSON will look like this
    {
      "message": [
        {
          "text": "message"
        }
      ],
      "target": [
        {
          "name": "name of Hangouts conversation"
        }
      ]
    }
1 Like

A follow up question. If I want some logic, if/else, on the message text. How would that be written in JSON?

This doesn’t work…

{
  {% if is_state(''device_tracker.xxx'', ''home'') %}
  "message": [
      {
        "text": "if"
      }
  ],
  {% else %}
  "message": [
      {
        "text": "else"
      }
  ],
  {% endif %}  
  "target": [
    {
      "name": "<conversation>"
    }
  ]
}

how to trigger action from hangouts message? i read the doc but i did not get it.

I could only get this to work using the target ID and not the target name. Under states where I find the ID for my conversations…it list the “name” for both as null. Is there a way for me to set the name to something?

Hi rock3r,

I am not good at straight JSON, don’t think I can help with this one sorry.

1 Like

Hi ashfaaa,

I haven’t set this up yet as I keep getting session closed errors, which I believe are being looked at. Once that is fixed, I will be looking at this, once I get it working I will let you know what I have done.

Hi Silfa718,

Have you set the name in the hangouts app (the web version) I set up the group in the web version putting in everyone I wanted and giving it a name there, then when it showed up in home assistant conversations, it already had a name.

okay, I see that.

Is there a way to set a name for a single person?

The way I have done it is using the hangouts account for the HA, I have created a conversation with just one person, and named that conversation with the person’s name, then set it up in the notify area of HA.

I have switched to notify/xxxx service calls as they correctly format the messages, if you just do send_message/xxx service calls it ignores formatting (new lines etc.)

I have some similar issues. I use Hangouts notification from HA automations. Usually it works very well but after some time (several days, probably a week) I start to get messages in the log about “session closed”. It happened for the second time today (I mean for the second time since I started to use it). Last time only Pi reboot helped. I am still investigating the current case.
Probably this information would help you, or probably you could share your findings if you managed to fix it

I am getting the following error:

2018-10-15 22:26:30 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall hangouts.send_message (c:e0365534a2e9456c8e0aa12947da65bf): message=[{'text': 'message'}], target=[{'name': 'Home'}]>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/core.py", line 1177, in _event_to_service_call
    await service_handler.func(service_call)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/hangouts/hangouts_bot.py", line 307, in async_handle_send_message
    service.data[ATTR_DATA])
KeyError: 'data'

thought I don’t seem to be getting the ‘session is closed’ error now