bbernhard / signal-cli-rest-api

Dockerized Signal Messenger REST API
https://bbernhard.github.io/signal-cli-rest-api/
MIT License
1.37k stars 160 forks source link

I had Signal working in Home Assistant. Now getting failures. #113

Closed rkhanso closed 3 years ago

rkhanso commented 3 years ago

I installed Signal into Home Assistant using the directions on the Home Assistant website. I am not using docker containers, but the Signal Add-On. It was working at initial install/config, but stopped. I get these errors in the home-assistant.log. Searching the Internet, I didn't find anything at all. 2021-03-21 19:27:50 ERROR (MainThread) [homeassistant.core] Error executing service: <ServiceCall notify.brenda (c:ABunchOfNumbers): message=Template("I'm at Costco. Do you need anything?")> Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/core.py", line 1504, in catch_exceptions await coro_or_task File "/usr/src/homeassistant/homeassistant/core.py", line 1523, in _execute_service await handler.job.target(service_call) File "/usr/src/homeassistant/homeassistant/components/notify/init.py", line 154, in _async_notify_message_service await self.async_send_message(kwargs) File "/usr/src/homeassistant/homeassistant/components/notify/init.py", line 133, in async_send_message await self.hass.async_add_executor_job(partial(self.send_message, message, kwargs)) # type: ignore File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/src/homeassistant/homeassistant/components/signal_messenger/notify.py", line 79, in send_message raise ex File "/usr/src/homeassistant/homeassistant/components/signal_messenger/notify.py", line 76, in send_message self._signal_cli_rest_api.send_message(message, self._recp_nrs, filenames) File "/usr/local/lib/python3.8/site-packages/pysignalclirestapi/api.py", line 83, in send_message raise exc File "/usr/local/lib/python3.8/site-packages/pysignalclirestapi/api.py", line 79, in send_message raise SignalCliRestApiError(json_resp["error"]) pysignalclirestapi.api.SignalCliRestApiError: INFO SignalAccount - Config file is in use by another instance, waiting… INFO SignalAccount - Config file lock acquired. Failed to send message: org.whispersystems.signalservice.api.push.exceptions.NotFoundException: Not found

In the Add-On logs, I get this:

Is this a bug?

rkhanso commented 3 years ago

After more testing, I can send messages to only one mobile number. No other mobile numbers seem to work.

bbernhard commented 3 years ago

~Which version are you using? The docker container or the Home Assistant addon?~

Sorry, just realized that you already answered that one. The Home Assistant addon is maintained by @haberda in this repository here. We can do some general debugging here, but in case it turns out that it's something specific related to the Home Assistant addon I think you would need to ask @haberda for help. I do not know about all the internals of the Home Assistant addon.

Some things you could try:

curl -X 'GET' 'https://127.0.0.1:8080/v1/identities/<number>' -H 'accept: application/json'

rkhanso commented 3 years ago

I'm using the Home Assistant Signal Add-On.

I'm assuming that those two lines need to be run in my HA Terminal, right? And, should I use the number I have registered the extra Signal account with Home Assistant? Or the destination phone number I want to send a notification text to?

If in the Terminal, I ran them and get no output back.

rkhanso commented 3 years ago

I thought it was odd that whenever I use my own phone number (which I also have the Signal app on) it works. I don't need Signal app on every phone that I want to send a text message to, do I? I wouldn't think so, but I shouldn't assume. I know my brother also has Signal on his phone. Maybe I should send him a test text from HA.

I thought it was odd that when I send myself a notification from Home Assistant, it works. But anyone else, it doesn't.

bbernhard commented 3 years ago

You can run them either in the HA terminal (which I suppose is a normal terminal, right?) or any other linux terminal. If you run the curl command on your local machine you need to replace 127.0.0.1 with the IP address of the machine where the HA addon is running. The number parameter corresponds to the number you've registered with signal.

bbernhard commented 3 years ago

I thought it was odd that whenever I use my own phone number (which I also have the Signal app on) it works.

If I understood you correctly, then you are using the same number for HA and your private phone number, right?

rkhanso commented 3 years ago

For HA, I am using my Google Voice number. It's different than my mobile phone number. It's a spare phone number that I use occasionally and can also send/receive text messages. This way I was able to get the verification code from Signal to set up with Home Assistant. This setup works ONLY when I send notifications to MY personal Cricket Mobile Phone number. But not to my wife's Cricket Mobile Phone Number, nor back to my Google Voice Number.

I just tried sending a notification from HA to my brother since he also has Signal app on his mobile phone. He didn't get anything either.

Then I sent one to my mobile phone after all that to make sure it did work. And it does work to my mobile phone.

Here is the configuration.yaml, showing mine and my wife's config. The only thing different is the name and the destination phone number used. One works, one doesn't. If I send my wife's phone a text directly from Google Voice, she gets those.

notify:
  - name: rogersignal
    platform: signal_messenger
    url: "http://myurl.duckdns.org:8080"
    number: !secret gmail_signal_phone_reg
    recipients:
      - "+1myphonenumber"
  - name: brendasignal
    platform: signal_messenger
    url: "http://myurl.duckdns.org:8080"
    number: !secret gmail_signal_phone_reg
    recipients:
      - "+1herphonenumber"
rkhanso commented 3 years ago

You can run them either in the HA terminal (which I suppose is a normal terminal, right?) or any other linux terminal. If you run the curl command on your local machine you need to replace 127.0.0.1 with the IP address of the machine where the HA addon is running. The number parameter corresponds to the number you've registered with signal.

I have a bunch of Raspberry Pi on my LAN and used one of them to run the commands you provided. I got no response at all and had to CTRL C to get back to the terminal

`pi@raspberrypi:~ $ curl -X GET -H "Content-Type: application/json" 'http://myurl.duckdns.org:8080/v1/receive/+1myphone'

^C pi@raspberrypi:~ $ curl -X 'GET' 'https://myurl.duckdns.org:8080/v1/identities/+1myphone' -H 'accept: application/json'

^C pi@raspberrypi:~ $`

And yes, I can ping my Home Assistant using the External URL from inside the LAN: pi@raspberrypi:~ $ ping myurl.duckdns.org PING myurl.duckdns.org (75.168.97.107) 56(84) bytes of data. 64 bytes from xx-xx-xx-xx.mpls.qwest.net (xx.xx.xx.xx): icmp_seq=1 ttl=64 time=0.780 ms 64 bytes from xx-xx-xx-xx.mpls.qwest.net (xx.xx.xx.xx): icmp_seq=2 ttl=64 time=0.624 ms ^C --- myurl.duckdns.org ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 2ms rtt min/avg/max/mdev = 0.624/0.702/0.780/0.078 ms pi@raspberrypi:~ $

bbernhard commented 3 years ago

For HA, I am using my Google Voice number. It's different than my mobile phone number.

just to be sure: you do not have the number associated with another signal app, do you? signal-cli which this REST API wrapper is based on assumes that only one signal app is using the number.

I have a bunch of Raspberry Pi on my LAN and used one of them to run the commands you provided. I got no response at all and had to CTRL C to get back to the terminal

that's odd. How long did you wait? signal-cli is a Java based application and is pretty slow on ARM based machines (like the raspberry pi). It takes quite a bit (20+ seconds) for the request to complete.

If you want to verify whether you can reach the REST API from your raspberry pi's on your LAN, you can execute the following request:

curl -X GET -H "Content-Type: application/json" 'http://myurl.duckdns.org:8080/v1/about'

This one should should return something in just a few ms.

bbernhard commented 3 years ago

You can also check the Addon log file whether the HTTP request hits the REST API. You should see something like this in the logs:

[GIN] 2021/03/21 - 19:45:32 | 400 | 17.02365478s | 192.168.2.100 | POST "/v1/receive"

rkhanso commented 3 years ago

For HA, I am using my Google Voice number. It's different than my mobile phone number.

just to be sure: you do not have the number associated with another signal app, do you? signal-cli which this REST API wrapper is based on assumes that only one signal app is using the number.

I have a bunch of Raspberry Pi on my LAN and used one of them to run the commands you provided. I got no response at all and had to CTRL C to get back to the terminal

that's odd. How long did you wait? signal-cli is a Java based application and is pretty slow on ARM based machines (like the raspberry pi). It takes quite a bit (20+ seconds) for the request to complete.

If you want to verify whether you can reach the REST API from your raspberry pi's on your LAN, you can execute the following request:

curl -X GET -H "Content-Type: application/json" 'http://myurl.duckdns.org:8080/v1/about'

This one should should return something in just a few ms.

I re-ran those two commands and waited about a minute before I got the following for both commands, and trying both http: and https: curl: (7) Failed to connect to myurl.duckdns.org port 8080: Connection timed out

Then I tried curl -X GET -H "Content-Type: application/json" 'http://myurl.duckdns.org:8080/v1/about' and it gets the same error: curl: (7) Failed to connect to myurl.duckdns.org port 8080: Connection timed out

But then I sent more test notifications to test to see if it's working and it still works only to my own mobile number. Not my wife's or anywhere else.

And in the Add-on logs, I see a bunch of this: [GIN] 2021/03/22 - 15:24:41 | 200 | 55.899µs | 192.168.2.100 | GET "/v1/about" [GIN] 2021/03/22 - 15:24:46 | 201 | 4.872869499s | 192.168.2.100 | POST "/v2/send" [GIN] 2021/03/22 - 15:25:21 | 200 | 40.728µs | 192.168.2.100 | GET "/v1/about" [GIN] 2021/03/22 - 15:25:30 | 400 | 8.210822912s | 192.168.2.100 | POST "/v2/send" [GIN] 2021/03/22 - 15:28:26 | 200 | 45.102µs | 192.168.2.100 | GET "/v1/about" [GIN] 2021/03/22 - 15:28:34 | 400 | 8.090724784s | 192.168.2.100 | POST "/v2/send" [GIN] 2021/03/22 - 15:28:57 | 200 | 45.133µs | 192.168.2.100 | GET "/v1/about" [GIN] 2021/03/22 - 15:29:02 | 201 | 4.523757632s | 192.168.2.100 | POST "/v2/send"

mdegat01 commented 3 years ago

I thought it was odd that whenever I use my own phone number (which I also have the Signal app on) it works. I don't need Signal app on every phone that I want to send a text message to, do I? I wouldn't think so, but I shouldn't assume. I know my brother also has Signal on his phone. Maybe I should send him a test text from HA.

I thought it was odd that when I send myself a notification from Home Assistant, it works. But anyone else, it doesn't.

This comment suggests a bit of confusion. You're aware that you aren't sending a text message right? This application hooks up to the Signal service and that can only send messages between Signal accounts. It's not possible for this application to send an SMS, it can only send messages to people who have the app and have created a signal account for their phone number.

I know the phone app can become your normal text messaging app and handle SMS, MMS, and Signal messages all in one place but that capability is exclusively for the phone app. Even Signal's official mac and windows apps can't do that, they only see and send Signal messages, same with this application.

haberda commented 3 years ago

This may not have anything to do with your issue, but are you exposing this service to the internet? Personally I would not do that. If possible you should only use this over a LAN because there is no authentication mechanism.

If you are pointing to an external URL it's possible that is causing the issue due to dns or latency issues. Another possibility is if you did not open the 8080 port on your router the connection would not be made. As for why it works for one number but not another, the only thing I can think of is the working number is maybe using an internal IP address rather than your external one.

rkhanso commented 3 years ago

I thought it was odd that whenever I use my own phone number (which I also have the Signal app on) it works. I don't need Signal app on every phone that I want to send a text message to, do I? I wouldn't think so, but I shouldn't assume. I know my brother also has Signal on his phone. Maybe I should send him a test text from HA. I thought it was odd that when I send myself a notification from Home Assistant, it works. But anyone else, it doesn't.

This comment suggests a bit of confusion. You're aware that you aren't sending a text message right? This application hooks up to the Signal service and that can only send messages between Signal accounts. It's not possible for this application to send an SMS, it can only send messages to people who have the app and have created a signal account for their phone number.

I know the phone app can become your normal text messaging app and handle SMS, MMS, and Signal messages all in one place but that capability is exclusively for the phone app. Even Signal's official mac and windows apps can't do that, they only see and send Signal messages, same with this application.

That is the issue I suppose. If this works like the Telegram app, then it's not what I'm looking for. I thought it was just a link into the same Signal platform that I use to send SMS from my phone to non-Signal users and that they would receive the text. I thought that HA would work the same as if I send from my phone to non-Signal users. The way I interpreted the directions at https://www.home-assistant.io/integrations/signal_messenger/ didn't indicate that the recipient also needed to have the Signal app on their phone. Or maybe I just hoped that was the case?

I'm really looking for a way to send a SMS/text message to any phone number, not needing any other platform as an overlay. Just a phone number.

I apologize, but thank you for your effort in helping me. Sorry it was for nothing.

bbernhard commented 3 years ago

This may not have anything to do with your issue, but are you exposing this service to the internet? Personally I would not do that. If possible you should only use this over a LAN because there is no authentication mechanism.

If you are pointing to an external URL it's possible that is causing the issue due to dns or latency issues. Another possibility is if you did not open the 8080 port on your router the connection would not be made. As for why it works for one number but not another, the only thing I can think of is the working number is maybe using an internal IP address rather than your external one.

Totally agreed! If you want to expose the Signal REST API publicly I would suggest to add a reverse proxy in front of it to add SSL and add some sort of authentication (basic auth, token based etc).

bbernhard commented 3 years ago

@rkhanso this looks like what you are looking for: https://www.home-assistant.io/integrations/twilio/

But you have to pay for the twilio service

rkhanso commented 3 years ago

I was trying to go free. There's also notify.events that is pretty cheap.

haberda commented 3 years ago

You can also send MMS messages via email. Every cell phone has an MMS email address that you can send to using the email integration. The email address is based on your cell provider but can usually be found pretty easy by a google search. I did that before Signal.

rkhanso commented 3 years ago

You can also send MMS messages via email. Every cell phone has an MMS email address that you can send to using the email integration. The email address is based on your cell provider but can usually be found pretty easy by a google search. I did that before Signal.

I tried that and couldn't get it to work. I'll look at it again though.

thanks for all the efforts.

mdegat01 commented 3 years ago

You can also send MMS messages via email. Every cell phone has an MMS email address that you can send to using the email integration. The email address is based on your cell provider but can usually be found pretty easy by a google search. I did that before Signal.

I tried that and couldn't get it to work. I'll look at it again though.

thanks for all the efforts.

FYI, this looks like a good list if you want to try it out. You will have to ask people you want to text what their provider is though since each email is provider specific.

Also if you're willing to dig deep you could put together a solution with Tasker + the android app where you trigger a Tasker task that then sends the content via text from your phone. It's hacky but definitely possible. There's also a lot on the HA forum about tasker so plenty of people to help out.

The key with both of these is that its actually using your current phone plan to send that text so its effectively free (assuming you have an unlimited plan). It's not really possible to have a web service which texts people for you for free since texting itself isn't free and someone would have to pay for the plan.

rkhanso commented 3 years ago

Thanks mdegat01 that's exactly what I ended up going with. I have Gmail working with HA to send emails that get converted to text to the recipient phones. It's working.