arnonym / ha-plugins

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

Things I have discovered #40

Closed Dunkelschunkel closed 1 year ago

Dunkelschunkel commented 1 year ago

Hi @arnonym, I just discovered your add-on and I am awestruck at what you have created. I have been using home assistant for a couple of years and have been wondering just as long why there is no better integration with telephony features and SIP. Your add-on fills this gap beautifully and I am still at the beginning of discovering all the features the add-on has to offer. That said, there are just some minor things to which you might have some insights.

Submenu Is it possible to return to a previous menu or submenu to the parent menu? "post_action" only returns me back to the menu on the same level. Maybe I missed something in the documentation and the issues, once I went down a menu branch it is not possible to go the other way.

timeout Timeouts only work in the root menu, the first level of the menu. Default option works just fine.

message and templating In my scenario someone is calling home assistant and ha-sip answers the call. After entering the pin the person can choose from from a couple of options one of which would be the announcing of the state of some entities. When in answering mode and thus using the yaml-file templating seems not possible. Only the "service: hassio.addon_stdin" call would be able to do just that and therefor be able to announce the current state of en entity. I guess using an automation and a webhook i could end the call, call back after a short delay and then announce the information I wanted to retrieve. The only thing holding me back are the rates of calling from landline (home assistant) to mobile ;-)

My yaml for incoming calls looks something like shown below. I could not switch from owner-1 to owner or even to the main menu. The templatings attempts are also visible in the menu "mieter" The timeout only works in main menu.

menu:
    message: Bitte Pin eingeben
    choices_are_pin: true
    timeout: 10
    choices:
        '9876:
          id: mieter
          message: Hallo Paul. Der "{{ states('input_boolean.heizbetrieb_gastezimmer') }}"" ist ! Mit 1 umschalten.
          post_action: hangup
        '12345678:
            id: owner
            message: Hallo Johannes. Wähle 1 für Vorsaal Oben oder 2 für Flur Mitte. Mit Raute beenden.
            post_action: noop
            choices:
                '1':
                    id: owner-1
                    message: Vorsaal Oben geschalten.
                    post_action: return
                '2':
                    id: owner-2
                    message: Flur Mitte geschalten.
                    post_action: return

A service call to a number to announce a state of an entity would look like this

service: hassio.addon_stdin
data:
    addon: c7744bff_ha-sip
    input:
        command: dial
        number: sip:**610@192.168.179.2
        webhook_to_call_after_call_was_established: another_webhook_id # web-hook id which you can listen on in your actions (deprecated)
        webhook_to_call: # web-hook IDs which you can listen on in your actions (additional to the global web-hook)
            call_established: another_webhook_id # can be all the same, or different
            entered_menu: another_webhook_id
            dtmf_digit: another_webhook_id
            call_disconnected: another_webhook_id
        ring_timeout: 15 # time to ring in seconds (optional, defaults to 300)
        sip_account: 1 # number of configured sip account: 1 or 2 
                       # (optional, defaults to first enabled sip account)
        menu:
            message: "{{ state_attr('input_boolean.heizbetrieb_gastezimmer', 'friendly_name') }}  ist {{ states('input_boolean.heizbetrieb_gastezimmer') }}"

I am looking forward to your response

Dunkelschunkel

arnonym commented 1 year ago

Hi Dunkelschunkel,

thanks for your kind words about the add-on!

submenu

Actually return should go from owner-1 to owner and I'm using the same functionality in my setup. Going back 2 levels is currently not possible but implementing a post_action: return 2 should be kinda easy. One could also implement a post_action: jump <menu-id> to be even more flexible. But I still wonder why going back 1 level does not work for you. Can you check the logs if there is anything suspicious? Setting the log level to 2 in the config helps to remove the pjsip noise from the logs.

timeout

The timeout from the root menu is not inherited by its children. You need to specify that in every menu. If that is what you did, than it's a bug. From the examples you posted it does not seem like you did, so please clarify :-).

templating in incoming calls

You're are totally right that it's not possible to use templating from the incoming_call_file config options. But there is another way to accomplish that. First you need to specify answer_mode: listen on your SIP account and then listen for the web-hook message for an incoming call and use the following action where you can specify your menu including templating:

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:
          message: Bye
          post_action: hangup

If you need to answer only specific numbers you can use home-assistant functionality to filter them and also include the number from the web-hook in the action shown above. You can also use this to have different menu definitions based on the number, so it's overall much more flexible but a bit more configuration done on the home-assistant side.

Hope I could shed some light on this, if you experience difficulties don't hesitate to post some more.

Dunkelschunkel commented 1 year ago

Hi @arnonym ,

your message has been received. As soon as I'll have some free time I will test your suggestions regarding the post_action: return. I also like the approach of listening for a call and answering it via an automation. This eliminates the templating issues. Thanks a lot.

Dunkelschunkel commented 1 year ago

Hi @arnonym,

I've had some time to dabble around some more and I've observed some behavior. But this has not been tested vigorously as I prefer.

submenu

You are right. The example given works. I return from owner-1 to owner. But adding a submenu media as child of the owner menu in which I am able to control for example media (2 - Volume up, 8 - Volume down etc.) and that I can leave at my choosing is not possible. This would require the mentioned post_action: jump <menu-id>

timeout

Defining timeout in a submenu does work. I messed up my .yaml and it didn't work. Using a simple test menu I could verify it is working. That said leaving a submenu and entering its parent menu the webhook with the correct menu-id gets called but the timeout for that menu does not restart. I believe the timeout is canceled once there is an action registered for that menu and it is not started again when leaving a childmenu and upon entering it's parent

templating in incoming calls

No troubles here. Defining allowed callers and using templating to answer each one with it's own menu with one automation covering them alll could be acomplished. Thanks for the kickstart.

cheers Dunkelschunkel

arnonym commented 1 year ago

Hey @Dunkelschunkel,

I will implement that menu jumping and going back more than one level, but I cannot say when I've time for that now, so you need a bit of patience.

The time-out is reset on:

What happens in your case?

Regards, Arne

arnonym commented 1 year ago

Hey @Dunkelschunkel, good news!

I just released a new version with better return and jump post actions. Also included is a fix to reset the time-out when returning to a menu. Please test and close the issue when everything is working as expected or comment if not.

Arne

Dunkelschunkel commented 1 year ago

Hey @arnonym, Thanks for all the effort. I will gladly test everything. Just some time needed.

Dunkelschunkel

Apr 13, 2023 11:15:24 AM Arne Gellhaus @.***>:

Hey @Dunkelschunkel[https://github.com/Dunkelschunkel], good news!

I just released a new version with better return and jump post actions. Also included is a fix to reset the time-out when returning to a menu. Please test and close the issue when everything is working as expected or comment if not.

Arne

— Reply to this email directly, view it on GitHub[https://github.com/arnonym/ha-plugins/issues/40#issuecomment-1506627074], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AT5ZC5ML2655U7R65PRARTTXA672XANCNFSM6AAAAAAWMDVSRI]. You are receiving this because you were mentioned.[Tracking image][https://github.com/notifications/beacon/AT5ZC5KS2ZDS6G2MHDILYFTXA672XA5CNFSM6AAAAAAWMDVSRKWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSZZVHAE.gif]

arnonym commented 1 year ago

Please reopen when you experience any problems.