How to set up a second service as fail over?

I have two sip service providers. I usually use make calls use the first one (72202). I want to use localphone as back up in case the registration to first one fails. The two statements I used are given below:

exten => _1NXXNXXXXXX,1,Dial(SIP/${EXTEN}@72202,20,tr)
same => n,Dial(SIP/${EXTEN}@localphone,30,tr)

In case the registration to 72202 fails, local phone will take over after 20 seconds (time out). My question is: is there any way that Asterisk would detect the registration to 72202 is not available so it will failover immediately? Thanks.

If the first phone is unregistered, and dynamic, it will fall through immediately. For static addresses, you can use qualify to detect the loss.

Thanks for your reply. But I was not talking about a phone registered to my asterisk. My asterisk is registered to another server 72202. If the second server is offline, I don’t know how my asterisk can detect this and make call through Localphone immediately. Is it possible to qualify a registration to a server as you said?

Enable qualify. When the qualify fails, the Dial will start to fall through promptly.

I understand now and made it work. Thanks.