Is endpoint xxx.xxx.xxx.xxx a phone or a switch? If the latter, it will show as inuse whenever anyone is using that switch.
I don’t believe there is any need to redirect through a local channel here, but if there is, there is an extra parameter in the member definition which gives the underlying channel from which to determine the device state.
The only way of determining the status of an arbitrary PSTN number is to actually ring it.
In the example above, xxx.xxx.xxx.xxx is the IP address is the SIP gateway for making external calls. Here, the requirement is only to be able to manage the callback of an agent in a queue via their mobile phone and not a local softphone. Everything works fine with a softphone, and the agent’s status is well detected by the ACD but not with a remote mobile phone PSTN. In this case, the local channel was the only solution I found to allow the queue member to use an external phone.
If there is any call in progress using the gateway, it will be considered in use. The dialled digits will not limit the the inuse status to just that dialled number, and there is absolutely no way of detecting a conflicting call that doesn’t go through Asterisk.
I say endpoint, because chan_pjsip doesn’t allow a literal IP address without an endpoint.
In terms of outgoing calls from Asterisk, you may be able to use a local channel and define a custom hint, which you use in a status interface, and manipulate with dialplan code, although you would have to be careful to reset it when the call ends.