Home Assistant SIP Gateway

Hi,

is it possible to send the caller number to a script action?

Something like this maybe:

action:
     domain: script
     service: turn_on
     entity_id: script.ha_sip_forward_call
     service_data:
         variables:
             message: "test"
             caller: "{{ caller }}"

Yes, this is available in the webhook callback with {{trigger.json.caller}}. See also GitHub - arnonym/ha-plugins: Home-Assistant SIP Gateway

Thank you for the quick reply.

Yes, that’s available if you trigger an automation with a webhook, but I would like to directly call a script in an action from an incoming call and give the caller number as a variable.

The dirty workaround would be to use a webhook in an automation and call the script from there, but I was hoping to call the script directly from my sip-1-inciming.yaml

I’m afraid it’s not possible to do that in the incoming-yaml file, as this is not parsed by home-assistant. If you don’t want to mix up incoming.yaml and webhooks you can do it like described in Generating dynamic Menus and messages on HA Entity State · Issue #86 · arnonym/ha-plugins · GitHub. That way you also don’t need to access the config directory to change your sip actions, but can do it directly from the home-assistant UI. Personally I don’t feel dirty doing it that way.

And you can even have different menus per caller, as you can use conditions to accept certain calls only.

That’s actually a good idea, but for some reason the jump command isn’t working there. The logs say:

| 20:26:46.660766 [ ] Webhook response 200 b''
| 20:26:46.664727 [1] Scheduled post action: jump
| 20:26:46.664788 [1] Could not find menu id: forward

This is my config, which was working fine in sip-1-incoming.yaml (except for the trigger parts):

service: hassio.addon_stdin
metadata: {}
data:
  addon: c7744bff_ha-sip
  input:
    command: answer
    number: "{{ trigger.json.parsed_caller }}"
    menu:
      message: >-
        Welcome message
      choices:
        "1":
          id: weiterleitung
          message: >-
            Ok, forward to who?
          choices:
            "1":
              id: call_a
              message: Ok, you will be connected to A
              post_action: jump forward
            "2":
              id: call_b
              message: Ok, you will be connected to B
              post_action: jump forward
            "999999999999999":
              id: forward
              message: Ok
              action:
                domain: script
                service: turn_on
                entity_id: script.ha_sip_forward_call
                service_data:
                  variables:
                    caller: "{{ trigger.json.parsed_caller }}"
                    message: Ok

The menu from the file and menu from stdin are handled exactly the same. At the beginning of every call ha-sip logs the parsed menu. Can you check if the choice is correctly parsed in the logs?

@j_d , @ Cao_Hoa , @Joerg

You asked for a stand-alone docker version. Fyi - with todays release it is possible.
You will need an Mqtt Broker like Mosquitto for the communcation. If that is set up - all you need to do is to create your own .env file with your connection details. Then you can do a docker compose up and post your commands as json to hasip/execute! Enjoy! :partying_face:

2 Likes

@Cao_Hoa see above. As a new member I can only mention two people in one post.

Thank you very much, it’s great to see your reply to create a version for using docker. I will use it for whatever purpose I will inform you. have a nice day

Thanks a lot, that’s awesome news!!

Now I have to spent some time to set it up and think of some useful automations :smile:

@arnonym I know I am a little bit late to the party, but I just wanted to say that this add-on is probably the absolute best thing I have ever added to my HA! I have a grandstream UCM IP PBX at home and this really ties everything together really splendidly. I’ve (so far) used the “Announcement Center” in the PBX to upload about 8 .wav files for things like doors being opened, motion detection, etc - and can now trigger them through automations using this add-on. The announcements play in perfect unison across all the IP phones. I’ve only just scratched the surface with what’s possible with this add-on but still wanted to say thanks!

2 Likes

hi, does TTS work for anyone with Piper?

Uhm…what about the error after the 2016.6 update?

Really awesome its working great for me. However I havent been able to get it working with piper TTS - has anyone else managed to do this?

Hi @arnonym , sorry to bother you with this. I’ve finally stumbled across your incredible work and I am a little stuck with a call menu. I’m trying to call into my Home Assistant, but the DTMF tones aren’t working. I have an option to hang-up if no menu option selected, so I know the menu is working. I’m unable to hear the tones when I call the system. I saw a previous post with a similar issue and changing the ‘method’, however this looked like it was for an outbound call. I’m using the HA-SIP service as an operator, that I can call inbound. Hope this makes sense. Thanks again for your amazing work on this.

I got HA-SIP connected to my 3CX portal. Incoming calls trigger the webhook but I would love to see the number on screen. It seems so simple no one mentioned it in the docs :slight_smile:
Even better if I can select the caller ID for two different screens (doorphone and landline)
Any example code available and where to place it?
I left the webhook option in the add-on standard and just trigger on the webhook now.

Can I somehow initiate a call to 2 phones (one internal, and one external) from HA? So make both phones ring, and after they both pick up, they can speak to each other?

Hi @arnonym

I think I manage to connect my doorbell.

  1. Can you confirm please?
11:00:56.039           pjsua_core.c  .PJSUA state changed: NULL --> CREATED
11:00:56.040         sip_endpoint.c  .Module "mod-pjsua-log" registered
11:00:56.040         sip_endpoint.c  .Module "mod-tsx-layer" registered
11:00:56.040         sip_endpoint.c  .Module "mod-stateful-util" registered
11:00:56.040         sip_endpoint.c  .Module "mod-ua" registered
11:00:56.040         sip_endpoint.c  .Module "mod-100rel" registered
11:00:56.040         sip_endpoint.c  .Module "mod-pjsua" registered
11:00:56.040         sip_endpoint.c  .Module "mod-invite" registered
11:00:56.047             alsa_dev.c  ..ALSA driver found 0 devices
11:00:56.047             alsa_dev.c  ..ALSA initialized
11:00:56.047                  pjlib  ..select() I/O Queue created (0x7f99945bba48)
11:00:56.051         sip_endpoint.c  .Module "mod-evsub" registered
11:00:56.051         sip_endpoint.c  .Module "mod-presence" registered
11:00:56.051         sip_endpoint.c  .Module "mod-mwi" registered
11:00:56.051         sip_endpoint.c  .Module "mod-refer" registered
11:00:56.051         sip_endpoint.c  .Module "mod-pjsua-pres" registered
11:00:56.051         sip_endpoint.c  .Module "mod-pjsua-im" registered
11:00:56.051         sip_endpoint.c  .Module "mod-pjsua-options" registered
11:00:56.051           pjsua_core.c  .No SIP worker threads created
11:00:56.051           pjsua_core.c  .pjsua version 2.14.1 for Linux-6.6.54/x86_64 initialized
11:00:56.051           pjsua_core.c  .PJSUA state changed: CREATED --> INIT
| 11:00:56.051589 [ ] Supported audio codecs: speex/16000/1, speex/8000/1, speex/32000/1, iLBC/8000/1, GSM/8000/1, PCMU/8000/1, PCMA/8000/1, G722/16000/1, opus/48000/2, L16/44100/2, L16/44100/1
11:00:56.051            pjsua_aud.c  Setting null sound device..
11:00:56.051            pjsua_aud.c  .Opening null sound device..
11:00:56.052           pjsua_core.c  SIP UDP socket reachable at 192.168.1.15:5060
11:00:56.053      udp0x7f99922cefd0  SIP UDP transport started, published address is 192.168.1.15:5060
11:00:56.053           pjsua_core.c  PJSUA state changed: INIT --> STARTING
11:00:56.053         sip_endpoint.c  .Module "mod-unsolicited-mwi" registered
11:00:56.053           pjsua_core.c  .PJSUA state changed: STARTING --> RUNNING
11:00:56.053            pjsua_acc.c  Adding account: id=sip:[email protected]
11:00:56.053            pjsua_acc.c  .Account sip:[email protected] added with id 0
11:00:56.053            pjsua_acc.c  .Acc 0: setting registration..
11:00:56.053            pjsua_acc.c  ..Contact for acc 0 updated: <sip:[email protected]:5060;ob>;+sip.ice
11:00:56.053           pjsua_core.c  ...TX 521 bytes Request msg REGISTER/cseq=63660 (tdta0x7f99920b34a8) to UDP 47.91.88.33:5060:
REGISTER sip:vdpconnect.com SIP/2.0
Via: SIP/2.0/UDP 192.168.1.15:5060;rport;branch=z9hG4bKPjsMUzRZ2SMs4RuHkKlO6zN2i3DHaRPzOk
Max-Forwards: 70
From: <sip:[email protected]>;tag=beMg-RDsadSdT5nL001ETPIs9N14Qi.F
To: <sip:[email protected]>
Call-ID: QNuGlyuEED2AobJBePD-gvdiMMuj64hJ
CSeq: 63660 REGISTER
Contact: <sip:[email protected]:5060;ob>;+sip.ice
Expires: 300
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length:  0


--end msg--
11:00:56.053            pjsua_acc.c  ..Acc 0: Registration sent
11:00:56.094           pjsua_core.c  .RX 540 bytes Response msg 401/REGISTER/cseq=63660 (rdata0x7f99920ae0d8) from UDP 47.91.88.33:5060:
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.1.15:5060;received=79.131.159.180;rport=57895;branch=z9hG4bKPjsMUzRZ2SMs4RuHkKlO6zN2i3DHaRPzOk
From: <sip:[email protected]>;tag=beMg-RDsadSdT5nL001ETPIs9N14Qi.F
To: <sip:[email protected]>;tag=47f5494f4dd8677feafc1bbd25a7fb92.9417
Call-ID: QNuGlyuEED2AobJBePD-gvdiMMuj64hJ
CSeq: 63660 REGISTER
WWW-Authenticate: Digest realm="vdpconnect.com", nonce="6714b8d60000c9a5760ac251cd8d88d92ec3c52a89659383"
Server: OpenSIPS (2.3.2 (x86_64/linux))
Content-Length: 0


--end msg--
11:00:56.094            pjsua_acc.c  ....IP address change detected for account 0 (192.168.1.15:5060 --> 79.131.159.180:57895). Updating registration (using method 4)
11:00:56.094            pjsua_acc.c  ....Contact for acc 0 updated: <sip:[email protected]:57895;ob>;+sip.ice
11:00:56.094      sip_auth_client.c  ...Digest algorithm is ""
11:00:56.094           pjsua_core.c  ....TX 727 bytes Request msg REGISTER/cseq=63661 (tdta0x7f99920b34a8) to UDP 47.91.88.33:5060:
REGISTER sip:vdpconnect.com SIP/2.0
Via: SIP/2.0/UDP 79.131.159.180:57895;rport;branch=z9hG4bKPjUAmqhflxP7S8PJJIBpA6PgIqPKPZTPPU
Max-Forwards: 70
From: <sip:[email protected]>;tag=beMg-RDsadSdT5nL001ETPIs9N14Qi.F
To: <sip:[email protected]>
Call-ID: QNuGlyuEED2AobJBePD-gvdiMMuj64hJ
CSeq: 63661 REGISTER
Contact: <sip:[email protected]:57895;ob>;+sip.ice
Expires: 300
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Authorization: Digest username="0e001a2fea54", realm="vdpconnect.com", nonce="6714b8d60000c9a5760ac251cd8d88d92ec3c52a89659383", uri="sip:vdpconnect.com", response="9a6c0d12526678fda2b88ce90bb06772"
Content-Length:  0


--end msg--
11:00:56.140           pjsua_core.c  .RX 629 bytes Response msg 200/REGISTER/cseq=63661 (rdata0x7f99920ae038) from UDP 47.91.88.33:5060:
SIP/2.0 200 OK
Via: SIP/2.0/UDP 79.131.159.180:57895;received=79.131.159.180;rport=57895;branch=z9hG4bKPjUAmqhflxP7S8PJJIBpA6PgIqPKPZTPPU
From: <sip:[email protected]>;tag=beMg-RDsadSdT5nL001ETPIs9N14Qi.F
To: <sip:[email protected]>;tag=47f5494f4dd8677feafc1bbd25a7fb92.2207
Call-ID: QNuGlyuEED2AobJBePD-gvdiMMuj64hJ
CSeq: 63661 REGISTER
Contact: <sip:[email protected]:57895;ob>;expires=300;received="sip:79.131.159.180:57895", <sip:[email protected]:49307;transport=udp>;expires=19;received="sip:79.131.159.180:49307"
Server: OpenSIPS (2.3.2 (x86_64/linux))
Content-Length: 0


--end msg--
11:00:56.140            pjsua_acc.c  ....SIP outbound status for acc 0 is not active
11:00:56.140            pjsua_acc.c  ....sip:[email protected]: registration success, status=200 (OK), will re-register in 300 seconds
11:00:56.140            pjsua_acc.c  ....Keep-alive timer started for acc 0, destination:47.91.88.33:5060, interval:13s
| 11:00:56.140991 [1] OnRegState: 200 OK
11:00:57.053            pjsua_aud.c  Closing sound device after idle for 1 second(s)
11:00:57.053            pjsua_aud.c  .Closing null sound device..

with this configuration

sip_global:
  port: 5060
  log_level: 5
  name_server: ""
  cache_dir: /config/audio_cache
sip:
  enabled: true
  registrar_uri: sip:vdpconnect.com
  id_uri: sip: [email protected]
  realm: "*"
  user_name: xxxxxxx
  password: "xxxxxx"
  answer_mode: listen
  settle_time: 1
  incoming_call_file: ""
sip_2:
  enabled: false
  registrar_uri: sip:fritz.box
  id_uri: sip:[email protected]
  realm: "*"
  user_name: anotheruser
  password: secret
  answer_mode: listen
  settle_time: 1
  incoming_call_file: ""
sip_3:
  enabled: false
  registrar_uri: sip:192.168.178.10
  id_uri: ""
  realm: "*"
  user_name: ""
  password: ""
  answer_mode: listen
  settle_time: 1
  incoming_call_file: ""
tts:
  platform: google_translate
  language: en
webhook:
  id: xxxxxx
  1. In the configuration if I try to remove the 2 other sip accounts from your example code i get error
    Is that ok? Do we need the other 2 false sip accounts?
Failed to save add-on configuration, Missing option 'sip_3' in root in ha-sip (c7744bff_ha-sip). Got {'sip_global': {'port': 5060, 'log_level'

for the time being I haven’t add anything else.
I have never user an event or webhook trigger and nothing I have tried until now seems to working. So I am not sure that everything is ok in my setup.

i tried something like this but it didn’t work

- id: SIP Incoming call
  alias: SIP Incoming call
  description: ""
  trigger:
    - platform: webhook
      allowed_methods:
        - POST
      local_only: true
      webhook_id: doorbell_ringing_webhook
  condition: []
  action:
  - action: notify.mobile_app_makis_smartphone
    data:
      message: 'the doorbell is ringing!'
  mode: single

I think this is a problem but I am not sure.

SIP/2.0 401 Unauthorized

Can anyone help please?