Voice over IP Integration - Call from Any SIP Softphone

I would like to actually ring the phone. Sort of like a doorbell chime or additional alarm siren or critical alert from ha. It would be even better if upon answering ha spoke the tts alert, but i’d settle for a ring to begin with.

Been looking at asterisk and ha-sip, but neither seem to actually ring the phone. Grandstream device btw. Can’t find anything in GS docs either. Any ideas? It seems like the next logical step in year of the voice to me, but literally i find no info on doing it.

1 Like

@blindguynar I don’t know how the mods are on the HA forums, but on the other opensource projects I’ve worked with and for, the general rule is one topic per thread (I realize I didn’t follow my own advice). But I suggest that you create a new topic with a subject line to catch the right attention to your idea. Make sure you tag me in your new thread, I do have a few ideas you can try not relevant to SIP Softphones.

I wanted to share with anyone who is using regular Asterisk and PJSIP that I was finally able to get calling to HA working. Here is what I had to do:

Install opus codec - basically follow the directions from Asterisk Tutorials: How to install and use Opus codec in Astersik

Add pjsip endpoint to pjsip.conf

[5000]
type=endpoint
context=users
disallow=all
allow=opus
callerid="Home Assistant"

I think the endpoint name (5000) can be whatever you want, it will get used in the next step.

Create an entry for dialing HA in the dialplan extensions.conf

exten => 5000,1,Dial(PJSIP/5000/sip:ha@<HA IP>:5060)

Replace with the IP address homeassistant is running on.

After that I was able to dial 5000 from my office phone and tell homeassistant to do stuff. Maybe this is obvious to people that have been using Asterisk for awhile but it took me a long time to realize I needed the PJSIP endpoint.

1 Like

I haven’t had a landline in several decades but suddenly I have two very compelling reasons to set one up.

  1. teach my two little girls how to pick it up and dial 911 (emergency dispatch in the US) in the case of a real emergency.
  2. use it to control my smart home and take my nerdiness to the next level just for fun.

I bought a grandstream and a vintage phone and quickly accomplished #2. I’m a bit stumped on accomplishing #1. Looks like I probably need to subscribe to a voip service provider and provision my grandstream to connect to it. This presents the issue of whether it’s possible to even do both since the grandstream is currently set to auto-dial strait to my HA server for Assist. Obviously, I’d prioritize the 911 for less confusion to the little ones. Maybe reach the Assist through some other dial sequence?

Is this even possible to have both with one phone line? Any advice greatly appreciated.

1 Like

Hi, why would this not work?!
#1 uses the grandstream to set up a phonecall with your VoIP service
#2 uses the grandstream to communicate locally to your HA assist

Instructions for connecting FusionPBX with the Home Assistant Voice over IP integration:

  1. Setup FusionPBX, provision a SIP device, and verify with a test call. The specifics for completing this step are outside of the scope of these instructions.
  2. Enable Opus module: Advanced menu > Modules option > Codecs header - Set “Opus” to Enabled = True and Start the module.
  3. Add Opus codec to the list of preferred codecs: Advanced menu > Variables option > Codecs header – Add “OPUS” to the beginning of global_codec_prefs and outbound_codec_prefs. Set media_mix_inbound_outbound_codecs to true.
  4. Adjust the SIP Profiles: Advanced menu > SIP Profiles option > Settings section > Internal profile – ensure the following settings are set properly.

inbound-late-negotiation=true,true
inbound-codec-negotiation=generous,true

  1. On your SIP device, add Opus as an active and preferred codec. The process for accomplishing this varies by device and manufacturer. If you are using FusionPBX to provision your SIP device, you may have to adjust the appropriate variables within Advanced menu > Default Settings option > Provision header.
  2. Add the Outbound Dialplan: Dialplan menu > Outbound Routes option. Create a new dialplan with the following settings.

Gateway = enum (we will change this in a moment)
DIalplan Expression = ^111$ (replace 111 with the number you wish to use to reach HA)
Enabled = true
Description = Home Assistant

  1. Edit the dialplan: Dialplan menu > Outbound Routes option > enum.### dialplan.
    a. Change the name of the dialplan to something like “Home Assistant.###” (with ### matching the extension number you chose).
    b. Configure the following settings. For settings where a > true is at the end, this signifies the Enabled column within the Dialplan.

action > set > hangup_after_bridge=true > true action > set > callee_id_name=Home Assistant > true action > set > callee_id_number=### > true (number of the extension you chose) action > bridge > sofia/internal/sip:<HA IP Address> > true (insert IP addr of Home Assistant)

  1. Reboot FusionPBX to ensure everything has taken effect (optional step).
  2. Attempt to call Home Assistant using the extension number you defined above.

so I’ve managed to call from my mac softphone, via FreePBX to Home Assistant.

It plays the ‘go’ sound (the two tones), but when I speak, nothing happens.

When I look in debug, it looks like this, even minutes later (see circle spinning next to STT)

Screenshot 2023-09-12 at 12.51.16

I got mine working using microsip via asterisk to the point where I could hear the ‘This is your home assistant’ loop, I then clicked ‘allow calls’ in hass but when i call it back, i get a ‘not available’ error from my freepbx. Did you have any issues like that/

this is exactlly what i’m looking for. I would like to have like an entitiy in the VOIP integration, to ring the phone. The hook is already detected. So I asume that this would not a big deal for the creator. Did you manage to start a new topic/request this feature?

Maybe this is completely off-topic… I will try nevertheless. I have a VoIP phone in the house of my mum and I would like to use it as an alarm clock to wake her up because her hearing is very bad. Would it be possible to ring the voip phone from HA???

1 Like

If you find a solution for this, please let me know. I’m interested in the exact same feature. Maybe we should contact the developer

1 Like

I tried to build a call flow app for the 3CX pbx that is hosting the phone, but I can’t get it to work… For now I just send her a notification to her iPhone through HA. But it would be so much better if I could call her VoIP phone.

For years I have used Home Assistant and various pbx systems, e.g. 3cx, freepbx, VitalPBX which was good until they limited the extensions to only 10?? Now I have built MikoPBX, which is made by Russian developers and is free to use, no restrictions, but you get paid support and add-ons.

VitalPBX had support for Home Assistant, I would like the same for the MikoPBX system. I just got the Goip adapter working. Or it would also be good if someone developed support for Home assistant in the Goip adapter.

Any of you guys figured out an easier way to broadcasting TTS generated from HA on your SIP phones? :slight_smile: Thanks!

hey @gravyflex did you ever find a solution for this? I’m in the same boat as you… I can issue voice commands and they work great, but all I ever hear is buzzing.

1 Like

Exactly the same here. DP750, voice commands work, but I hear only buzzing.

Thanks for posting this! I was really surprised to see such a specific device mentioned on the docs rather than showing that anything with SIP URI dialing can call into it.

I was able to get one or two calls to go through before realizing I had to ‘allow calls’ on the VoIP device in the Integration, but ran into an issue after enabling that:

  • Experiencing dead air on the SIP call, but it connects and shows the call timer.
  • I used tcpdump on haos after installing it through the SSH add-on, and pulled it into wireshark.
  • Capture from haos shows the RTP being received, but nothing being sent out.
  • I believe that since the capture is on the interface level, there might be some sort of firewall blocking the RTP from coming in or out of the homeassistant application on the server.

Has anyone run into this, or at least familiar enough with HAOS to know where to look for an internal firewall or allowing a port range being blocked?

Thanks!

1 Like

ok, I am SO CLOSE to getting this to work. But something is wrong with authentication.

System: Latest version of HASS running on a synology in a container using CORE.
3cx local running on a windows server, latest version.
No trunk to the outside world - used as an intercom only.
A trunk to HASS:

  • default route is to my extension
  • random main trunk number
  • set to do not require authentication, and the HASS ip:5060
  • autodiscover off
  • only the opus codec defined
  • transport protocol any
type or paste code here

I then have HA-SIP set up with:
Port 5061
log level 5
name server: (IP of my DNS)
Cache dir: /tmp/audio_cache (this does exist)

sip
enabled: true
registrar_uri: sip:Mydomain.ny.3cx.us
id_uri: sip:[email protected]
realm: "*"
username: {what do I put here from 3cx? I've tried email, sip address, just the extension in quotes etc}
password: What password do I use here-  the same one as for the user above?
answer_mode: listen
Settle_time: 1
incoming_call_file: ""

Whenever I try to fire up HA-sip I get:


22:54:46.025      sip_auth_client.c  ...Digest algorithm is "MD5"
22:54:46.026           pjsua_core.c  ....TX 746 bytes Request msg REGISTER/cseq=27779 (tdta0x7f73d51866f8) to UDP 192.168.2.245:5060:
REGISTER sip:Mydomain.ny.3cx.us SIP/2.0
Via: SIP/2.0/UDP 192.168.2.205:5061;rport;branch=z9hG4bKPjjL-cJJaBmLU0EGsymSi5jylMs8IS-i98
Max-Forwards: 70
From: <sip:[email protected]>;tag=G7gkrPKq6D0j-IkExHjKBCLUAoqlShEk
To: <sip:[email protected]>
Call-ID: C8.FMaXbVVW9la-Xv1ScsNMjTfpmLb9I
CSeq: 27779 REGISTER
Contact: <sip:[email protected]:5061;ob>;+sip.ice
Expires: 300
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Proxy-Authorization: Digest username="sip:[email protected]", realm="3CXPhoneSystem", nonce="Deleted for security reasons - there is a hash here", uri="sip:Mydomain.ny.3cx.us", response="5208265f5b91b7c267c85cf59f908ec5", algorithm=MD5
Content-Length:  0


--end msg--
22:54:46.128           pjsua_core.c  .RX 334 bytes Response msg 403/REGISTER/cseq=27779 (rdata0x7f73d5367038) from UDP 192.168.2.245:5060:
SIP/2.0 403 Invalid credentials
Via: SIP/2.0/UDP 192.168.2.205:5061;rport=5061;branch=z9hG4bKPjjL-cJJaBmLU0EGsymSi5jylMs8IS-i98
To: <sip:[email protected]>;tag=c8050e7d
From: <sip:[email protected]>;tag=G7gkrPKq6D0j-IkExHjKBCLUAoqlShEk
Call-ID: C8.FMaXbVVW9la-Xv1ScsNMjTfpmLb9I
CSeq: 27779 REGISTER
Content-Length: 0


--end msg--
22:54:46.131            pjsua_acc.c  ....SIP registration failed, status=403 (Invalid credentials)
| 22:54:46.131924 [1] OnRegState: 403 Invalid credentials
22:54:46.902            pjsua_aud.c  Closing sound device after idle for 1 second(s)
22:54:46.902            pjsua_aud.c  .Closing null sound device..

Any clues as to what I’m doing wrong? I feel like I am SO CLOSE.
*

Has anyone found a way to set a fixed rtp port?

Rtp port is chosen randomly and thus a lot of ports need to be unblocked on the firewall

Ok, I now have ha-sip registring the extension successfully. However whenever I write a script to send a message I get a not an object error. I can’t seem to make the examples that use nested objects to work at all (IE the format:

addon: 
input:
  command: play_message
  number: sip:number
etc

I am consistently getting a couple of weird statuses/messages:

this one: SIP outbound status for acc 0 is not active
and this one: Error: Not an object:

Here is the script that will save but doesn’t work with a “not an object” error:

alias: Send Lee a test message
sequence:
  - sequence:
      - action: hassio.addon_stdin
        metadata: {}
        data:
          addon: c7744bff_ha-sip
          input: >
            { "command":"play_message", "number":"sip:[email protected]",
            "message":"This is a test messsage", "cache_audio": true,
            "wait_for_audio_to_finish": true }
      - action: hassio.addon_stdin
        metadata: {}
        data:
          addon: c7744bff_ha-sip
          input: |
            {
              "command": "dial",
              "number": "sip:[email protected]",
              "webhook_to_call_after_call_was_established": "hasip_web_call_established",
              "webhook_to_call": "hasip_web_listen_in",
              "ring_timeout": "hasip_web_no_answer",
              "call_established": "hasip_web_call_answered",
              "entered_menu": "hasip_web_entered_menu",
              "timeout": "hasip_web_message_timeout",
              "dtmf_digit": "hasip_web_digit_dialed",
              "call_disconnected": "hasip_web_hung_up",
              "playback_done": "hasip_web_playback_complete",
              "ring_timeout": 15,
              "sip_account": 1,
              "message": "This is a different message"
            }
description: ""
icon: mdi:phone

both of these calls fail (one uses the dial command, the other the play message command - and yes I tried doing each individually first)

0:57:02.234            pjsua_acc.c  ....SIP outbound status for acc 0 is not active
10:57:02.234            pjsua_acc.c  ....sip:[email protected]: registration success, status=200 (OK), will re-register in 300 seconds
10:57:02.234            pjsua_acc.c  ....Keep-alive timer started for acc 0, destination:192.168.2.245:5060, interval:14s
| 10:57:02.234763 [1] OnRegState: 200 OK
| 10:57:53.913152 [ ] Error: Not an object: { "command":"play_message", "number":"sip:[email protected]", "message":"This is a test messsage", "cache_audio": true, "wait_for_audio_to_finish": true }

| 10:57:54.203629 [ ] Error: Not an object: {
  "command": "dial",
  "number": "sip:[email protected]",
  "webhook_to_call_after_call_was_established": "hasip_web_call_established",
  "webhook_to_call": "hasip_web_listen_in",
  "ring_timeout": "hasip_web_no_answer",
  "call_established": "hasip_web_call_answered",
  "entered_menu": "hasip_web_entered_menu",
  "timeout": "hasip_web_message_timeout",
  "dtmf_digit": "hasip_web_digit_dialed",
  "call_disconnected": "hasip_web_hung_up",
  "playback_done": "hasip_web_playback_complete",
  "ring_timeout": 15,
  "sip_account": 1,
  "message": "This is a different message"
}```