Voice over IP Integration - Call from Any SIP Softphone

The new Voice over IP (VOIP) integration is so much more powerful than just integrating with old-school phones. Since the project doesn’t support it, I figured I’d post my findings on the non-supported uses and we can expand this.

FYI: Let’s not keep bugging the team about updating the integration page. Let’s just keep the info about this in this post until this application goes from “unsupported” to “supported.”

I don’t claim to be master of VOIP stuff, but I use it in my day to day office and I’ve managed to set it up so that I can call my Home Assistant instance from my office softphone (either my cell phone or my desktop with a headset) and access the Voice Assistant pipeline of my choosing.

VOIP Integration - What Is It?

The VOIP Integration can be added here: Link to Integrations: Add integration – My Home Assistant

This creates a VOIP Client on your network - a virtual telephone number that you can call. Home Assistant can pipe that call into an assistant pipeline so that you can have a chat with whatever assistant you’ve set up.

The tutorial on the integration page envisions a purely hardware-based connection. But it doesn’t have to be just that. You can use a SIP Softphone, a software that makes VOIP telephone calls using the Session Initiation Protocol (SIP).

Note that despite the flaw in the browser version of Home Assistant requiring https, you do not need https to make the call from a SIP Softphone

What do you need?

  1. Home Assistant up and running with the VOIP Integration set up using the above link.
  2. A SIP Softphone, set up on the hardware of your choice

What Softphones have been tested and are working?

(please report in this post; I’ll do my best to keep this updated)

Windows

  • MicroSIP

Android

  • Mizudroid

How To (Local Network)

  1. Determine your Home Assistant’s local IP Address (e.g. 192.168.1.100)
  2. Confirm the port that the VOIP Integration is listening on (default: 5060) and that the port isn’t being blocked by a firewall on your Home Assistant server.
  3. Install your softphone. Make sure that the Opus codec is enabled.
  4. Using your softphone, dial your Home Assistant instance by entering the following, based on the above: sip:192.168.1.100:5060
  5. When you hear the prompt, access your integrations page. You should see a new device under Voice over IP. Click it, and turn on the “Allow Calls” switch. Confirm that the “Assistant Pipeline” reflects the one that you want to use (see the tutorials regarding the different Assistant Pipelines).
  6. End the call, and call the same number. You should hear a tone and be able to use whatever pipeline you’ve set.

Specific Softphone Tips

MicroSIP

  • If you have an account already set up with an existing provider, you’ll need to turn on “Enable Local Account” under the settings to be able to make the local SIP call

Mizudroid

  • You must use a login name to make the SIP call. Use sip:[email protected]:5060. Note that “ha” doesn’t need to be an active user or your own login, and it doesn’t need a password.

Version History for this Post
1.0.20230504 - Initial Post, including MicroSIP and Mizudroid

7 Likes

I have 4 VOIP lines at home, so I am familiar with VOIP. However I am not sure to understand the benefits of connecting to HA by VOIP instead of using the HA App.

My family and I are all way too well trained on the Google Assistant. In fact, I rarely interact with the HA visual interface; I just ask the Assistant to handle it. My plan is to get shortcuts set up on the SIP clients so that rather than use Google Assistant, we can use a totally offline local system to turn on switches, scenes, etc.

OK, I get it. The advantage is then that it works locally even if internet is down. That is smart as Comcast has been down at least 6 times in our town, in the past 10 days :sob:
But can this solution work on speakers similar to Google Home and Alexa, and if so, which models ?

That I wouldn’t know. You could probably use the Grandstream adaptor method to use a speakerphone (so, no hot word but a simple button press), but I can’t think of a system off the top of my head that would be as hands free.

That’s why I wanted softphone. I have the software on my cell phone so I can just grab that and go. Cell is in my pocket all the time anyway. I could also set up a softphone on my parents’ cells so that when they’re home they can interact with lights by voice and without having to give them access to the actual HA interface.

Understood & thanks. Personally, if I have to use my cell phone, I may as well use the HA App and using Alexa and/or GH still seems more practical than picking up the home (VOIP) phone.
This being said, I of course welcome any new HA development and this VOIP option may evolve into something more practical.

1 Like

One big benefit is that HA app needs https for voice to work where as the sip clients just need the ip address so anyone using plan http can interact without changing their setup.

Also potential for using wake words via automate / tasker / macrodroid apps (altho from testing the mizudroid call intent seems to be broken atm)

1 Like

I had thought of remapping the bixby button (if that’s still a thing; I haven’t used a Sammy since the Galaxy S9). Hardware button, plus Tasker? Yes please.

Thanks, this helped!
I successfully called the HA with mizudroid and was able to setup the devic in HA.

However when I call HA now it seems to register the call but just hangs up immediately.

Logger: homeassistant
Source: /usr/src/homeassistant/homeassistant/runner.py:137
First occurred: 07:41:49 (1 occurrences)
Last logged: 07:41:49

Error doing job: Exception in callback None()
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 1035, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "/usr/local/lib/python3.10/site-packages/voip_utils/voip.py", line 131, in datagram_received
    raise err
  File "/usr/local/lib/python3.10/site-packages/voip_utils/voip.py", line 121, in datagram_received
    audio_bytes = self._rtp_input.process_packet(
  File "/usr/local/lib/python3.10/site-packages/voip_utils/rtp_audio.py", line 70, in process_packet
    audio_bytes = opuslib.api.decoder.decode(
  File "/usr/local/lib/python3.10/site-packages/opuslib/api/decoder.py", line 246, in decode
    raise opuslib.exceptions.OpusError(result)
opuslib.exceptions.OpusError: b'buffer too small'

Any idea what’s going on and what to do about it?

Is it possible for you to back up your settings, clear your data on Mizudroid, and try again? In my case, I’m using a fresh install of Mizudroid so all of my settings are purely default.

Opus is the audio codec being used to handle the audio data (think of other formats like MP3, FLAC, OGG, etc.). I actually don’t use it with my other VOIP providers, so I had to manually adjust my settings to turn it on in MicroSIP. If you’re using Mizudroid with other providers, maybe you changed your setting?

This was a first time install of mizudroid. No settings were changed, and I did actually reset the whole app this morning, to try again. Same result :cry:

My install is HAOS 10.1 and I associated the Home Assistant Cloud as Assist Pipeline.

Would be interesting what the differences are between a working and non working environment.

As mentioned by others, it’s not really practical at the moment, but it would have been an easy way to play around with the voice Assistant to prepare for what is about to come.

Sorry, not sure. Maybe try setting up another assist pipeline (e.g. ChatGPT)? Can you get to the Assistant using a browser and the HTTPS connection?

Yes, it works in the browser through NABU casa

Thank you for your help but I’ll give up for now. No chance to get any support as this solution is unsupported and I am not able to make any sense of the little debug information available.

I had an idea of connecting my SIP doorbells via this integration so that visitors could talk to OpenAI while I’m away but it looks like Mobotix does not support Opus codec.

I am trying to use MicroSIP and it appears to connect and device gets added in HA but I hear no audio. Also I am trying to connect to with a SPA112 and having issues there but it adding device but phone goes into busy. But just to focus on MicroSIP is there any suggestions to check?

Thought I read somewhere that my HA needed to be using https?

Also that the Opus codec is needed, which is why the SPA112 is probably not working right.

Testing with Zoiper is the same as MicroSIP. It connects and device shows up in HA, but no audio.

Seems like I am in a similar place trying to call from linphone. I was able to get the device to show up but no audio from homeassistant yet. From the logs it looks like the issue is linphone might be using “padding or extension headers” which are apparently not currently supported.

Also another issue I was having before was making sure the RTP ports were opened. It randomly picks an RTP port so it seems like you basically have to open all ports >1024, which probably should be avoided, especially if the HA node is accessible from the internet.

Edit adding error message from log:

2023-05-06 14:50:35.624 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback None()
Traceback (most recent call last):
  File "/usr/lib64/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/lib64/python3.11/asyncio/selector_events.py", line 1169, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "/srv/homeassistant/lib64/python3.11/site-packages/voip_utils/voip.py", line 131, in datagram_received
    raise err
  File "/srv/homeassistant/lib64/python3.11/site-packages/voip_utils/voip.py", line 121, in datagram_received
    audio_bytes = self._rtp_input.process_packet(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib64/python3.11/site-packages/voip_utils/rtp_audio.py", line 66, in process_packet
    raise RtpError("Padding and extension headers not supported")
voip_utils.error.RtpError: Padding and extension headers not supported

I’m trying Linphone too and having the same issues. I’ve managed to do the initial connection but to get a follow on call recognised unless I reload the integration. On top of the padding error above, I also get this error:


Logger: voip_utils.sip
Source: /usr/local/lib/python3.10/site-packages/voip_utils/sip.py:134 
First occurred: 6 May 2023 at 20:27:57 (18 occurrences) 
Last logged: 08:27:42

Unexpected error handling SIP INVITE
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/voip_utils/sip.py", line 57, in datagram_received
    method, ruri, headers, body = self._parse_sip(message)
  File "/usr/local/lib/python3.10/site-packages/voip_utils/sip.py", line 216, in _parse_sip
    method = line_parts[0]
IndexError: list index out of range

Resolution for MicroSIP:

Opus is not enabled by default, after adding it to enabled coded, it works:

image

1 Like

I’m seeing that as well, it appears linphone is sending a message with two empty lines for some reason.