I’m trying to use ha-sip.answer in my automation, which registers ongoing calls as ‘+316<SomePhoneNumber>’. However, if I read in the calling number from the webhook to a variable, it seems to be converted to a number automatically, making it so the call is no longer found since the ‘+’ is removed.
Note that the first try (‘caller_number’) comes very close but due to the zero-width whitespace it is still not matched to the right string (this solution came from someone having the same issue here).
Is there no way to create a numbers string starting with a ‘+’ character?
Some more info
Note that parsed_caller and internal_id in the webhook of HA-SIP contains the exact string I need:
21:17:44.239165 [ ] Got "answer" command for 31612345678
| 21:17:44.239497 [ ] Warning: call not in progress: 31612345678
| 21:17:44.239528 [ ] Currently registered calls:
| 21:17:44.239561 [ ] +31612345678
When I put those same values inside of a variable, the ‘+’ seems to always be lost (just like mentioned above), making me believe that this is an ‘issue’ with home-assistant and not an issue with the HA-SIP addon.
Hi Dominic! Thanks for your quick response. I can probably parse out the ‘+’ in my sip server (running under asterisk) before passing it on but I would prefer to keep the number as is to also keep it compatible with calling back etc. etc. It works fine if the number does not have a ‘+’ (e.g. non-external calls).
Unfortunately I need to pass the number I want to “pick up” to HA-SIP. The matching of the passed number to the call that needs to be picked up is done internally and I can’t do it myself.
Unfortunately this doesn’t work either. I think HA-SIP just matches to the the string starting with “+”. I also tried creating a text-input but this doesn’t seem to work either…
I think this is being done by Home Assistant, not by Jinja. It looks like Home Assistant is automatically converting a string it gets from a Jinja {{ }} print statement into a number if the string “looks” like a number. I can’t find a way to suppress this.
It’s possible someone else will be able to figure out a trick for this.
Some other ideas in the meanwhile:
Any chance that SIP tolerates some whitespace, for example, between digits?
Can you configure SIP to drop the country code, or ideally to drop the +?
(I don’t know how much poking around you already did, so sorry if these seem obvious and you’ve already tried).
Assuming this is a limitation of HA, you might be stuck with either sending only an integer or only something that HA concludes is not an integer.
The suggestion provided by @zodyking should indeed work.
The problem you’re facing is that normally a jinja template will always result in a string. To make the results more usable, the template parser of Home Assistant converts the result of a template to a native type (so e.g. an integer, floating point number, list, etc).
The side effect of this is that everything which resembles a number, will be converted to a number, but the formatting of that number gets lost. So a + at the start of the number, but also trailing zeros in a value like 12.30 (for example if you want it to be a monetary value)
To avoid this, you can make the value part of a more complex type, like a list or a mapping, and that’s exactly what @zodyking does above.
Although it seems to be a bit complex, this should also work, as the source will be a string including the +:
And of course, one cannot make an exception for +, since mathematically it must be permissible to start a number with that (and hence also - for negative numbers).
Off-topic: I wonder why + was used for the international MSISDN format. Seems like a particularly bad choice when it comes to computers.
The result of the template is parsed, and the result is always a string. There is no context anymore at that point if it is a string because a string filter was used, or because a result of template is simply always a string.