SIP (VoIP) Monitoring for incoming calls using MQTT

Hi folks,

I’ve built a SIP (VoIP) monitoring project using MQTT which broadcasts incoming calls with CallerID.

You can find the project here:

Dockerfile for hosting sip2mqtt here:

My HAS configuration here:
https://github.com/MartyTremblay/home-assistant-config/blob/master/packages/sip_call.yaml

PRs welcomed :slight_smile:

7 Likes

This is good news. But how to install everything? I’m sorry I’m not familiar with this. Do I install this on my raspberry pi that also host my HA? What’s the command to run? Thanks.

Yeah, that’s the challenge with this integration… Unfortunately, the sip2mqtt project depends on the pjsip Python module, which isn’t available from pip and normally requires to be manually built and installed from sourcecode. I’ve included a link to my Dockerfile to facilitate this but for folks not familiar to Docker and containers, this will be a bit challenging and probably outside the scope of this thread. That being said, I’ve migrated all my HA infrastructure using Docker and I haven’t looked back since.

your docker is in raspberry pi? i know there is a thing call docker in Synology NAS.

You can actually run HAS Docker on a Raspberry Pi but I opted not to due to the memory requirements from the number of containers I run in my setup. If you’re planning on running only HAS and this Python script, you have two options available to you.

  1. Run your setup using two separate Docker containers (one for HAS, the other for sip2mqtt)
  2. Download, build, and install the pjsip Python module on your Raspberry pi and run sip2mqtt alongside of HAS. Interestingly, you can get most of the steps to doing that manually by looking at the Dockerfile

One more option to add to this list. Hass.io runs on your Pi using Docker. This sounds exactly like what you may need to get this up and running quickly on a Pi.

Here is a short turtorial how you can make a addon: https://home-assistant.io/hassio/addon_tutorial/

2 Likes

Hi @MartyTremblay, I’ve been looking for a good Voip SIP notifier on Home Assistant for a bit and fount this thread.
I was trying to pull your pjsip-docker container from dockerhub on my UnRaid server to use in conjunction with Hass.io, but I’ve been having some trouble. I’m kinda new with UnRaid and Docker in general.
Could you provide some simple guidance as to how to pull the container? It would be greatly appreciated.
Thanks!

1 Like

Hi @RevelRob

Happy to help. Can you tell me what kind of issues you’re having? I don’t know anything about UnRaid but I can’t imagine it being all that different. Is the device an Intel-based CPU?

Also, I’ve been half-seriously working on building a HA native Python component to do the same thing but having issues of my own. Perhaps I’ll post my code to see if there’s anyone having experience with asynchronous Python willing to contribute and help :wink:

1 Like

Thanks for the quick reply!
unRAID is a server OS (like Synology for example) that has docker baked in.
It’s more ui based when it comes to docker containers though, so I haven’t really learned how to pull non unRAID based containers.
I tried adding your container but it says that it’s a private repo and I don’t have permission.
It’s not listed in docker hub either so I can’t pull it there.

Right, I forgot to link my Docker Hub repo link. Try this…

https://hub.docker.com/r/retrohunter/pjsip-docker/

Thanks again!

I saw that container when searching earlier and tried to pull it but when I do, I get the following error:

root@localhost:# /usr/local/emhttp/plugins/dynamix.docker.manager/scripts/docker run -d --name='pjsip-docker' --net='bridge' -e TZ="America/New_York" -e HOST_OS="unRAID" 'retrohunter/pjsip-docker'
Unable to find image 'retrohunter/pjsip-docker:latest' locally
/usr/bin/docker: Error response from daemon: manifest for retrohunter/pjsip-docker:latest not found.
See '/usr/bin/docker run --help'.

The command failed.

Ah, that’s because I’m using the 2.x branch. Try pulling this instead:

retrohunter/pjsip-docker:2.x

Ok, so I got a bit further. I had to add the “:2.x” tag to the end of the repo.
Haha, just saw your reply.

I also mapped ‘/opt’ and added sip2mqtt.py to a sub directory named sip2mqtt.
Getting closer.
Now do I have to edit the sip2mqtt.py to include my mqtt parameters or do I add them as variables in the container?

Thanks for your help by the way.

Hrm, I think the base image I’m using has changed since the wget command is failing. Looking into it now.

1 Like

ok, built a new version and deployed to Docker Hub. Pull the latest image using the --pull directive to force an update. Then run with the following docker command.

python /opt/sip2mqtt/sip2mqtt.py -t{MQTTPORT} -a{MQTTURL} -uSip2Mqtt -p{MQTTPASS} -d{VOIP.URL} -n{SIPUSER} -s{SIPPASS} -vvvv

Alternatively, pretty sure you can use ENV variables instead.

-a MQTT_ADDRESS, --mqtt_address MQTT_ADDRESS
the MQTT broker address string
-t MQTT_PORT, --mqtt_port MQTT_PORT
the MQTT broker port number
-u MQTT_USERNAME, --mqtt_username MQTT_USERNAME
the MQTT broker username
-p MQTT_PASSWORD, --mqtt_password MQTT_PASSWORD
the MQTT broker password
-d SIP_DOMAIN, --sip_domain SIP_DOMAIN
the SIP domain
-n SIP_USERNAME, --sip_username SIP_USERNAME
the SIP username
-s SIP_PASSWORD, --sip_password SIP_PASSWORD
the SIP password

1 Like

Sorry Marty, I’m still having some problems.
I don’t even know how to start to explain. I wish I knew more about docker.
Also, by chance, does it have to be MQTT_DOMAIN instead of MQTT_ADDRESS? My logs keep asking for that instead.

Values with {ABCD} are variables to be replaced.

Here’s an actual example using my values with usernames and passwords masked

python /opt/sip2mqtt/sip2mqtt.py -t16491 -am13.cloudmqtt.com -u******* -p****** -dtoronto3.voip.ms -n******* -s******* -vvvv

Do you have an MQTT service you can use? I use cloudmqtt.com

I think I’m getting closer.

I entered my credentials in Post Arguments and ended up with this in the logs:

Traceback (most recent call last):
File "/opt/sip2mqtt/sip2mqtt.py", line 209, in <module>
main(sys.argv[1:])
File "/opt/sip2mqtt/sip2mqtt.py", line 157, in main
broker.connect(args.mqtt_domain, args.mqtt_port, args.mqtt_keepalive)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 768, in connect
return self.reconnect()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 895, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File "/usr/lib/python2.7/socket.py", line 571, in create_connection
raise err
socket.error: [Errno 111] Connection refused

I am using my local hassio mosquitto broker and entered the ip (-a192.168.85.40).
Funny, I also use toronto3.voip.ms. Love voip.ms.