Home Assistant SIP Gateway

@meni123 I released version 2.8 which includes some dependency updates. Please check if this fixes the segfault.

I checked with the new version and it still crashes,
Attached is the log from the crash
Thank you for the wonderful plugin and your efforts to resolve the issues

23:17:48.822            pjsua_aud.c !Destroying player 0..
23:17:48.822            pjsua_aud.c  Creating file player: /tmp/tmpltkdux1y.wav..
23:17:48.823           wav_player.c  .File player '/tmp/tmpltkdux1y.wav' created: samp.rate=24000, ch=1, bufsize=4KB, filesize=62KB
23:17:48.823            pjsua_aud.c  .Player created, id=0, slot=2
23:17:48.823            pjsua_aud.c  Conf connect: 2 --> 1
23:17:48.823           conference.c  .Port 2 (/tmp/tmpltkdux1y.wav) transmitting to port 1 (sip:[email protected])
| 23:17:48.823110 [1] Calling home assistant service on domain lock service lock with entity lock.delet
Fatal Python error: Segmentation fault
Thread 0x00007f25448dcb48 (most recent call first):
  File "/usr/local/lib/python3.10/socket.py", line 705 in readinto
  File "/usr/local/lib/python3.10/http/client.py", line 279 in _read_status
  File "/usr/local/lib/python3.10/http/client.py", line 318 in begin
  File "/usr/local/lib/python3.10/http/client.py", line 1375 in getresponse
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 444 in _make_request
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703 in urlopen
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 487 in send
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 701 in send
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 587 in request
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 59 in request
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 115 in post
  File "/ha-sip/ha.py", line 109 in call_service
  File "/ha-sip/call.py", line 376 in handle_action
  File "/ha-sip/call.py", line 361 in handle_menu
  File "/ha-sip/call.py", line 295 in handle_dtmf_digit
  File "/ha-sip/call.py", line 178 in handle_events
  File "/ha-sip/main.py", line 172 in main
  File "/ha-sip/main.py", line 177 in <module>
Extension modules: _pjsua2, charset_normalizer.md (total: 2)
/run.sh: line 36:   213 Segmentation fault      (core dumped) python3 /ha-sip/main.py
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

That segfault is happening inside python library code, I cannot see a way how this is happening except devices with very small memory. What system is home-assistant running on? Architecture (amd64, aarch64, etc.) and how much RAM does that system have?

It’s a powerful system.
Home Assistant Supervised on Debian,
The processor is: CPU: Intel N100 4 cores 4 threads up to 3.40GHz 6MB Cac
Architecture: amd64 x86_64
The RAM is onboard LPDDR5 8GB 4800MHz

Hi all together,
I think, my problem is to initialize the sound device:

23:42:17.823            pjsua_aud.c  .Opening null sound device..
23:42:17.824           pjsua_core.c  bind() error: Address in use [status=120098]
23:42:17.824           endpoint.cpp  pjsua_transport_create(type, &tcfg, &tid) error: Address in use (status=120098) [../src/pjsua2/endpoint.cpp:2243]
Traceback (most recent call last):
  File "/ha-sip/main.py", line 177, in <module>
    main()
  File "/ha-sip/main.py", line 160, in main
    end_point = sip.create_endpoint(endpoint_config)
  File "/ha-sip/sip.py", line 27, in create_endpoint
    end_point.transportCreate(pj.PJSIP_TRANSPORT_UDP, sip_tp_config)
  File "/root/.local/lib/python3.10/site-packages/pjsua2-2.13-py3.10-linux-x86_64.egg/pjsua2.py", line 7196, in transportCreate
    return _pjsua2.Endpoint_transportCreate(self, type, cfg)
pjsua2.Error
23:42:17.845           pjsua_core.c  Shutting down, flags=0...
23:42:17.845           pjsua_core.c  PJSUA state changed: INIT --> CLOSING

Home assistant is running in Proxmox on an Intel NUC
Any idea to solve the problem?

Best regards
Bany

Hi Bernd,

ha-sip does not use any sound device. It’s trying to listen on the port specified in your configuration, but that’s already in use. Do you have any SIP server running on the same interface already? You can change the port of ha-sip on the configuration page to something else.

Regards,
Arne

Hi Arne
thanks for your quick answer.
The error disappears by changing the port. But I don’t know where it could be in use. I uninstalled Asterisk, without any success.
May it be a problem to use a VoIP-phone in the same network?
Beste regards
Bany

No, the phone cannot cause the problem. It must listen on the same IP address.

then I don’t have any idea where to look for the used port… - do you?

I found the plug-in - now port 5060 works

1 Like

for all who wants to use it with “Deutsche Glasfaser”

sip_global:
  port: 5060
  log_level: 5
  name_server: 8.8.8.8

sip:
  enabled: true
  registrar_uri: sip:dg.voip.dg-w.de
  id_uri: sip:[email protected]
  realm: "*"
  user_name: "3050123456"
  password: PASSWORD
  answer_mode: listen
  settle_time: 1
  incoming_call_file: ""
1 Like

Hi,
This add-on looks good and I have done some reading on pjsua.

I am using hassio on a pi4 and have a usb headset available.

Is it possible to use the headset in the pi4 as a sound device, so I can make calls and record audio, etc?

Thanks, Robert

Hi Robert,

ha-sip does not support any audio hardware.

Regards,
Arne

Hi Arne,

I am trying to transfer an incoming call to a particular sip uri.

Your example is:

service: hassio.addon_stdin
data_template:
    addon: c7744bff_ha-sip
    input:
        command: transfer
        number: sip:**[email protected]
        transfer_to: sip:**[email protected]

Can you please provide a little context for this example?

I have setup my ha-sip on **[email protected]
If I use **611 to call **620 I would like the call to be transferred to **623

I have set this example up as a script. I have called **620 from **611 and manually answered the call. Then executed the script but nothing has happened.

Do I need to dial **623 before making the transfer?

I suppose I do not understand the capabilities of ha-sip. Should all incoming calls go to it (like an old fashioned telephone operator)?

I have been trying to use the software with my dect phones on my fritzbox and am unsure if they are not responding as they should.

Thanks, Robert

Hey guys,

since some days the webhook didn’t work.
I found this in the supervisor:

23-06-10 21:08:29 WARNING (MainThread) [supervisor.addons.options] Unknown option 'cache' for ha-sip (c7744bff_ha-sip)
23-06-10 21:08:29 WARNING (MainThread) [supervisor.addons.options] Unknown option 'cache_dir' for ha-sip (c7744bff_ha-sip)
23-06-10 21:08:29 WARNING (MainThread) [supervisor.addons.options] Unknown option 'time_memory' for ha-sip (c7744bff_ha-sip)
23-06-10 21:08:29 WARNING (MainThread) [supervisor.addons.options] Unknown option 'base_url' for ha-sip (c7744bff_ha-sip)
23-06-10 21:08:29 WARNING (MainThread) [supervisor.addons.options] Unknown option 'service_name' for ha-sip (c7744bff_ha-sip)

any idea how to fix this?
thanks
Bany

@arnonym
Is there a way to connect this extension to Voice over IP integration?
That I call the number I wrote in the extension and the voice assistant answers me?
Thank you

Hi Robert,

did not see your post, so sorry for the late answer. You don’t need to call the destination extension before transfering a call. Looks like you did everything right, to check what is going wrong I recommend checking the logs and post again, if you need help interpreting those.

Arne

Hi Meni,

I actually tried that with varying success, as the integration was not able to detect when the given command was completed (I guess silence detection is not working correctly), but that could also depend on the hardware you’re using.

To do this you will need to create an account without user/password like this:

enabled: true
registrar_uri: sip:<LAN IP address of your home assistant without the angle brackets>
id_uri: ""
realm: "*"
user_name: ""
password: ""
answer_mode: accept
settle_time: 1
incoming_call_file: ""

Also by default the sip integration is listening on the same port as ha-sip, so you need to change one of them. I changed the sip integration to port 5061 and ha-sip stayed on 5060.

After that you can dial

service: hassio.addon_stdin
data_template:
    addon: c7744bff_ha-sip
    input:
        command: dial
        number: sip:ha@<LAN IP address of your home assistant without the angle brackets>:5061
        webhook_to_call: 
            call_established: voice-assistant-connected

to connect to the voice assistant (probably you want to do this after a call_established web-hook is called on the incoming call from your sip phone, you need to use the global web-hook from the ha-sip configuration for this).

Finally you can connect both calls with

service: hassio.addon_stdin
data_template:
    addon: c7744bff_ha-sip
    input:
        command: bridge_audio
        number: sip:<id of your sip phone call>
        bridge_to: sip:<id of the sip integration/voice assistant call>

probably also on a web-hook callback (I already included this option on the call to the voice assistant: voice-assistant-connected). You can look up the ID’s in the ha-sip log ("Registering call with id ").

After writing that down (all from memory, I did that test over a month ago), that seems rather complex but I hope you get an idea how this is working.

Good luck and keep me informed :slight_smile:

Arne

1 Like

Thank you,
I’m checking it, so far I haven’t succeeded,
He connects to the voice assistant but there is no response,
I saw that Opus codecs need to be installed. Is it installed in your extension?
Thanks

Yes, the Opus codec is included. You can see the list of supported codecs in the logs when the plugin starts.

1 Like

I had the same issue after switching to a newer version of HA
After the update I got the error, that the base_url in my configurations.yaml is not accepted.
After deleting the base_url I got the same sound.

Anyway, I changed to Nabu Casa tts using:

platform: cloud
language: de-DE
service_name: cloud_say

Which works well.
At the beginning I had started with en-US and changed to de

Long story short:
de only creates a beep sound
de-DE works well.

I hope it helps (if not fixed already) - just wanted to share my findings…

1 Like