arnonym / ha-plugins

Home-Assistant SIP Gateway
Apache License 2.0
170 stars 22 forks source link

Pick up #12

Closed timostr closed 1 year ago

timostr commented 2 years ago

My doorbell rings until someone answers the call by phone. Could you add "Pick up Phone / answer phone" functionality and then of course hang up?

arnonym commented 2 years ago

This is already implemented and currently in beta phase. You can take a look at the docs at https://github.com/arnonym/ha-plugins-next and figure out if that suits your use-case. This will hopefully soon be merged into the official version.

timostr commented 2 years ago

Very nice, I will test it tomorrow. Thank you! So it is possible that I use some sensor to trigger the pickup. I.e. someone open the door, this is notified by some sensor and this could trigger the pickup.

Arne Gellhaus @.***> schrieb am Do., 1. Sept. 2022, 17:07:

This is already implemented and currently in beta phase. You can take a look at the docs at https://github.com/arnonym/ha-plugins-next and figure out if that suits your use-case. This will hopefully soon be merged into the official version.

— Reply to this email directly, view it on GitHub https://github.com/arnonym/ha-plugins/issues/12#issuecomment-1234412228, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYXYOXT44AEDRXE7FIWIELV4DBCTANCNFSM6AAAAAAQCOGWVM . You are receiving this because you authored the thread.Message ID: @.***>

timostr commented 2 years ago

I hope I don't stress you.

If I read your code correctly, then the configuration file defines, whether a call is picked up or not. Unfortunately this is not what I need. I need to be able to decide to pick up only, if some conditions are meet. Other users might want to pick up only at specific times. Your solution would cause immediate ringing stop.

Scenario:

  1. Someone presses the ring button at my door DECT phone
  2. All configured phones at the Fritzbox are ringing (including the SIP-Client at the home assistant)
  3. Someone opens the door. This triggers a sensor (Homematic IP/HomeAssistent) to indicate "door was opened"
  4. SW in HomeAssistent (hopefully your code) picks up the ringing phone and hangs up after a brief moment
  5. Ringing had stopped

In short:

  1. Press a button to pickup phone (send command "answer with status 200" to pjsua
  2. Wait 1 Second
  3. Send command "hangup"

Timo Ströhlein @.***> schrieb am Do., 1. Sept. 2022, 19:59:

Very nice, I will test it tomorrow. Thank you! So it is possible that I use some sensor to trigger the pickup. I.e. someone open the door, this is notified by some sensor and this could trigger the pickup.

Arne Gellhaus @.***> schrieb am Do., 1. Sept. 2022, 17:07:

This is already implemented and currently in beta phase. You can take a look at the docs at https://github.com/arnonym/ha-plugins-next and figure out if that suits your use-case. This will hopefully soon be merged into the official version.

— Reply to this email directly, view it on GitHub https://github.com/arnonym/ha-plugins/issues/12#issuecomment-1234412228, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYXYOXT44AEDRXE7FIWIELV4DBCTANCNFSM6AAAAAAQCOGWVM . You are receiving this because you authored the thread.Message ID: @.***>

arnonym commented 2 years ago

You're totally right, That's not something that's currently working, but I think there is only a small bit missing and I like the idea.

Which architecture are you running HA on? Because I don't prepare the docker images for all architectures on the "next" repo.

And when testing against the "next" repo, you need to use "8cd50eef_ha-sip-next" as the add-on name in your stdin actions, if you have not done that already.

timostr commented 2 years ago

Fantastic! I think as well, that it requires "mostly" adding a third command to "dial, hangup" with name answer or pickup.

HA is running at Raspberry PI 4!

I'm happy to test that function. :-)

arnonym commented 2 years ago

Was a bit more involved: https://github.com/arnonym/ha-plugins/commit/81d0ea045ff3654546a9bcbc9549a5dc95c2c2cd

I'll ping here when the images are built, otherwise you can get an old image when installing now.

arnonym commented 2 years ago

Happy testing :-)

arnonym commented 2 years ago

Can you try with "answer" command, please?

timostr commented 2 years ago

Hi, success - thank you fantastic!

Here the log file: Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS Contact: sip:homeassistant@192.168.188.100:5060;ob;+sip.ice Supported: replaces, 100rel, timer, norefersub Session-Expires: 600;refresher=uac Require: timer Content-Type: application/sdp Content-Length: 325

v=0 o=- 3871119042 3871119043 IN IP4 192.168.188.100 s=pjmedia b=AS:84 t=0 0 a=X-nat:0 m=audio 4036 RTP/AVP 9 101 c=IN IP4 192.168.188.100 b=TIAS:64000 a=rtcp:4006 IN IP4 192.168.188.100 a=sendrecv a=rtpmap:9 G722/8000 a=ssrc:1831611325 cname:2818776249a48107 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-16 --end msg-- | Call connecting... 16:50:50.403 pjsua_core.c .RX 484 bytes Request msg ACK/cseq=32 (rdata0x27c3e6e8) from UDP 192.168.188.1:60828: ACK sip:homeassistant@192.168.188.100:5060;ob SIP/2.0 Via: SIP/2.0/UDP 192.168.188.1:5060;branch=z9hG4bK88CA6E0C8445D8F2 From: "Timo" sip:**610@fritz.box;tag=99E15AD6BEE6A304 To: sip:homeassistant@192.168.188.100;ob;tag=L-zcs8hZZRoygcGMaSbbhW2O8hvOB95o;+sip.ice Call-ID: 47DF22C5BF5C8615@192.168.188.1 CSeq: 32 ACK Contact: sip:E9B37508FF40CC36C87507B3CD367@192.168.188.1 Max-Forwards: 70 User-Agent: AVM FRITZ!Box 7590 154.07.29 TAL (Oct 26 2021) Content-Length: 0

--end msg-- | Call connected | No action supplied 16:50:50.455 stream.c G722 codec used, remote samples per frame detected = 80 Got "hangup" command for 610 | Hang-up. 16:50:55.425 pjsua_call.c Call 0 hanging up: code=0.. 16:50:55.425 pjsua_media.c .Call 0: deinitializing media.. 16:50:55.426 pjsua_media.c .. [CONFIRMED] To: "Timo" <sip:610@fritz.box>;tag=99E15AD6BEE6A304 Call time: 00h:00m:05s, 1st res in 68 ms, conn in 8073ms

0 audio G722 @16kHz, sendrecv, peer=192.168.188.1:7082

   SRTP status: Not active Crypto-suite: 
   ICE role: Unknown, state: Candidate Gathering, comp_cnt: 2
   RX pt=9, last update:00h:00m:04.810s ago
      total 249pkt 39.9KB (49.8KB +IP hdr) @avg=63.3Kbps/79.1Kbps
      pkt loss=0 (0.0%), discrd=0 (0.0%), dup=0 (0.0%), reord=0 (0.0%)
            (msec)    min     avg     max     last    dev
      loss period:   0.000   0.000   0.000   0.000   0.000
      jitter     :   0.000   0.502   1.125   0.750   0.154
   TX pt=9, ptime=20, last update:never
      total 0pkt 0B (0B +IP hdr) @avg=0bps/0bps
      pkt loss=0 (0.0%), dup=0 (0.0%), reorder=0 (0.0%)
            (msec)    min     avg     max     last    dev 
      loss period:   0.000   0.000   0.000   0.000   0.000
      jitter     :   0.000   0.000   0.000   0.000   0.000
   RTT msec      :   0.000   0.000   0.000   0.000   0.000

16:50:55.427 pjsua_media.c ...Media stream call00:0 is destroyed 16:50:55.428 icetp00 ..Stopping ICE, reason=media stop requested 16:50:55.428 ice_session.c ..ICE session 0x27cac078 destroyed 16:50:55.428 icetp00 ..ICE stream transport 0x27cb7168 destroyed | Call disconnected 16:50:55.430 pjsua_core.c ....TX 401 bytes Request msg BYE/cseq=31917 (tdta0x27cb71e8) to UDP 192.168.188.1:5060: BYE sip:E9B37508FF40CC36C87507B3CD367@192.168.188.1 SIP/2.0 Via: SIP/2.0/UDP 192.168.188.100:17783;rport;branch=z9hG4bKPj53dsLgdVcWs1BI5FsKFIYUxU7ZlhqA.d Max-Forwards: 70 From: sip:homeassistant@192.168.188.100;ob;tag=L-zcs8hZZRoygcGMaSbbhW2O8hvOB95o;+sip.ice To: "Timo" sip:**610@fritz.box;tag=99E15AD6BEE6A304 Call-ID: 47DF22C5BF5C8615@192.168.188.1 CSeq: 31917 BYE Content-Length: 0

--end msg-- 16:50:55.438 pjsua_core.c .RX 736 bytes Response msg 200/BYE/cseq=31917 (rdata0x27c3e6e8) from UDP 192.168.188.1:5060: SIP/2.0 200 OK Via: SIP/2.0/UDP 192.168.188.100:17783;rport=17783;branch=z9hG4bKPj53dsLgdVcWs1BI5FsKFIYUxU7ZlhqA.d From: sip:homeassistant@192.168.188.100;ob;tag=L-zcs8hZZRoygcGMaSbbhW2O8hvOB95o;+sip.ice To: "Timo" sip:**610@fritz.box;tag=99E15AD6BEE6A304 Call-ID: 47DF22C5BF5C8615@192.168.188.1 CSeq: 31917 BYE X-RTP-Stat: CS=79;PS=234;ES=251;OS=19904;SP=0/0;SO=0;QS=-;PR=0;ER=251;OR=0;CR=0;SR=0;QR=-;PL=0,0;BL=0;LS=0;RB=0/0;SB=0/0;EN=G722;DE=;JI=0,6;DL=2,2,3;IP=192.168.188.1:7082,192.168.188.100:4036 X-RTP-Stat-Add: DQ=0;DSS=0;DS=0;PLCS=0;JS=0 X-SIP-Stat: DRT=1;IR=0 User-Agent: AVM FRITZ!Box 7590 154.07.29 TAL (Oct 26 2021) Supported: 100rel,replaces,timer Allow-Events: telephone-event,refer Content-Length: 0

--end msg--

arnonym commented 2 years ago

Nice!

You can also "answer" directly with this command which will do the hangup automatically:

service: hassio.addon_stdin
data_template:
    addon: c7744bff_ha-sip
    input:
        command: answer
        number: 5551234456 # if this is unclear, you can look that up in the logs ("Registering call with id <number>")
        menu:
          post_action: hangup
timostr commented 2 years ago

It gets better and better! Is it also possible to have a list of numbers in the answer? E.g. service: hassio.addon_stdin data_template: addon: c7744bff_ha-sip input: command: answer number:

arnonym commented 2 years ago

No, that's not possible. For that you still need two actions.

timostr commented 2 years ago

Nice!

You can also "answer" directly with this command which will do the hangup automatically:

service: hassio.addon_stdin
data_template:
    addon: c7744bff_ha-sip
    input:
        command: answer
        number: 5551234456 # if this is unclear, you can look that up in the logs ("Registering call with id <number>")
        menu:
          post_action: hangup

Somehow this is not working. Here the log file: `12:17:17.985 pjsua_media.c ..Call 0: initializing media.. 12:17:17.985 icetp00 ...Creating ICE stream transport with 2 component(s) 12:17:17.988 icetp00 ....Comp 1/0: host candidate 192.168.188.100:4026 (tpid=64) added 12:17:17.988 icetp00 ....Comp 1/1: host candidate 172.17.0.1:4026 (tpid=64) added 12:17:17.988 icetp00 ....Comp 1/2: host candidate 172.30.32.1:4026 (tpid=64) added 12:17:17.991 icetp00 ....Comp 2/0: host candidate 192.168.188.100:4008 (tpid=64) added 12:17:17.991 icetp00 ....Comp 2/1: host candidate 172.17.0.1:4008 (tpid=64) added 12:17:17.991 icetp00 ....Comp 2/2: host candidate 172.30.32.1:4008 (tpid=64) added 12:17:17.991 icetp00 ....ICE stream transport 0xf551598 created 12:17:17.991 pjsua_media.c ...Media index 0 selected for audio call 0 12:17:17.992 pjsua_core.c .....TX 313 bytes Response msg 100/INVITE/cseq=44 (tdta0xf506318) to UDP 192.168.188.1:5060: SIP/2.0 100 Trying Via: SIP/2.0/UDP 192.168.188.1:5060;received=192.168.188.1;branch=z9hG4bK9ED773A090FD548B Call-ID: 0A6419DB86869E50@192.168.188.1 From: "Klingel Familie" sip:**6142@fritz.box;tag=95C3260756DFECCC To: sip:homeassistant@192.168.188.100;ob;+sip.ice CSeq: 44 INVITE Content-Length: 0

--end msg-- 12:17:18.000 pjsua_aud.c ..Destroying player 0.. 12:17:18.001 pjsua_call.c ..Call 0 hanging up: code=0.. 12:17:18.001 pjsua_media.c ...Call 0: deinitializing media.. 12:17:18.001 pjsua_media.c .... [INCOMING] To: "Klingel Familie" sip:**6142@fritz.box;tag=95C3260756DFECCC Call time: 00h:00m:00s, 1st res in 18 ms, conn in 0ms 12:17:18.001 pjsua_media.c ....Call 0: cleaning up provisional media, prov_med_cnt=1, med_cnt=0 12:17:18.001 icetp00 ....ICE stream transport 0xf551598 destroyed 12:17:18.001 pjsua_core.c ......TX 351 bytes Response msg 603/INVITE/cseq=44 (tdta0xf527918) to UDP 192.168.188.1:5060: SIP/2.0 603 Decline Via: SIP/2.0/UDP 192.168.188.1:5060;received=192.168.188.1;branch=z9hG4bK9ED773A090FD548B Call-ID: 0A6419DB86869E50@192.168.188.1 From: "Klingel Familie" sip:**6142@fritz.box;tag=95C3260756DFECCC To: sip:homeassistant@192.168.188.100;ob;tag=QO1UMIYOXawvMQIjyKx5LolcKwcaU1Z1;+sip.ice CSeq: 44 INVITE Content-Length: 0

--end msg-- 12:17:18.001 pjsua_aud.c ..Destroying player 1.. 12:17:18.002 pjsua_aud.c ..Destroying player 2.. &id001 id: null message: null language: en action: null choices_are_pin: false choices: {} default_choice: id: null message: Unknown option language: en action: null Traceback (most recent call last): File "/ha-sip/account.py", line 64, in onIncomingCall choices_are_pin: false choices: null default_choice: null timeout_choice: null post_action: return timeout: 300 parent_menu: *id001 timeout_choice: id: null message: null language: en action: null choices_are_pin: false choices: null default_choice: null timeout_choice: null incoming_call = call.Call(self.end_point, self, prm.callId, None, menu, self.callback, self.ha_config, call.DEFAULT_TIMEOUT) File "/ha-sip/call.py", line 99, in init post_action: hangup timeout: 300 parent_menu: *id001 post_action: noop timeout: 300 parent_menu: null

12:17:18.010 call.cpp ..pjsua_call_get_info(id, &pj_ci) error: INVITE session already terminated (PJSIP_ESESSIONTERMINATED) (status=171140) [../src/pjsua2/call.cpp:495] self.callback_id = self.get_callback_id() File "/ha-sip/call.py", line 261, in get_callback_id call_info = self.get_call_info() File "/ha-sip/call.py", line 267, in get_call_info ci = self.getInfo() File "/root/.local/lib/python3.9/site-packages/pjsua2.py", line 6466, in getInfo return _pjsua2.Call_getInfo(self) pjsua2.Error python3: ../src/pjsip/sip_transport.c:842: pjsip_rx_data_free_cloned: Assertion rdata' failed. /run.sh: line 32: 202 Aborted (core dumped) python3 /ha-sip/main.py s6-rc: info: service legacy-services: stopping s6-rc: info: service legacy-services successfully stopped s6-rc: info: service legacy-cont-init: stopping s6-rc: info: service legacy-cont-init successfully stopped s6-rc: info: service fix-attrs: stopping s6-rc: info: service fix-attrs successfully stopped s6-rc: info: service s6rc-oneshot-runner: stopping s6-rc: info: service s6rc-oneshot-runner successfully stopped

arnonym commented 2 years ago

There was also a bug, which prevented the hangup if no message was given. So for now add a message like "Bye" to that menu.

But in your log it looks like the hangup is done twice. Do you have any idea what might have caused this? If you can re-produce this please change the log_level to 2 in your add-on config, so all these full messages from pjsip are not taking all the space. Please also post the actions you have configured in home assistant.

arnonym commented 2 years ago

The bugfix with empty message is now on the latest beta.

arnonym commented 2 years ago

rc1 also fixed some issues with hangup handling. looking forward to your test report!

timostr commented 2 years ago

very nice - I will check and report issues (if there are any).

Am Fr., 9. Sept. 2022 um 17:04 Uhr schrieb Arne Gellhaus < @.***>:

rc1 also fixed some issues with hangup handling. looking forward to your test report!

— Reply to this email directly, view it on GitHub https://github.com/arnonym/ha-plugins/issues/12#issuecomment-1242090029, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYXYOR3KW7HMFDWPLLKKIDV5NGXFANCNFSM6AAAAAAQCOGWVM . You are receiving this because you authored the thread.Message ID: @.***>

timostr commented 2 years ago

I can open my door by phone by calling the door bell and send sending #9. Is this possible?

  1. Call Door-Bell ("'**614")
  2. Wait for Pickup
  3. Send dtmf "#9"
  4. hangup

Q1: Is it possible to put that into one action?

I tried following so far without success:

alias: Öffne Haustür
description: ""
trigger: []
condition: []
action:
  - service: hassio.addon_stdin
    data:
      addon: 8cd50eef_ha-sip-next
      input:
        command: dial
        number: "**614"
  - service: hassio.addon_stdin
    data:
      addon: 8cd50eef_ha-sip-next
      input:
        command: send_dtmf
        number: "**614"
        digits: "#9"
        method: in_band
        menu:
          post_action: hangup
mode: single
arnonym commented 2 years ago

Does this work if you add a waiting period between the dial and the send_dtmf? That might not be the final solution, but I would like to know if the send_dtmf is doing the right thing.

arnonym commented 2 years ago

And I think you need to specify a complete SIP URI for the dial and send_dtmf commands. So use sip:**614@fritz.box for both of them. You can always check the logs of ha-sip to see what's happening.

arnonym commented 2 years ago

And also the post_action with hangup does not work with send_dtmf because there is currently no way of knowing when pjsip is done sending those. Maybe this should be part of the readme. So you need to add an additional wait action and use the hangup command. So many pitfalls!

timostr commented 2 years ago

alias: Öffne Haustür description: "" trigger: [] condition: [] action:

Yes, this way it's working. Again thank you!

Arne Gellhaus @.***> schrieb am Sa., 17. Sept. 2022, 16:33:

And also the post_action with hangup does not work with send_dtmf because there is currently no way of knowing when pjsip is done sending those. Maybe this should be part of the readme. So you need to add an additional wait action and use the hangup command. So many pitfalls!

— Reply to this email directly, view it on GitHub https://github.com/arnonym/ha-plugins/issues/12#issuecomment-1250082071, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYXYOQENIIDKY47GVMB6ETV6XJDXANCNFSM6AAAAAAQCOGWVM . You are receiving this because you authored the thread.Message ID: @.***>

arnonym commented 2 years ago

Good to hear!

I added another option to the dial command to minimize the time to send the DTMF commands. It's called webhook_to_call_after_call_was_established. You can use that webhook id in a "wait for" action like that:

wait_for_trigger:
  - platform: webhook
    webhook_id: totally-secret-webhook-id-but-not-the-one-from-the-config

So you don't need the fixed 5 second wait anymore. The wait after the sending of DTMFs does probably not matter too much, because the thing you wanted to be done is already performed.

I would appreciate if you can test this one also! If this is working can you please post the complete automation YAML (without phone numbers of course, if those are sensitive) because I would like that example in the docs.

timostr commented 2 years ago

One Problem - I don't know (yet) how to use webhooks. I've switched recently to HomeAssistant and don't know yet how to integrate webhook into an automation. Do I have to extend the webhook_id with "webhook_to_call_after_call_was_established". i.e. "very_secret_webhook/webhook_to_call_after_call_was_established"? Showing the numbers is no problem, because those are internal numbers only. Do you have a screenshot or code how to use your latest addition? Sorry - that you need to spoon feed me.

Am So., 18. Sept. 2022 um 08:24 Uhr schrieb Arne Gellhaus < @.***>:

Good to hear!

I added another option to the dial command to minimize the time to send the DTMF commands. It's called webhook_to_call_after_call_was_established. You can use that webhook id in a "wait for" action like that:

wait_for_trigger:

  • platform: webhook webhook_id: totally-secret-webhook-id-but-not-the-one-from-the-config

So you don't need the fixed 5 second wait anymore. The wait after the sending of DTMFs does probably not matter too much, because the thing you wanted to be done is already performed.

I would appreciate if you can test this one also! If this is working can you please post the complete automation YAML (without phone numbers of course, if those are sensitive) because I would like that example in the docs.

PS: the images are currently compiling, so they will be available in about an hour.

— Reply to this email directly, view it on GitHub https://github.com/arnonym/ha-plugins/issues/12#issuecomment-1250202109, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYXYOTMHZ346BDO4G6KOKTV62YTLANCNFSM6AAAAAAQCOGWVM . You are receiving this because you authored the thread.Message ID: @.***>

arnonym commented 2 years ago

It's just a name that needs to be the same on both sides (so in the dial command and also in the wait_for_trigger action. So no slashes or anything like that. The thing is you need to handle it like a password, because if you know the URL of your home-assistant (if exposed to the internet) and the webhook-id someone could potentially open your door. If you create the wait_for_trigger action, home-assistant will create a secret id for you which you can copy to the dial action.

Hope this helps to clarify this.

Edit: Example yaml:

alias: Öffne Haustür
description: ""
trigger: []
condition: []
action:
  - service: hassio.addon_stdin
    data:
      addon: 8cd50eef_ha-sip-next
      input:
        command: dial
        number: sip:**620@fritz.box
        webhook_to_call_after_call_was_established: offne-haustur-YPoP1pHZlgak2lnz5tQuJyHW
  - wait_for_trigger:
      - platform: webhook
        webhook_id: offne-haustur-YPoP1pHZlgak2lnz5tQuJyHW
  - service: hassio.addon_stdin
    data:
      addon: 8cd50eef_ha-sip-next
      input:
        command: send_dtmf
        number: sip:**620@fritz.box
        digits: "#9"
        method: in_band
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: hassio.addon_stdin
    data:
      addon: 8cd50eef_ha-sip-next
      input:
        command: hangup
        number: sip:**620@fritz.box
mode: single
timostr commented 2 years ago

I've tested it with wait_for_trigger. However it's not working. I guess there needs to be a minimum time, between picking up and sending the dtmf.

Here the log:

| 
| Registering call with id sip:**614@fritz.box
| Calling
| Early
| onCallMediaState call info state 3
| Connected media.
| Call connecting...
| onCallMediaState call info state 4
| Connected media.
| Call connected
| Call is established.
| Calling webhook offne-haustur-xxxxxxxxxxxxx with data {'event': 'call_established', 'caller': 'sip:**614@fritz.box', 'parsed_caller': '**614'}
| Webhook response 200 b''
| Calling webhook sip_call_webhook_id with data {'event': 'call_established', 'caller': 'sip:**614@fritz.box', 'parsed_caller': '**614'}
| Webhook response 200 b''
| No action supplied
| Scheduled post action: noop
| Got "send_dtmf" command for sip:**614@fritz.box
| Sending DTMF #9
| onCallMediaState call info state 5
| Connected media.
| Got "hangup" command for sip:**614@fritz.box
| Hang-up.
| Call disconnected
| Calling webhook sip_call_webhook_id with data {'event': 'call_disconnected', 'caller': 'sip:**614@fritz.box', 'parsed_caller': '**614'}
| Webhook response 200 b''
arnonym commented 2 years ago

Can you call a phone instead of the door station and listen to what it is sending?

Edit: I just did that myself and the first tone is barely hearable. So you might need an additional delay of 1 second or so.

Edit2: I added a settle_time option to the SIP accounts which defaults to "1". Please try again with that without adding an addtional delay.

timostr commented 2 years ago

It is working fine with settle_time set to 2 seconds. Very nice one step less in the automation!

arnonym commented 2 years ago

Do all your use-cases work as expected now?

timostr commented 2 years ago

My use-cases:

  1. Stop Door-Phone-Ring: Working fine (Pickup phone then hang-up phone) 👍
  2. Open Door: Working fine (Call Door, wait 2-3 Seconds, send "#9" DTMF, hang-up again) 👍
  3. Log Door-Phone-Ring: I guess it should be possible with your code to log the time, when someone presses the ring button and the home-assistant phone rings. I guess something with webhooks. However I couldn't figure it out yet. :-|
  4. Log Door-Phone-Ring without someone has opened the door: This is a variant of use-case 3 with the addition to use my door-open sensor. I.e. check time of last ring when the door was opened. If last ring is more than 5 Minutes old, then someone rung without opening.
arnonym commented 2 years ago

Maybe this automation example will help you how to configure an automation based on a webhook:

alias: "SIP: Incoming calls"
description: ""
trigger:
  - platform: webhook
    webhook_id: sip_call_webhook_id
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: |
              {{ trigger.json.event == "incoming_call" }}
        sequence:
          - service: notify.telegram_haus_bot
            data:
              message: Call from {{trigger.json.caller}}
    default: []
mode: single
timostr commented 2 years ago

Thanks - I managed a more complex automation: Upon door ring send an actionable notification to three phones at home. If "open door" is pressed on phone, the doors opens.

Here the automation:

alias: Ringindicator and door opener
description: Is executed, if home assistant phone is called
trigger:
  - platform: webhook
    webhook_id: sip_call_webhook_id
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: |
              {{ trigger.json.event == "incoming_call" }}
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: "{{ is_state('person.peter', 'home') }}"
                sequence:
                  - service: notify.mobile_app_phone_peter
                    data:
                      message: Ring ring!
                      data:
                        notification_icon: mdi:lock-open-variant
                        actions:
                          - action: OPEN_DOOR
                            title: Open door
                      title: Door ring
          - choose:
              - conditions:
                  - condition: template
                    value_template: "{{ is_state('person.ida', 'home') }}"
                sequence:
                  - service: notify.mobile_app_phone_ida
                    data:
                      message: Ring ring!
                      data:
                        notification_icon: mdi:lock-open-variant
                        actions:
                          - action: OPEN_DOOR
                            title: Open dooor
                      title: Door ring
          - choose:
              - conditions:
                  - condition: template
                    value_template: "{{ is_state('person.minimum', 'home') }}"
                sequence:
                  - service: notify.mobile_app_phone_minimum
                    data:
                      message: Ring ring!
                      data:
                        notification_icon: mdi:lock-open-variant
                        actions:
                          - action: OPEN_DOOR
                            title: Open dooor
                      title: Door ring
          - wait_for_trigger:
              - platform: event
                event_type: mobile_app_notification_action
                event_data:
                  action: OPEN_DOOR
                context: {}
            timeout:
              hours: 0
              minutes: 1
              seconds: 0
              milliseconds: 0
            continue_on_timeout: false
          - service: hassio.addon_stdin
            data:
              addon: 8cd50eef_ha-sip-next
              input:
                command: answer
                number: "{{ caller }}"
            enabled: true
          - delay:
              hours: 0
              minutes: 0
              seconds: 5
              milliseconds: 0
            enabled: true
          - service: hassio.addon_stdin
            data:
              addon: 8cd50eef_ha-sip-next
              input:
                command: send_dtmf
                number: "{{ caller }}"
                digits: "#9"
                method: in_band
            enabled: true
          - delay:
              hours: 0
              minutes: 0
              seconds: 5
              milliseconds: 0
            enabled: true
          - service: hassio.addon_stdin
            data:
              addon: 8cd50eef_ha-sip-next
              input:
                command: hangup
                number: "{{ caller }}"
            enabled: true
    default: []
variables:
  caller: "{{trigger.json.parsed_caller}}"
mode: single
arnonym commented 2 years ago

Really nice idea! Also the check if the receiving person is at home! Any reason you're using the delay instead of the settle_time?

I think I will put together an example page with more complex automations, and I guess that will be part of it. Do you want to get attributed?

timostr commented 2 years ago

I've got the feeling that explicit delay in automation works better. With settle_time it works sometimes and sometimes it doesn't work. I had not yet the time to reproduce it. I don't need to get attributed. :-) Btw. the last automation can be further enhanced with timeout and automatic deletion of notification once door has been opened or picture, if you have a camera at your dooor.

arnonym commented 1 year ago

As this is released now I'll close this ticket. Thanks for the productive discussions!

timostr commented 1 year ago

hi, yup - I noticed as well it runs with message. I changed log level and will test it later. My kids are still sleeping - means ringing the doorbell now will not be appreciated. :-)

Btw. is it "data:" or "data-template" in the automation? service: hassio.addon_stdin data_template: addon: 8cd50eef_ha-sip-next input: command: answer number: "**6142" menu: message: Haustür wird geöffnet! post_action: hangup

Am So., 4. Sept. 2022 um 07:32 Uhr schrieb Arne Gellhaus < @.***>:

There was also a bug, which prevented the hangup if no message was given. So for now add a message like "Bye" to that menu.

But in your log it looks like the hangup is done twice. Do you have any idea what might have caused this? If you can re-produce this please change the log_level to 2 in your add-on config, so all these full messages from pjsip are not taking all the space. Please also post the actions you have configured in home assistant.

— Reply to this email directly, view it on GitHub https://github.com/arnonym/ha-plugins/issues/12#issuecomment-1236263619, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYXYOWL3NRGOSXLHRUYT2LV4QX7FANCNFSM6AAAAAAQCOGWVM . You are receiving this because you authored the thread.Message ID: @.***>

arnonym commented 1 year ago

Whenever you need to use a templating feature you need to use data_template. Otherwise you can just use data.