arnonym / ha-plugins

Home-Assistant SIP Gateway
Apache License 2.0
157 stars 19 forks source link

Transfer call function #80

Closed TheFes closed 5 months ago

TheFes commented 5 months ago

I have an old anaolog phone connected to a Grandstream, and I want to build a menu so my kids (3 and 5) can call us and the grandparents.

What I think I need to do is build a menu like this:

- id: "1704917611241"
  alias: TEST SIP
  description: ""
  trigger:
    - platform: webhook
      local_only: true
      webhook_id: sip_call_webhook_id
  condition: []
  action:
    - choose:
        - conditions: "{{ trigger.json.parsed_caller == '**621' }}"
          sequence:
            - service: hassio.addon_stdin
              data:
                addon: c7744bff_ha-sip
                input:
                  command: answer
                  number: "**621"
                  menu:
                    message:
                      Hello, dial 1 to call daddy, 2 for mommy
                    timeout: 30
                    choices:
                      "1":
                        id: dad
                        message: Hang up now, the phone will ring when daddy picked up
                        action:
                          domain: script
                          service: turn_on
                          entity_id: script.call_dad
                        post_action: hangup
                      "2":
                        id: mom
                        message: Hang up now, the phone will ring when mommy picked up
                        action:
                          domain: script
                          service: turn_on
                          entity_id: script.call_mom
                        post_action: hangup
  mode: single

Then script.call_dad should have a sequence like this:

service: hassio.addon_stdin
data:
    addon: c7744bff_ha-sip
    input:
        command: dial
        number: sip:+31123456789@192.168.2.100
        ring_timeout: 15 # time to ring in seconds (optional, defaults to 300)
        menu:
            message: Someone is trying to reach you, one moment, the call will be transferred.

The above works, I get called, and when I pick up I get the message.

But then I need to transfer this call from HA (620) to the phone (621) I tried

service: hassio.addon_stdin
data:
    addon: c7744bff_ha-sip
    input:
        command: transfer
        number: sip:**620@192.168.2.100
        transfer_to: sip:**621@192.168.2.100

Any advice how to achieve this? Thanks (also for making this great add-on)

arnonym commented 5 months ago

Hoi Martjin,

can you take a look in the logs to see what is actually happening? Best to do that is with log level 2, so you don't have all the pjsip noise.

TheFes commented 5 months ago

Hoi!

So basically transfer should work? Did I assume correctly the line should be free so I'm able to transfer the call? That's why I ask to hang up and wait until the phone rings in the menu.

what should be used for number: in the transer call action, is that the internal number HA is using, or the external phone number?

arnonym commented 5 months ago

For transfer the line must be free, you could also try bridge_audio, which connects two existing calls by audio.

number is the internal number from ha-sip. If you're using this command with non-existing calls you can see an error in the logs, that's why I asked to look there.

catohagen commented 5 months ago

from my testing, I managed to get transfer call working....I found out

service: hassio.addon_stdin
data:
  addon: c7744bff_ha-sip
  input:
    command: transfer
    number: port_02
    transfer_to: sip:port_01@192.168.1.160:5060
    call_established: sip_call_established

the 'port_02' is the same as you get from {{ trigger.json.parsed_caller }} so you could test if number: **620

maybe will work (or what json.parsed_caller says in your logs)

TheFes commented 5 months ago

sorry, I indeed should have shared the log.

I tried this. In devtools > services I initiated this service call:

service: hassio.addon_stdin
data:
    addon: c7744bff_ha-sip
    input:
        command: dial
        number: sip:+311234567896@192.168.2.100
        ring_timeout: 60 # time to ring in seconds (optional, defaults to 300)
        menu:
            message: Hallo, hallo. Ik ga je zometeen doorverbinden. Wacht maar eventjes. 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0

Then, while my phone was still blabbing out this message (so I assume that would mean the call is ongoing, I tried this:

service: hassio.addon_stdin
data:
    addon: c7744bff_ha-sip
    input:
        command: transfer
        number: sip:**620@192.168.2.100
        transfer_to: sip:**621@192.168.2.100

That gives the following in the log (I tried 3 times, and then disconnected):

09:21:56.226351 [ ] Got "dial" command for sip:+31123456789@192.168.2.100
| &id001
| id: null
| message: Hallo, hallo. Ik ga je zometeen doorverbinden. Wacht maar eventjes. 10 9
|   8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3
|   2 1 0
| audio_file: null
| language: nl-NL
| action: null
| choices_are_pin: false
| choices: {}
| default_choice:
|   id: null
|   message: Unknown option
|   audio_file: null
|   language: en
|   action: null
|   choices_are_pin: false
|   choices: null
|   default_choice: null
|   timeout_choice: null
|   post_action:
|     action: return
|     level: 1
|   timeout: 300.0
|   parent_menu: *id001
| timeout_choice:
|   id: null
|   message: null
|   audio_file: null
|   language: en
|   action: null
|   choices_are_pin: false
|   choices: null
|   default_choice: null
|   timeout_choice: null
|   post_action:
|     action: hangup
|   timeout: 300.0
|   parent_menu: *id001
| timeout: 300.0
| post_action:
|   action: noop
| parent_menu: null
| 
| 09:21:56.246561 [1] Registering call with id sip:+31123456789@192.168.2.100
| 09:21:56.246972 [ ] Add to state: sip:+31123456789@192.168.2.100
| 09:21:56.260977 [1] Calling
| 09:21:56.342698 [1] Early
| 09:21:56.344079 [1] onCallMediaState call info state 3
| 09:21:56.344926 [1] Connected media 1
| 09:22:07.089752 [1] Call connecting...
| 09:22:07.091880 [1] onCallMediaState call info state 4
| 09:22:07.091993 [1] Connected media 1
| 09:22:07.092243 [1] Call connected
| 09:22:07.102799 [1] onCallMediaState call info state 5
| 09:22:07.102896 [1] Connected media 1
| 09:22:08.112505 [1] Call is established.
| 09:22:08.113082 [ ] Calling webhook sip_call_webhook_id with data {'event': 'call_established', 'caller': 'sip:+31123456789@192.168.2.100', 'parsed_caller': '+31123456789', 'sip_account': 1}
| 09:22:08.158056 [ ] Webhook response 200 b''
| 09:22:08.158848 [1] Playing message: Hallo, hallo. Ik ga je zometeen doorverbinden. Wacht maar eventjes. 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0
| 09:22:08.176539 [ ] Getting audio from "http://192.168.2.3:8123/api/tts_proxy/10966fca7eee401adfb0ba41924a3752a0e33fb8_nl-nl_dd0e95eb04_cloud.mp3"
| 09:22:10.373140 [1] No action supplied
| 09:22:14.924732 [ ] Warning: call not in progress: sip:**620@192.168.2.100
| 09:22:23.724715 [ ] Warning: call not in progress: sip:**620@192.168.2.100
| 09:22:33.564538 [ ] Warning: call not in progress: sip:**620@192.168.2.100
| 09:22:37.366394 [1] Call disconnected
| 09:22:37.366707 [ ] Calling webhook sip_call_webhook_id with data {'event': 'call_disconnected', 'caller': 'sip:+31123456789@192.168.2.100', 'parsed_caller': '+31123456789', 'sip_account': 1}
| 09:22:37.380284 [ ] Webhook response 200 b''
| 09:22:37.380644 [ ] Remove from state: sip:+31123456789@192.168.2.100
TheFes commented 5 months ago

@catohagen parsed called is **621 or '+31123456789' I don't see port numbers then. Unless you are referring to a different webhook.

Note that I'm not using phones directly connected to the Fritz!Box. I use a analog phone connected to a Grandstream via the network, and the HA SIP add-on itself.

In the end my goal that I can let the add-on make a connection between the Grandstream and an external number (using a choice menu). Maybe there is another approach here which would work better.

TheFes commented 5 months ago

maybe I should initiate the transfer in the first service call, but I couldn't find how to add actions there.

catohagen commented 5 months ago

'parsed_caller': '+31123456789'

I would try, number : +31123456789

I know I got transfer call working, I have two old analog phones, connected to a Grandstream HT802 (two ports), but I cant remember why, but I ended up using bridge call instead.

I got another HT802 on its way in the mail, so I might need to reconfigure everything again with 4 old phones calling eachother Only thing thats bugging me now, is that if I call a phone, I dont know how to 'cancel' a call. If I call and hang up after 2 rings , the target phone just keeps ringing until timeout..

catohagen commented 5 months ago

for bridge calls, this is working for me (calling from port_02 to port_01) /homeassistant/sip-1-incoming.yaml :

        '3':
            id: call_01
            message: stand by, calling kitchen
            action:
                domain: automation
                service: trigger
                entity_id: automation.webhook_call_port_01
            post_action: noop

then automation.webhook_call_port_01:

addon: c7744bff_ha-sip
input:
  command: dial
  number: sip:port_01@192.168.1.160:5060
  ring_timeout: 15
  sip_account: 1
  webhook_to_call:
    call_established: sip_connect_call_bridge_01
    call_disconnected: sip_call_disconnected

then sip_connect_call_bridge_01 gets run when call_established:

addon: c7744bff_ha-sip
input:
  command: bridge_audio
  number: port_02
  bridge_to: sip:port_01@192.168.1.160:5060
catohagen commented 5 months ago

maybe I should initiate the transfer in the first service call, but I couldn't find how to add actions there.

try with the 'webhook_to_call:' in your dial service call, and add the transfer stuff

  webhook_to_call:
    call_established: 'create_a_webhook_transfer_call'
arnonym commented 5 months ago

When ha-sip throws the | 09:22:14.924732 [ ] Warning: call not in progress: sip:**620@192.168.2.100 error, it means that it could not find the call under the given ID.

You can find out the internal ha-sip ID in the log by searching for Add to state: sip:+31123456789@192.168.2.100. The string after state is the one you need to use for number in commands. The first "add to state" log is unfortunately missing in the posted log.

TheFes commented 5 months ago

I initiated a new call, here is the full log (added some extra lines at the top)

13:07:32.330503 [1] OnRegState: 200 OK
| 13:12:27.343418 [1] OnRegState: 200 OK
| 13:17:22.369197 [1] OnRegState: 200 OK
| 13:22:17.400937 [1] OnRegState: 200 OK
| 13:27:12.415472 [1] OnRegState: 200 OK
| 13:32:07.430417 [1] OnRegState: 200 OK
| 13:37:02.446813 [1] OnRegState: 200 OK
| 13:41:57.466965 [1] OnRegState: 200 OK
| 13:46:52.477881 [1] OnRegState: 200 OK
| 13:51:47.492313 [1] OnRegState: 200 OK
| 13:52:59.639612 [ ] Got "dial" command for sip:+31123456789@192.168.2.100
| &id001
| id: null
| message: Hallo, hallo. Ik ga je zometeen doorverbinden. Wacht maar eventjes. 10 9
|   8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3
|   2 1 0
| audio_file: null
| language: nl-NL
| action: null
| choices_are_pin: false
| choices: {}
| default_choice:
|   id: null
|   message: Unknown option
|   audio_file: null
|   language: en
|   action: null
|   choices_are_pin: false
|   choices: null
|   default_choice: null
|   timeout_choice: null
|   post_action:
|     action: return
|     level: 1
|   timeout: 300.0
|   parent_menu: *id001
| timeout_choice:
|   id: null
|   message: null
|   audio_file: null
|   language: en
|   action: null
|   choices_are_pin: false
|   choices: null
|   default_choice: null
|   timeout_choice: null
|   post_action:
|     action: hangup
|   timeout: 300.0
|   parent_menu: *id001
| timeout: 300.0
| post_action:
|   action: noop
| parent_menu: null
| 
| 13:52:59.662230 [1] Registering call with id sip:+31123456789@192.168.2.100
| 13:52:59.662511 [ ] Add to state: sip:+31123456789@192.168.2.100
| 13:52:59.692217 [1] Calling
| 13:52:59.776537 [1] Early
| 13:52:59.777670 [1] onCallMediaState call info state 3
| 13:52:59.778943 [1] Connected media 1
| 13:53:06.042049 [1] Call connecting...
| 13:53:06.047898 [1] onCallMediaState call info state 4
| 13:53:06.048247 [1] Connected media 1
| 13:53:06.048895 [1] Call connected
| 13:53:06.059899 [1] onCallMediaState call info state 5
| 13:53:06.060154 [1] Connected media 1
| 13:53:07.061410 [1] Call is established.
| 13:53:07.062016 [ ] Calling webhook sip_call_webhook_id with data {'event': 'call_established', 'caller': 'sip:+31123456789@192.168.2.100', 'parsed_caller': '+31123456789', 'sip_account': 1}
| 13:53:07.109787 [ ] Webhook response 200 b''
| 13:53:07.110405 [1] Playing message: Hallo, hallo. Ik ga je zometeen doorverbinden. Wacht maar eventjes. 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0
| 13:53:07.125764 [ ] Getting audio from "http://192.168.2.3:8123/api/tts_proxy/10966fca7eee401adfb0ba41924a3752a0e33fb8_nl-nl_dd0e95eb04_cloud.mp3"
| 13:53:07.665150 [1] No action supplied
| 13:53:10.142194 [1] Call disconnected
| 13:53:10.142328 [ ] Calling webhook sip_call_webhook_id with data {'event': 'call_disconnected', 'caller': 'sip:+31123456789@192.168.2.100', 'parsed_caller': '+31123456789', 'sip_account': 1}
| 13:53:10.154199 [ ] Webhook response 200 b''
| 13:53:10.154777 [ ] Remove from state: sip:+31123456789@192.168.2.100

There doesn't seem to be another Add to state: line

TheFes commented 5 months ago

I just realized (based on the other input) shouldn't this be number: 620 instead of number: sip:**620@192.168.2.100

service: hassio.addon_stdin
data:
    addon: c7744bff_ha-sip
    input:
        command: transfer
        number: sip:**620@192.168.2.100
        transfer_to: sip:**621@192.168.2.100
TheFes commented 5 months ago

for bridge calls, this is working for me (calling from port_02 to port_01) /homeassistant/sip-1-incoming.yaml :

        '3':
            id: call_01
            message: stand by, calling kitchen
            action:
                domain: automation
                service: trigger
                entity_id: automation.webhook_call_port_01
            post_action: noop

then automation.webhook_call_port_01:

addon: c7744bff_ha-sip
input:
  command: dial
  number: sip:port_01@192.168.1.160:5060
  ring_timeout: 15
  sip_account: 1
  webhook_to_call:
    call_established: sip_connect_call_bridge_01
    call_disconnected: sip_call_disconnected

then sip_connect_call_bridge_01 gets run when call_established:

addon: c7744bff_ha-sip
input:
  command: bridge_audio
  number: port_02
  bridge_to: sip:port_01@192.168.1.160:5060

This looks really interesting, but how do I link that last action to the webhook, that's where I'm a bit lost

Oh wait, I create an automation triggered by the webhook :)

TheFes commented 5 months ago

Okay, I'm still trying to figure this out.

My goal

To enable my kids to call parents and grandparents using the old analog rotary dial phone connected to a Grandstream HT801.

My devices currently used for testing

device id
HA SIP add-on **620
Granstream (with analog phone) **621
My mobile phone +316123456789

note: the mobile number is of course not my real number, but I didn't seem very wise to share it publicly on GitHub ;)

What I currently have

Based on my initial setup, and the comments above, I have now created a menu in which I call a script. In the script I initiate the call to my mobile phone, and then after connection is established, I try to bridge audio with the HA SIP add on (which initiated the call) and the Granstream (and therefor the analog phone).

Automation with the menu

automation:
  - id: aef85bb7-d7c6-4727-84b7-c15f222d7f71
    alias: Menu for Grandstream
    trigger:
      - platform: webhook
        local_only: true
        webhook_id: sip_call_webhook_id
    condition: []
    action:
      - choose:
          - conditions: "{{ trigger.json.parsed_caller == '**621' }}"
            sequence:
              - service: hassio.addon_stdin
                data:
                  addon: c7744bff_ha-sip
                  input:
                    command: answer
                    number: "**621"
                    menu:
                      message:
                        Hallo, draai 1 om papa te bellen
                        om te stoppen.
                      timeout: 30
                      choices:
                        "1":
                          id: papa
                          message: Papa wordt gebeld
                          action:
                            domain: script
                            service: turn_on
                            entity_id: script.call_dad
                          post_action: noop
    mode: single

script which is called from the menu

script:
  call_dad:
    alias: Call dad
    mode: restart
    sequence:
      - service: hassio.addon_stdin
        data:
          addon: c7744bff_ha-sip
          input:
            command: dial
            number: sip:+31123456789@192.168.2.100
            ring_timeout: 60
            sip_account: 1
            webhook_to_call:
              call_established: sip_connect_call_bridge_621
              call_disconnected: sip_call_disconnected
      - wait_for_trigger:
          - platform: webhook
            local_only: true
            webhook_id: sip_connect_call_bridge_621
        timeout:
          minutes: 5
      - service: hassio.addon_stdin
        data:
          addon: c7744bff_ha-sip
          input:
            command: bridge_audio
            number: "**620"
            bridge_to: sip:**621@192.168.2.100

What happens during testing

what works

what doesn't work

Log report (level 2)

looks like it's truncated to 100 lines

| 22:28:12.572833 [1] Connected media 1
| 22:28:12.578578 [1] Call connecting...
| 22:28:12.593258 [1] Call connected
| 22:28:13.604314 [1] Call is established.
| 22:28:13.604507 [ ] Calling webhook sip_call_webhook_id with data {'event': 'call_established', 'caller': '"HA SIP" <sip:**621@fritz.box>', 'parsed_caller': '**621', 'sip_account': 1}
| 22:28:13.615879 [ ] Webhook response 200 b''
| 22:28:13.616201 [1] Playing message: Hallo, draai 1 om papa te bellen, 2 om mama te bellen en 3 om te stoppen.
| 22:28:13.639059 [ ] Getting audio from "http://192.168.2.3:8123/api/tts_proxy/0d6c71cb34afc69c8d79b3ab6420a184c9caf762_nl-nl_dd0e95eb04_cloud.mp3"
| 22:28:13.937746 [1] No action supplied
Could not deserialize JSON: "command":"answer","number":"**621","menu":{"message":"Hallo, draai 1 om papa te bellen, 2 om mama te bellen en 3 om te stoppen.","timeout":30,"choices":{"1":{"id":"papa","message":"Papa wordt gebeld","action":{"domain":"script","service":"turn_on","entity_id":"script.call_dad"},"post_action":"noop"}}}}
| 22:28:17.619169 [1] Playback interrupted.
| 22:28:17.619429 [1] Scheduled post action: noop
| 22:28:17.624295 [1] onDtmfDigit: digit 1
| 22:28:17.624406 [ ] Calling webhook sip_call_webhook_id with data {'event': 'dtmf_digit', 'caller': '"HA SIP" <sip:**621@fritz.box>', 'parsed_caller': '**621', 'digit': '1', 'sip_account': 1}
| 22:28:17.632121 [ ] Webhook response 200 b''
| 22:28:17.632292 [1] Current input: 1
| 22:28:17.632333 [ ] Calling webhook sip_call_webhook_id with data {'event': 'entered_menu', 'caller': '"HA SIP" <sip:**621@fritz.box>', 'parsed_caller': '**621', 'menu_id': 'papa', 'sip_account': 1}
| 22:28:17.644434 [ ] Webhook response 200 b''
| 22:28:17.644736 [1] Playing message: Papa wordt gebeld
| 22:28:17.656002 [ ] Getting audio from "http://192.168.2.3:8123/api/tts_proxy/9a1857f9f2a6f548df225dc970b507f01b95382f_nl-nl_dd0e95eb04_cloud.mp3"
| 22:28:17.760298 [ ] Calling home assistant service on domain script service turn_on with entity script.call_dad
| 22:28:17.778029 [ ] Service response 200 b'[{"entity_id":"script.call_dad","state":"on","attributes":{"last_triggered":"2024-01-13T21:28:17.770475+00:00","mode":"restart","current":1,"friendly_name":"Call dad"},"last_changed":"2024-01-13T21:28:17.770602+00:00","last_updated":"2024-01-13T21:28:17.770602+00:00","context":{"id":"01HM2BKF36HZEDHCJ5E17JDWRD","parent_id":null,"user_id":"5cca702da9834cdeacf34de267570551"}}]'
Could not deserialize JSON: "command":"answer","number":"**621","menu":{"message":"Hallo, draai 1 om papa te bellen, 2 om mama te bellen en 3 om te stoppen.","timeout":30,"choices":{"1":{"id":"papa","message":"Papa wordt gebeld","action":{"domain":"script","service":"turn_on","entity_id":"script.call_dad"},"post_action":"noop"}}}}
| 22:28:17.924123 [ ] Got "dial" command for sip:+31123456789@192.168.2.100
| &id001
| id: null
| message: null
| audio_file: null
| language: en
| action: null
| choices_are_pin: false
| choices: {}
| default_choice:
|   id: null
|   message: Unknown option
|   audio_file: null
|   language: en
|   action: null
|   choices_are_pin: false
|   choices: null
|   default_choice: null
|   timeout_choice: null
|   post_action:
|     action: return
|     level: 1
|   timeout: 300.0
|   parent_menu: *id001
| timeout_choice:
|   id: null
|   message: null
|   audio_file: null
|   language: en
|   action: null
|   choices_are_pin: false
|   choices: null
|   default_choice: null
|   timeout_choice: null
|   post_action:
|     action: hangup
|   timeout: 300.0
|   parent_menu: *id001
| post_action:
|   action: noop
| timeout: 300.0
| parent_menu: null
| 
| 22:28:17.926182 [1] Registering call with id sip:+31123456789@192.168.2.100
| 22:28:17.926220 [ ] Add to state: sip:+31123456789@192.168.2.100
| 22:28:17.929656 [1] Calling
| 22:28:17.979517 [1] Early
| 22:28:17.979773 [1] onCallMediaState call info state 3
| 22:28:17.979811 [1] Connected media 1
| 22:28:20.037095 [1] Playback done.
| 22:28:20.040290 [1] Scheduled post action: noop
| 22:28:25.884630 [1] Call connecting...
| 22:28:25.886520 [1] onCallMediaState call info state 4
| 22:28:25.886581 [1] Connected media 1
| 22:28:25.886704 [1] Call connected
| 22:28:25.898348 [1] onCallMediaState call info state 5
| 22:28:25.898452 [1] Connected media 1
| 22:28:26.903964 [1] Call is established.
| 22:28:26.904038 [ ] Calling webhook sip_connect_call_bridge_621 with data {'event': 'call_established', 'caller': 'sip:+31123456789@192.168.2.100', 'parsed_caller': '+31123456789', 'sip_account': 1}
| 22:28:26.910687 [ ] Webhook response 200 b''
| 22:28:26.910822 [ ] Calling webhook sip_call_webhook_id with data {'event': 'call_established', 'caller': 'sip:+31123456789@192.168.2.100', 'parsed_caller': '+31123456789', 'sip_account': 1}
| 22:28:26.922122 [ ] Webhook response 200 b''
| 22:28:26.922231 [1] No action supplied
| 22:28:26.922292 [1] Scheduled post action: noop
| 22:28:26.924052 [ ] Warning: call not in progress: **620
| 22:28:39.456700 [1] Call disconnected
| 22:28:39.456788 [ ] Calling webhook sip_call_disconnected with data {'event': 'call_disconnected', 'caller': 'sip:+31123456789@192.168.2.100', 'parsed_caller': '+31123456789', 'sip_account': 1}
| 22:28:39.464117 [ ] Webhook response 200 b''
| 22:28:39.464264 [ ] Calling webhook sip_call_webhook_id with data {'event': 'call_disconnected', 'caller': 'sip:+31123456789@192.168.2.100', 'parsed_caller': '+31123456789', 'sip_account': 1}
| 22:28:39.471151 [ ] Webhook response 200 b''
| 22:28:39.471295 [ ] Remove from state: sip:+31123456789@192.168.2.100
| 22:28:42.821003 [1] Call disconnected
| 22:28:42.821063 [ ] Calling webhook sip_call_webhook_id with data {'event': 'call_disconnected', 'caller': '"HA SIP" <sip:**621@fritz.box>', 'parsed_caller': '**621', 'sip_account': 1}
| 22:28:42.827213 [ ] Webhook response 200 b''
| 22:28:42.827404 [ ] Remove from state: **621
| 22:28:42.928156 [ ] Got "answer" command for **621
| 22:28:42.928208 [ ] Warning: call not in progress: **621
catohagen commented 5 months ago

Could not deserialize JSON: "command":"answer","number":"**621","menu":{"message":"Hallo, draai 1 om papa te bellen, 2 om mama te bellen en 3 om te stoppen.","timeout":30,"choices":{"1":{"id":"papa","message":"Papa wordt gebeld","action":{"domain":"script","service":"turn_on","entity_id":"script.call_dad"},"post_action":"noop"}}}}

maybe there is something with this...I know I have seen this in my logs, but I dont remember what or if I did something to fix that..

catohagen commented 5 months ago

just wanted to add, right after the brigde is done, I have this

wait_template: >-
  {{ iif(is_state_attr('automation.webhook_call_disconnected', 'current',  1),
  'True', 'False') }}
continue_on_timeout: false

so it waits (loops) here until automation.webhook_call_disconnected is runned, then in automation.webhook_call_disconnected it will hang up

service: hassio.addon_stdin
data_template:
  addon: c7744bff_ha-sip
  input:
    command: hangup
    number: port_01

its a choose: condition, if parsed caller is port_02 (port 2 in the ht802) it will hang up port_01 and vice versa

TheFes commented 5 months ago

okay, that makes sense, but I'm still having issues with acuatlly bridging the call (or transfering it).

catohagen commented 5 months ago

@TheFes ok, I was hoping you got it working soon :) ....but I was thinking, you bridge 620 and that is your ha-sip, have you tried bridging 621 and mobile phone ?

command: bridge_audio number: "**621" bridge_to: sip:+3112346789@192.168.2.100

With my bridging, I only bridge the two phones, and not ha-sip itself

TheFes commented 5 months ago

@catohagen I will give that a try, but I assume the script (in my current setup) initiates a call from HA SIP to my mobile phone (as it runs on HA and I don't mention a device which does the calling) or am I just misunderstanding how this works (note I don't have a clue about telephony).

I'm also not sure what is expect as input for the fields number: and brigde_to_sip: But I have changed it now to test your input, currently not in the livingroom where the phone is located, will give it a try in an hour.

catohagen commented 5 months ago

@TheFes I have no idea how all this works myself, I used a good week, figuring out how to transfer or bridge calls :) We basicly do the same thing with the bridging, I dont understand why it doesnt bridge/transfer for you, its rock solid here

TheFes commented 5 months ago

@catohagen many, many thanks! The bridging works with your suggestion!

catohagen commented 5 months ago

@TheFes Fantastic, thats great :)

arnonym commented 5 months ago

Nice, that you found a solution @TheFes, and thank you very much for your support @catohagen. I'm always amazed what people create with ha-sip. My use-case is so much simpler!

gerard33 commented 5 months ago

just wanted to add, right after the brigde is done, I have this

wait_template: >-
  {{ iif(is_state_attr('automation.webhook_call_disconnected', 'current',  1),
  'True', 'False') }}
continue_on_timeout: false

so it waits (loops) here until automation.webhook_call_disconnected is runned, then in automation.webhook_call_disconnected it will hang up

service: hassio.addon_stdin
data_template:
  addon: c7744bff_ha-sip
  input:
    command: hangup
    number: port_01

its a choose: condition, if parsed caller is port_02 (port 2 in the ht802) it will hang up port_01 and vice versa

I am using the automation and script as discussed here successfully as well.

I also use the automation.webhook_call_disconnected , but I noticed that the 'webhook_call_disconnected is only running when the bridge_to number is ending the call. When the phone which started the call then ends the call that webhook is not run and the call stays open on the bridge_to number (in my case I have tested this with the Fritz fon app on my mobile phone).

The default webhook sip_call_webhook_id is run with 'event': 'call_disconnected' but that is to generic to use in this case. Did you found a solution for this?

catohagen commented 5 months ago

@gerard33

When the phone which started the call then ends the call that webhook is not run and the call stays open on the bridge_to >number (in my case I have tested this with the Fritz fon app on my mobile phone).

The default webhook sip_call_webhook_id is run with 'event': 'call_disconnected' but that is to generic to use in this case. >Did you found a solution for this?

I have atleast that working here (when the phone which started the call then ends the call) I get busy signal on the called/target phone. But I have added a second Grandstream 802 added now, and 4 phones that can call eachother, so my configs are a mess now :) I had to use some helpers to get this working..

GrandStream HT802 no1 : 2 phones, port_01 and port_02 GrandStream HT802 no2 : 2 phones, port_03 and port_04

helpers: input_boolean.sip_port01_active input_boolean.sip_port02_active input_boolean.sip_port03_active input_boolean.sip_port04_active these booleans will be set to 1/True when 'call_established' and when you hang up they will be 0/False

input_text.sip_port01_target_port input_text.sip_port02_target_port input_text.sip_port03_target_port input_text.sip_port04_target_port

I set "input_text.sip_port0x_target_port" with the "target" phone I'm calling so if I call from phone 3 (port_03) to phone 4 (port_04) the input_text.sip_port03_target_port will be set to port_04 so this way I can hang up port_04 when port_03 hangs up, and also if port_04 calls port_02, but if nobody picks up you can hang up on phone 4 and port_02 stops ringing (instead of ringing until timeout timer)

I'm not sure these helpers are the best way of achieving this, as the automations are getting large with lots of conditions, but I think I get it working as a house intercom + extra menus for controlling home assistant stuff......in the end.