Voice over IP Integration - Call from Any SIP Softphone

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"
}```