Home Assistant SIP Gateway

listen is the correct mode for this. In this mode the only thing which will be done for every incoming call is the notification through a webhook (but you can also just ignore that).

1 Like

Thank you very much for the great addon!
Currently I was able to configure it so that when there is an incoming call from the doorphone, then the webhook triggers an automation, where I get a pop-up of the camera of the doorphone with browser_mod.
Would it be possible to answer the call on demand (e.g. by pressing a key in the pop-up card) and speak through Home Asssistant with the person at the door?
The ideal scenario would be to have 3 buttons on the pop-up, one to answer the call, one to disconnect the call and one to open the door. More or less, you can have these in automations configuration, but what about the voice over the browser?

1 Like

Currently I don’t see a way with ha-sip to do this. But there is also GitHub - TECH7Fox/sip-hass-card: A SIP client inside home assistant! which implements a sip client on the front-end side of home assistant. Maybe you can use this one (I’m not exactly sure what the scope of this add-on is). Please report if you were successful!

This add-on is for Asterisk only, but maybe I can also install the Asterisk add-on and connect via SIP trunk to my PBX. I will test and see!
Thanks a lot

Are you sure on that only working with asterisk? If I understood the docs correctly you can specfiy any sip server.

That’s what is mentioned also here, because in browsers you can only work with wss. If other PBXes support wss, then I guess it would work too.

Did not think about that a browser only can do websocket connections to talk to a SIP server. I think you could terminate the websocket connection with something like GitHub - novnc/websockify: Websockify is a WebSocket to TCP proxy/bridge. This allows a browser to connect to any application/server/service.?

Unfortunately, too much for my level of knowledge and understanding!
I consider myself good at SIP, but this goes far beyond my level!

Hello, I implemented the SIP Gateway addon and are able to connect to a SIP-Account on my FritzBox to make calls.
But sending DTMF is not working :frowning:
There are no errors in the LOG, but there are no tones hearable.

| Got “send_dtmf” command for sip:**[email protected]
| Sending DTMF 123#
14:05:49.386 pjsua_aud.c !Conf connect: 3 → 1
14:05:49.386 conference.c .Port 3 (tonegen) transmitting to port 1 (sip:**[email protected])
| Got “hangup” command for sip:**[email protected]
| Hang-up.
14:06:04.886 pjsua_call.c !Call 1 hanging up: code=0…
14:06:04.886 pjsua_media.c .Call 1: deinitializing media…
14:06:04.886 pjsua_media.c …
[CONFIRMED] To: sip:**[email protected];tag=8C3A5A87806EDEA2
Call time: 00h:00m:26s, 1st res in 84 ms, conn in 2511ms

My goal is to connect to my door-station (already working) and send the needed DMTF (#) to open the door. For my tests, I created 3 separate Scripts for Connecting, SendingDMTF and Disconnecting, and instead of the Doorstation I use my FritzFon to check the correct function.

Is there something needed that I am not aware of or something else I can try?

Kindest regards,
Christian…

Hi Christian,

I have two ideas what possible could go wrong.

  1. You might hang-up too early, so ha-sip does not have a chance to transmit the actual tones. So depending on your automation you need to add a delay.

  2. The door station handles a different format of the DTMF tones. There are (at least) 3 ways to handle them through SIP, and you can set the method to “in_band” (default), “rfc2833” or “sip_info” (check the docs for details).

Hope this will help!

1 Like

Hi Arne,
I could opt out 1. because I have several Scripts for dialing, sending the DTMF and hangup.
So after I have a connection, I am able to try multiple DTMF-Versions before I finish testing by using the hangup-script.
I wanted to reply, that I have already tried out all 3 DTMF-Formats, but then I was not sure I really tried all. So I repeated my test with all 3 DTMF-Formats and “sip_info” got me the result I expected.

Looks like I missed that one in all of my test I´ve done before :crazy_face:

Thank you very much for your great addon. I takes me one step closer to my perfect smarthome :+1:

Kindest regards,
Christian…

PS: One thing to add: I had to send # for opening my door, but that did not work by default, because without " it is interpreted as a comment. So I had to use digit: “#” instead of only digit: #
But that is a general yaml-script “issue” :wink:

You’re welcome! Nice that you sorted that out!

I also added a note to the docs regarding the # sign, so other people can learn from your mistakes :slight_smile:. Thanks for the feed-back!

1 Like

Thank you for your project!!
I was able to setup your integration e configure with an extension on my Yeastar PBX. If I try to call the extension it ring.
Now I would like to create an automation, that if someone call the extension I can toggle a switch.
How can I do that?

Thank you for your support and patience!

Hi Marco,

to create an automation which toggles a switch when someone is calling a configured extension you can use the following yaml (create new automation, click the tripple dot menu on the right top, click on “Edit in YAML”, paste the code below):

alias: "Toggle switch on phone call"
description: ""
trigger:
  - platform: webhook
    webhook_id: sip_call_webhook_id # same as in ha-sip config
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: |
              {{ trigger.json.event == "incoming_call" }}
        sequence:
          - service: switch.toggle
            data: {}
            target:
              entity_id: switch.switch_entity_name
    default: []
mode: single

If this is not what you had in mind, don’t hesitate to ask again!

Great! It works well!

Is it possible to add a filter thath only few number can have the access of thath automation.
I have try to add a debugger on the code, and when try to take a call this is the output:

‘JSON: {“caller”: ““Pareschi Marco” \u003csip:[email protected]\u003e”, “event”: “incoming_call”, “parsed_caller”: “522”}’

I see that webhook call name of the caller and the “parsed_caller” that was my extension? How can filter the incoming extansion?

Sorry, but I’m not very confortable with code :slight_smile:

Thank you for you patience and kindless !!

If I understood correctly, you only want to toggle the switch if a specific extension is calling?

You can add a second condition which is checking for the parsed_caller content:

alias: "SIP: Incoming calls"
description: ""
trigger:
  - platform: webhook
    webhook_id: sip_call_webhook_id
condition: []
action:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: template
                value_template: |
                  "{{ trigger.json.event == "incoming_call" }}"
              - condition: template
                value_template: |
                  "{{ trigger.json.parsed_caller == "522" }}"
        sequence:
          - service: switch.toggle
            data: {}
            target:
              entity_id: switch.switch_entity_name
    default: []
mode: single
1 Like

Perfect! Works like a charm!
Thank you very much for your collaboration and support!!

1 Like

@arnonym
Hi Arne.
I’ve just installed your great addon. Is there a way to hang up an incoming call without answering it? I tried several options with command/hangup but without success.

Hi Gerwazy,

yes, that should work. I do it like this:

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

As the number you need to specify the same string you used for the dial command. If this is not working please set the log level in the add-ons configuration to 2 and post the log here where you tried to hang-up the call.

1 Like

I did in the same way. The trick was to wait 5 seconds after trigger :slight_smile:

      - delay:
          hours: 0
          minutes: 0
          seconds: 5
          milliseconds: 0
      - service: hassio.addon_stdin
        data:
          addon: c7744bff_ha-sip
          input:
            command: hangup
            number: "{{ trigger.json.parsed_caller }}"
1 Like