Use Fritz!Box for outbound Calls


#1

Hi everyone,

I’m looking for a way to use my Fritz!Box to give me a call on my mobil on events.
With the Twilio call I won’t work because I’m from germany and it could be a bit to much expensive :wink:

Is anybody use a feature I’m aksing for?

Frederik


#2

would be nice, but i guess that a custom component needs to be created for that.
i use call monitor but that only gives the call data and no option to call.

do you know of any automated ways to make a call?
i only know that i can click in the fritz.box in the browser.
i dont know if that is possible from outside the fritzbox programm.

i looked a bit but i only found a commandline call, but you need to pickup a phone for that.


#3

Instead of making this specific to the FritzBox it may be more efficient to have a generic SIP implementation, as requested by myself here: Notifications via SIP + TTS


#4

and how does that work?
can i then use my housetelephone number to call my mobile?
or do you need some other provider?

i cant think of a way to use my home phone without going through my fritzbox.


#5

The FritzBox is a SIP gateway. Have you seen the section “Telefoniegeräte”? There you can add “virtual” telephones which you can use with whatever SIP client you like. And because there are a lot of different SIP enabled devices and services, a SIP component would make HASS compatible to all of them.


#6

no i have not seen anything because i dont know where to look for SIP :wink:
could be helpfull if you post a link in 1 or both topics :wink:


#7

Here you go (FritzBox 7490):


#8

thats a nice picture from fritzbox.

but it doesnt tell me anything about SIP :wink:
do you have a link to a python github that uses sip en what you can use to call through that fritzbox?


#9

What SIP is (in German): https://de.wikipedia.org/wiki/Session_Initiation_Protocol

To summarize:
SIP is a protocol which you can use to make telephone calls via IP connections. VOIP would be the buzzword you might have heard before.
Your FritzBox provides a server to which SIP clients (telephone software) can register, and then make telephone calls. For the FritzBox there is the Fritz FON app that is designed to work great with the specific features the FB has. SIP is standarized though, so you can use any SIP client you like. For android theres Sipdroid and many others. And instead of using the FB you can also register an account at some SIP provides like Sipgate (with a free account you get a “Festnetznummer” and inbound calls are free).
So if you add a virtual telephone on your FB and configure it to react on your primary telephone number and use the same one for outbound calls, plus having a smartphone or pc with a sip client, then you have essentially the same as a real DECT phone which you use usually.

Along with HASS the idea would be to have a notification platform which registers HASS as a SIP client (FB, Sipgate, whatever the user has), and configure a normal telephone number as the recipient of the message. The message in this case should be the result of some kind of TTS processing. Otherwise you would just hear your phone ring and just hear silence when you pick up. But using the FB GUI to initiate a call wouldn’t output any audible information either.

Hope I could clarify SIP now a little bit better. :slight_smile:


#10

yeah thanks.
i googled for “python SIP”

and its on pypi.
so i dont need an component for that i am just going to use that in appdaemon :wink:


#11

Could you please post the link? SIP is not a SIP client. PJSUA is the closest I found to be useful, but it requires the PJSIP library to be installed, which may take some time when building on a raspberry.


#12

yeah, i spoke to fast :wink:
found also pjsua.

so i guess it wont be that simple :wink:

and i think we wont find anyone that will create a SIP python lib, that wont use existing code.


#13

I think using pjsua would be totally fine as long as the instructions are straightforward. :wink:

And something interesting that could be done:


#14

am i correct to assume that the fritzbox is sip server?

in that case this could work:

http://most-voip.readthedocs.io/en/latest/index.html


#15

Yes, the FB is a SIP server. And the library in the link uses pjsip as well. And since pjsua comes together with pjsip, adding another library isn’t really necessary.


#16

Another example of what can be done with SIP: https://github.com/fabianhu/SIP-Pi
If HASS was acting like an answering machine we could trigger automation via DTMF codes. But again, this is using pjsip. Maybe someone should build a deb-package which can easily be installed.


#17

yeah, didnt read everything again before i posted :wink:

but the big difference is that most-voip gives python commands like my_voip.make_call(my_extension)
and pjsua is a complete program that uses commandline.
as far as i can see its also python, so i could use that lib, but i cant find an easy script to make a call.


#18

hmm, most-voip is python 2.7 :frowning:


#19

Hi,

some progress. Pre-homeasisstant I used sipcmd to give me a 30sec call that I wouldn’t pick up. Just the caller id was good enough to know it was e.g. my doorbell. That was a 2015 script - I tried a lot of tools and didn’t get that running in 2018.

I still like the concept - if homeassistant gives me a call I maybe check my email more rapidly (e.g. alarm control). In theory it would also be quite suitable to playout prerecorded wav, however, my current docker container don’t have audio devices.

Calling & hangup works, its pure python - I’ll try to further integrate. I see two options - get the script into the homeassistant container (e.g. by creating a Dockerfile that inherits from homeassistant) - or have a separate docker container, e.g. subscribing to mqtt. The later one might work me around the below script not working with python3 as mentioned in a previous post.

Dockerfile:

FROM debian:latest

#########################
# Basics
#########################
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get install -y mosquitto-clients python python-pip supervisor libsrtp-dev libasound2-dev
RUN  pip install paho-mqtt configparser

#########################
## sipcmd - funktioniert nicht mehr richtig, legt nicht auf - komischer fehler, scheint abzubrechen ohne die verbindungen zu killen
#########################
#RUN cd /tmp ; git clone https://github.com/tmakkonen/sipcmd.git ; cd sipcmd; make;


#########################
# python self compiled
# http://most-voip.readthedocs.io/en/latest/python_docs/tutorial/voip_tutorial_1.html#step-1-initialize-the-library
#########################

RUN mkdir -p /tmp/pjsip ; cd /tmp/pjsip; wget http://www.pjsip.org/release/2.7.2/pjproject-2.7.2.tar.bz2 && \
    tar -jxvf pjproject-2.7.2.tar.bz2

RUN cd /tmp/pjsip/pjproject-2.7.2 && \
    ./configure --enable-shared  && \
    make dep && make && make install && \
    cd pjsip-apps/src/python && python setup.py install

RUN apt-get install -y libpjmedia-codec2

RUN echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/tmp/pjsip/pjproject-2.7.2/third_party/lib/:/tmp/pjsip/pjproject-2.7.2/pjsip/lib" >> /root/.bashrc


CMD tail -f /dev/null

call_and_hangup.py

#! /usr/bin/python
import sys
import pjsua as pj
import threading
import time

def log_cb(level, str, len):
    print str,

class MyAccountCallback(pj.AccountCallback):
    sem = None

    def __init__(self, account):
        pj.AccountCallback.__init__(self, account)

    def wait(self):
        self.sem = threading.Semaphore(0)
        self.sem.acquire()

    def on_reg_state(self):
        if self.sem:
            if self.account.info().reg_status >= 200:
                self.sem.release()

# Callback to receive events from Call
class MyCallCallback(pj.CallCallback):
    def __init__(self, call=None):
        pj.CallCallback.__init__(self, call)

    # Notification when call state has changed
    def on_state(self):
        print "Call is ", self.call.info().state_text,
        print "last code =", self.call.info().last_code,
        print "(" + self.call.info().last_reason + ")"

    # Notification when call's media state has changed.
    def on_media_state(self):
        global lib
        if self.call.info().media_state == pj.MediaState.ACTIVE:
            # Connect the call to sound device
            call_slot = self.call.info().conf_slot
            lib.conf_connect(call_slot, 0)
            lib.conf_connect(0, call_slot)
            print "Hello world, I can talk!"

lib = pj.Lib()

try:
    lib.init(log_cfg = pj.LogConfig(level=1, callback=log_cb))
    lib.set_null_snd_dev()

    lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(5080))
    lib.start()

    acc = lib.create_account(pj.AccountConfig("sipgate.de", "username", "password"))

    acc_cb = MyAccountCallback(acc)
    acc.set_callback(acc_cb)
    acc_cb.wait()

    # Make call
    call = acc.make_call("sip:[email protected]", MyCallCallback())

    # Wait 20 seconds and hangup
    time.sleep(20)

    lib.destroy()
    lib = None

except pj.Error, e:
    print "Exception: " + str(e)
    lib.destroy()

#20

That would make your solution alow more versatile. Everybody capable of running Docker could use this without being bound to a special way to run Home Assistant.